From 25a103187137077d4331e7153fe119e1c0c3ffb6 Mon Sep 17 00:00:00 2001 From: Tao Wang Date: Fri, 1 Nov 2024 05:00:16 +1100 Subject: [PATCH] community: Fix a validation error for MoonshotChat (#27801) - **Description:** Change `MoonshotCommon.client` type from `_MoonshotClient` to `Any`. - **Issue:** Fix the issue #27058 - **Dependencies:** No - **Twitter handle:** TaoWang2218 In PR #17100, the implementation for Moonshot was added, which defined two classes: - `MoonshotChat(MoonshotCommon, ChatOpenAI)` in `langchain_community.chat_models.moonshot`; - Here, `validate_environment()` assigns **client** as `openai.OpenAI().chat.completions` - Note that **client** here is actually a member variable defined in `ChatOpenAI`; - `MoonshotCommon` in `langchain_community.llms.moonshot`; - And here, `validate_environment()` assigns **_client** as `_MoonshotClient`; - Note that this is the underscored **_client**, which is defined within `MoonshotCommon` itself; At this time, there was no conflict between the two, one being `client` and the other `_client`. However, in PR #25878 which fixed #24390, `_client` in `MoonshotCommon` was changed to `client`. Since then, a conflict in the definition of `client` has arisen between `MoonshotCommon` and `MoonshotChat`, which caused `pydantic` validation error. To fix this issue, the type of `client` in `MoonshotCommon` should be changed to `Any`. Signed-off-by: Tao Wang --- libs/community/langchain_community/llms/moonshot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/langchain_community/llms/moonshot.py b/libs/community/langchain_community/llms/moonshot.py index 473f35fdf069b..7f204fa69d885 100644 --- a/libs/community/langchain_community/llms/moonshot.py +++ b/libs/community/langchain_community/llms/moonshot.py @@ -39,7 +39,7 @@ def completion(self, request: Any) -> Any: class MoonshotCommon(BaseModel): """Common parameters for Moonshot LLMs.""" - client: _MoonshotClient + client: Any base_url: str = MOONSHOT_SERVICE_URL_BASE moonshot_api_key: Optional[SecretStr] = Field(default=None, alias="api_key") """Moonshot API key. Get it here: https://platform.moonshot.cn/console/api-keys"""