mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 15:43:54 +00:00
community[patch]: Update the default “API URL” and “MODEL” of sparkllm (#22070)
- **Description:** When I was running the sparkllm, I found that the default parameters currently used could no longer run correctly. - original parameters & values: - spark_api_url: "wss://spark-api.xf-yun.com/v3.1/chat" - spark_llm_domain: "generalv3" ```python # example from langchain_community.chat_models import ChatSparkLLM spark = ChatSparkLLM(spark_app_id="my_app_id", spark_api_key="my_api_key", spark_api_secret="my_api_secret") spark.invoke("hello") ```  So I updated them to 3.5 (same as sparkllm official website). After the update, they can be used normally. - new parameters & values: - spark_api_url: "wss://spark-api.xf-yun.com/v3.5/chat" - spark_llm_domain: "generalv3.5"
This commit is contained in:
parent
4fda7bf4f2
commit
9aba9e3e33
@ -43,6 +43,9 @@ from langchain_core.utils import (
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
SPARK_API_URL = "wss://spark-api.xf-yun.com/v3.5/chat"
|
||||||
|
SPARK_LLM_DOMAIN = "generalv3.5"
|
||||||
|
|
||||||
|
|
||||||
def _convert_message_to_dict(message: BaseMessage) -> dict:
|
def _convert_message_to_dict(message: BaseMessage) -> dict:
|
||||||
if isinstance(message, ChatMessage):
|
if isinstance(message, ChatMessage):
|
||||||
@ -108,7 +111,7 @@ class ChatSparkLLM(BaseChatModel):
|
|||||||
Extra infos:
|
Extra infos:
|
||||||
1. Get app_id, api_key, api_secret from the iFlyTek Open Platform Console:
|
1. Get app_id, api_key, api_secret from the iFlyTek Open Platform Console:
|
||||||
https://console.xfyun.cn/services/bm35
|
https://console.xfyun.cn/services/bm35
|
||||||
2. By default, iFlyTek Spark LLM V3.0 is invoked.
|
2. By default, iFlyTek Spark LLM V3.5 is invoked.
|
||||||
If you need to invoke other versions, please configure the corresponding
|
If you need to invoke other versions, please configure the corresponding
|
||||||
parameters(spark_api_url and spark_llm_domain) according to the document:
|
parameters(spark_api_url and spark_llm_domain) according to the document:
|
||||||
https://www.xfyun.cn/doc/spark/Web.html
|
https://www.xfyun.cn/doc/spark/Web.html
|
||||||
@ -134,17 +137,31 @@ class ChatSparkLLM(BaseChatModel):
|
|||||||
}
|
}
|
||||||
|
|
||||||
client: Any = None #: :meta private:
|
client: Any = None #: :meta private:
|
||||||
spark_app_id: Optional[str] = None
|
spark_app_id: Optional[str] = Field(default=None, alias="app_id")
|
||||||
|
"""Automatically inferred from env var `IFLYTEK_SPARK_APP_ID`
|
||||||
|
if not provided."""
|
||||||
spark_api_key: Optional[str] = Field(default=None, alias="api_key")
|
spark_api_key: Optional[str] = Field(default=None, alias="api_key")
|
||||||
spark_api_secret: Optional[str] = None
|
"""Automatically inferred from env var `IFLYTEK_SPARK_API_KEY`
|
||||||
spark_api_url: Optional[str] = None
|
if not provided."""
|
||||||
spark_llm_domain: Optional[str] = None
|
spark_api_secret: Optional[str] = Field(default=None, alias="api_secret")
|
||||||
|
"""Automatically inferred from env var `IFLYTEK_SPARK_API_SECRET`
|
||||||
|
if not provided."""
|
||||||
|
spark_api_url: Optional[str] = Field(default=None, alias="api_url")
|
||||||
|
"""Base URL path for API requests, leave blank if not using a proxy or service
|
||||||
|
emulator."""
|
||||||
|
spark_llm_domain: Optional[str] = Field(default=None, alias="model")
|
||||||
|
"""Model name to use."""
|
||||||
spark_user_id: str = "lc_user"
|
spark_user_id: str = "lc_user"
|
||||||
streaming: bool = False
|
streaming: bool = False
|
||||||
|
"""Whether to stream the results or not."""
|
||||||
request_timeout: int = Field(30, alias="timeout")
|
request_timeout: int = Field(30, alias="timeout")
|
||||||
|
"""request timeout for chat http requests"""
|
||||||
temperature: float = Field(default=0.5)
|
temperature: float = Field(default=0.5)
|
||||||
|
"""What sampling temperature to use."""
|
||||||
top_k: int = 4
|
top_k: int = 4
|
||||||
|
"""What search sampling control to use."""
|
||||||
model_kwargs: Dict[str, Any] = Field(default_factory=dict)
|
model_kwargs: Dict[str, Any] = Field(default_factory=dict)
|
||||||
|
"""Holds any model parameters valid for API call not explicitly specified."""
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
"""Configuration for this pydantic object."""
|
"""Configuration for this pydantic object."""
|
||||||
@ -199,13 +216,13 @@ class ChatSparkLLM(BaseChatModel):
|
|||||||
values,
|
values,
|
||||||
"spark_api_url",
|
"spark_api_url",
|
||||||
"IFLYTEK_SPARK_API_URL",
|
"IFLYTEK_SPARK_API_URL",
|
||||||
"wss://spark-api.xf-yun.com/v3.1/chat",
|
SPARK_API_URL,
|
||||||
)
|
)
|
||||||
values["spark_llm_domain"] = get_from_dict_or_env(
|
values["spark_llm_domain"] = get_from_dict_or_env(
|
||||||
values,
|
values,
|
||||||
"spark_llm_domain",
|
"spark_llm_domain",
|
||||||
"IFLYTEK_SPARK_LLM_DOMAIN",
|
"IFLYTEK_SPARK_LLM_DOMAIN",
|
||||||
"generalv3",
|
SPARK_LLM_DOMAIN,
|
||||||
)
|
)
|
||||||
# put extra params into model_kwargs
|
# put extra params into model_kwargs
|
||||||
values["model_kwargs"]["temperature"] = values["temperature"] or cls.temperature
|
values["model_kwargs"]["temperature"] = values["temperature"] or cls.temperature
|
||||||
@ -307,12 +324,10 @@ class _SparkLLMClient:
|
|||||||
"Please install it with `pip install websocket-client`."
|
"Please install it with `pip install websocket-client`."
|
||||||
)
|
)
|
||||||
|
|
||||||
self.api_url = (
|
self.api_url = SPARK_API_URL if not api_url else api_url
|
||||||
"wss://spark-api.xf-yun.com/v3.1/chat" if not api_url else api_url
|
|
||||||
)
|
|
||||||
self.app_id = app_id
|
self.app_id = app_id
|
||||||
self.model_kwargs = model_kwargs
|
self.model_kwargs = model_kwargs
|
||||||
self.spark_domain = spark_domain or "generalv3"
|
self.spark_domain = spark_domain or SPARK_LLM_DOMAIN
|
||||||
self.queue: Queue[Dict] = Queue()
|
self.queue: Queue[Dict] = Queue()
|
||||||
self.blocking_message = {"content": "", "role": "assistant"}
|
self.blocking_message = {"content": "", "role": "assistant"}
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
|
Loading…
Reference in New Issue
Block a user