Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9ebd412
bufix: add bind_tools impl for MoonshotChat
markshao Nov 1, 2025
7d8af43
Merge branch 'main' into markshao/add-bindtools-impl-in-moonshot
mdrxy Nov 4, 2025
8c57b07
Merge branch 'main' into markshao/add-bindtools-impl-in-moonshot
mdrxy Nov 5, 2025
7468586
Merge branch 'main' into markshao/add-bindtools-impl-in-moonshot
markshao Nov 5, 2025
b95b011
fix(chat_models): parallel tool calls in ChatTongyi when incremental …
TBice123123 Nov 5, 2025
0fa7c63
fix(infra): remove unused `dataclasses-json` dependency (#270)
noirbee Nov 5, 2025
888a38b
chore: update `README.md` (#408)
mdrxy Nov 5, 2025
1107250
feat(agent_toolkits): Make `WebClient` injectable for Slack toolkit (…
m1kl0sh Nov 5, 2025
d386468
feat(document_loaders): add flexible timeout to `PlaywrightURLLoader`…
parthsompura Nov 5, 2025
82c99be
feat: add SSL verification option to recursive link fetching (#46)
rajasblack Nov 5, 2025
3259e26
chore: some cleanup (#412)
mdrxy Nov 7, 2025
ce6a5cf
fix(azure): Fix key assignment logic (#418)
yashovardhan99 Nov 10, 2025
cde3d06
feat(vectorstores): add routing support for hybrid search (#416)
yukiharada1228 Nov 10, 2025
55adf50
nit: use american english (#419)
mdrxy Nov 10, 2025
683f6a4
chore(infra): clarify allowed scopes section in PR linting workflow (…
mdrxy Nov 10, 2025
6918499
chore: update `README.md` (#422)
mdrxy Nov 11, 2025
23dda6c
fix lint issues
Nov 22, 2025
418d003
Merge branch 'main' into markshao/add-bindtools-impl-in-moonshot
markshao Nov 23, 2025
ad929d4
Merge branch 'main' into markshao/add-bindtools-impl-in-moonshot
markshao Nov 27, 2025
7a1d458
Merge branch 'main' into markshao/add-bindtools-impl-in-moonshot
markshao Nov 30, 2025
e2ca30d
Merge branch 'main' into markshao/add-bindtools-impl-in-moonshot
markshao Dec 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions libs/community/langchain_community/chat_models/moonshot.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"""Wrapper around Moonshot chat models."""

from typing import Dict
from typing import Any, Callable, Dict, Sequence, Type, Union

from langchain_core.language_models import LanguageModelInput
from langchain_core.messages import AIMessage
from langchain_core.runnables import Runnable
from langchain_core.tools import BaseTool
from langchain_core.utils import (
convert_to_secret_str,
get_from_dict_or_env,
pre_init,
)
from langchain_core.utils.function_calling import convert_to_openai_tool
from pydantic import BaseModel

from langchain_community.chat_models import ChatOpenAI
from langchain_community.llms.moonshot import MOONSHOT_SERVICE_URL_BASE, MoonshotCommon
Expand Down Expand Up @@ -172,9 +178,11 @@ def validate_environment(cls, values: Dict) -> Dict:

client_params = {
"api_key": values["moonshot_api_key"].get_secret_value(),
"base_url": values["base_url"]
if "base_url" in values
else MOONSHOT_SERVICE_URL_BASE,
"base_url": (
values["base_url"]
if "base_url" in values
else MOONSHOT_SERVICE_URL_BASE
),
}

if not values.get("client"):
Expand All @@ -185,3 +193,22 @@ def validate_environment(cls, values: Dict) -> Dict:
).chat.completions

return values

def bind_tools(
self,
tools: Sequence[Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]],
**kwargs: Any,
) -> Runnable[LanguageModelInput, AIMessage]:
"""Bind tool-like objects to this chat model.

Args:
tools: A list of tool definitions to bind to this chat model.
Can be a dictionary, pydantic model, callable, or BaseTool. Pydantic
models, callables, and BaseTools will be automatically converted to
their schema dictionary representation.
**kwargs: Any additional parameters to pass to the
:class:`~langchain.runnable.Runnable` constructor.
"""

formatted_tools = [convert_to_openai_tool(tool) for tool in tools]
return super().bind(tools=formatted_tools, **kwargs)
2 changes: 1 addition & 1 deletion libs/community/langchain_community/llms/moonshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def completion(self, request: Any) -> Any:
class MoonshotCommon(BaseModel):
"""Common parameters for Moonshot LLMs."""

client: Any
client: Any = Field(default=None)
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"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def test_usage_metadata(self, model: BaseChatModel) -> None:
def test_chat_moonshot_instantiate_with_alias() -> None:
"""Test MoonshotChat instantiate when using alias."""
api_key = "your-api-key"
chat = MoonshotChat(api_key=api_key) # type: ignore[call-arg]
chat = MoonshotChat(api_key=api_key)
assert cast(SecretStr, chat.moonshot_api_key).get_secret_value() == api_key
14 changes: 14 additions & 0 deletions libs/community/tests/unit_tests/chat_models/test_moonshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Any

import pytest

from langchain_community.chat_models.moonshot import MoonshotChat

mock_tool_list = [lambda: f"tool-id-{i}" for i in range(3)]


@pytest.mark.requires("openai")
def test_moonshot_bind_tools() -> None:
llm = MoonshotChat(name="moonshot")
ret: Any = llm.bind_tools(mock_tool_list)
assert len(ret.kwargs["tools"]) == 3
2 changes: 1 addition & 1 deletion libs/community/tests/unit_tests/llms/test_moonshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@pytest.mark.requires("openai")
def test_moonshot_model_param() -> None:
llm = Moonshot(model="foo") # type: ignore[call-arg]
llm = Moonshot(model="foo")
assert llm.model_name == "foo"
llm = Moonshot(model_name="bar") # type: ignore[call-arg]
assert llm.model_name == "bar"