community[patch]: Extend Baichuan model with tool support (#24529)

**Description:** Expanded the chat model functionality to support tools
in the 'baichuan.py' file. Updated module imports and added tool object
handling in message conversions. Additional changes include the
implementation of tool binding and related unit tests. The alterations
offer enhanced model capabilities by enabling interaction with tool-like
objects.

---------

Co-authored-by: ccurme <chester.curme@gmail.com>
This commit is contained in:
nobbbbby
2024-07-26 14:20:44 +08:00
committed by GitHub
parent ee399e3ec5
commit 4f3b4fc7fe
2 changed files with 138 additions and 10 deletions

View File

@@ -8,6 +8,7 @@ from langchain_core.messages import (
HumanMessage,
HumanMessageChunk,
SystemMessage,
ToolMessage,
)
from langchain_core.pydantic_v1 import SecretStr
from pytest import CaptureFixture, MonkeyPatch
@@ -58,6 +59,18 @@ def test__convert_message_to_dict_system() -> None:
assert result == expected_output
def test__convert_message_to_dict_tool() -> None:
message = ToolMessage(name="foo", content="bar", tool_call_id="abc123")
result = _convert_message_to_dict(message)
expected_output = {
"name": "foo",
"content": "bar",
"tool_call_id": "abc123",
"role": "tool",
}
assert result == expected_output
def test__convert_message_to_dict_function() -> None:
message = FunctionMessage(name="foo", content="bar")
with pytest.raises(TypeError) as e: