From 736afd5d3815f3618c662a276ad7d57b59cde05f Mon Sep 17 00:00:00 2001 From: Guangdong Liu Date: Thu, 7 Mar 2024 10:43:16 +0800 Subject: [PATCH] community[patch]: Fix sparkllm authentication problem. (#18651) - **Description:** fix sparkllm authentication problem.The current timestamp is in RFC1123 format. The time deviation must be controlled within 300s. I changed to re-obtain the url every time I ask a question. https://www.xfyun.cn/doc/spark/general_url_authentication.html#_1-2-%E9%89%B4%E6%9D%83%E5%8F%82%E6%95%B0 --- .../langchain_community/chat_models/sparkllm.py | 13 +++++++------ libs/community/langchain_community/llms/sparkllm.py | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/libs/community/langchain_community/chat_models/sparkllm.py b/libs/community/langchain_community/chat_models/sparkllm.py index b29467108eb..9305b0ce378 100644 --- a/libs/community/langchain_community/chat_models/sparkllm.py +++ b/libs/community/langchain_community/chat_models/sparkllm.py @@ -306,15 +306,12 @@ class _SparkLLMClient: "wss://spark-api.xf-yun.com/v3.1/chat" if not api_url else api_url ) self.app_id = app_id - self.ws_url = _SparkLLMClient._create_url( - self.api_url, - api_key, - api_secret, - ) self.model_kwargs = model_kwargs self.spark_domain = spark_domain or "generalv3" self.queue: Queue[Dict] = Queue() self.blocking_message = {"content": "", "role": "assistant"} + self.api_key = api_key + self.api_secret = api_secret @staticmethod def _create_url(api_url: str, api_key: str, api_secret: str) -> str: @@ -370,7 +367,11 @@ class _SparkLLMClient: ) -> None: self.websocket_client.enableTrace(False) ws = self.websocket_client.WebSocketApp( - self.ws_url, + _SparkLLMClient._create_url( + self.api_url, + self.api_key, + self.api_secret, + ), on_message=self.on_message, on_error=self.on_error, on_close=self.on_close, diff --git a/libs/community/langchain_community/llms/sparkllm.py b/libs/community/langchain_community/llms/sparkllm.py index 7d5eeab2184..f2735f108d0 100644 --- a/libs/community/langchain_community/llms/sparkllm.py +++ b/libs/community/langchain_community/llms/sparkllm.py @@ -203,15 +203,12 @@ class _SparkLLMClient: "wss://spark-api.xf-yun.com/v3.1/chat" if not api_url else api_url ) self.app_id = app_id - self.ws_url = _SparkLLMClient._create_url( - self.api_url, - api_key, - api_secret, - ) self.model_kwargs = model_kwargs self.spark_domain = spark_domain or "generalv3" self.queue: Queue[Dict] = Queue() self.blocking_message = {"content": "", "role": "assistant"} + self.api_key = api_key + self.api_secret = api_secret @staticmethod def _create_url(api_url: str, api_key: str, api_secret: str) -> str: @@ -267,7 +264,11 @@ class _SparkLLMClient: ) -> None: self.websocket_client.enableTrace(False) ws = self.websocket_client.WebSocketApp( - self.ws_url, + _SparkLLMClient._create_url( + self.api_url, + self.api_key, + self.api_secret, + ), on_message=self.on_message, on_error=self.on_error, on_close=self.on_close,