mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-14 15:16:21 +00:00
standard-tests: split tool calling test (#20803)
just making it a bit easier to grok
This commit is contained in:
parent
6622829c67
commit
ddc2274aea
@ -117,13 +117,16 @@ class ChatModelIntegrationTests(ABC):
|
||||
assert isinstance(result.content, str)
|
||||
assert len(result.content) > 0
|
||||
|
||||
def test_tool_message_histories(
|
||||
def test_tool_message_histories_string_content(
|
||||
self,
|
||||
chat_model_class: Type[BaseChatModel],
|
||||
chat_model_params: dict,
|
||||
chat_model_has_tool_calling: bool,
|
||||
) -> None:
|
||||
"""Test that message histories are compatible across providers."""
|
||||
"""
|
||||
Test that message histories are compatible with string tool contents
|
||||
(e.g. OpenAI).
|
||||
"""
|
||||
if not chat_model_has_tool_calling:
|
||||
pytest.skip("Test requires tool calling.")
|
||||
model = chat_model_class(**chat_model_params)
|
||||
@ -131,15 +134,10 @@ class ChatModelIntegrationTests(ABC):
|
||||
function_name = "my_adder_tool"
|
||||
function_args = {"a": "1", "b": "2"}
|
||||
|
||||
human_message = HumanMessage(content="What is 1 + 2")
|
||||
tool_message = ToolMessage(
|
||||
name=function_name,
|
||||
content=json.dumps({"result": 3}),
|
||||
tool_call_id="abc123",
|
||||
)
|
||||
|
||||
# String content (e.g., OpenAI)
|
||||
string_content_msg = AIMessage(
|
||||
messages_string_content = [
|
||||
HumanMessage(content="What is 1 + 2"),
|
||||
# string content (e.g. OpenAI)
|
||||
AIMessage(
|
||||
content="",
|
||||
tool_calls=[
|
||||
{
|
||||
@ -148,17 +146,37 @@ class ChatModelIntegrationTests(ABC):
|
||||
"id": "abc123",
|
||||
},
|
||||
],
|
||||
)
|
||||
messages = [
|
||||
human_message,
|
||||
string_content_msg,
|
||||
tool_message,
|
||||
),
|
||||
ToolMessage(
|
||||
name=function_name,
|
||||
content=json.dumps({"result": 3}),
|
||||
tool_call_id="abc123",
|
||||
),
|
||||
]
|
||||
result = model_with_tools.invoke(messages)
|
||||
assert isinstance(result, AIMessage)
|
||||
result_string_content = model_with_tools.invoke(messages_string_content)
|
||||
assert isinstance(result_string_content, AIMessage)
|
||||
|
||||
def test_tool_message_histories_list_content(
|
||||
self,
|
||||
chat_model_class: Type[BaseChatModel],
|
||||
chat_model_params: dict,
|
||||
chat_model_has_tool_calling: bool,
|
||||
) -> None:
|
||||
"""
|
||||
Test that message histories are compatible with list tool contents
|
||||
(e.g. Anthropic).
|
||||
"""
|
||||
if not chat_model_has_tool_calling:
|
||||
pytest.skip("Test requires tool calling.")
|
||||
model = chat_model_class(**chat_model_params)
|
||||
model_with_tools = model.bind_tools([my_adder_tool])
|
||||
function_name = "my_adder_tool"
|
||||
function_args = {"a": 1, "b": 2}
|
||||
|
||||
messages_list_content = [
|
||||
HumanMessage(content="What is 1 + 2"),
|
||||
# List content (e.g., Anthropic)
|
||||
list_content_msg = AIMessage(
|
||||
AIMessage(
|
||||
content=[
|
||||
{"type": "text", "text": "some text"},
|
||||
{
|
||||
@ -175,11 +193,12 @@ class ChatModelIntegrationTests(ABC):
|
||||
"id": "abc123",
|
||||
},
|
||||
],
|
||||
)
|
||||
messages = [
|
||||
human_message,
|
||||
list_content_msg,
|
||||
tool_message,
|
||||
),
|
||||
ToolMessage(
|
||||
name=function_name,
|
||||
content=json.dumps({"result": 3}),
|
||||
tool_call_id="abc123",
|
||||
),
|
||||
]
|
||||
result = model_with_tools.invoke(messages)
|
||||
assert isinstance(result, AIMessage)
|
||||
result_list_content = model_with_tools.invoke(messages_list_content)
|
||||
assert isinstance(result_list_content, AIMessage)
|
||||
|
Loading…
Reference in New Issue
Block a user