mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-14 14:05:37 +00:00
standard-tests: tool tests (#28244)
This commit is contained in:
@@ -10,50 +10,56 @@ class ToolsIntegrationTests(ToolsTests):
|
||||
If invoked with a ToolCall, the tool should return a valid ToolMessage content.
|
||||
"""
|
||||
tool_call = ToolCall(
|
||||
name=tool.name, args=self.tool_invoke_params_example, id=None
|
||||
name=tool.name,
|
||||
args=self.tool_invoke_params_example,
|
||||
id="123",
|
||||
type="tool_call",
|
||||
)
|
||||
result = tool.invoke(tool_call)
|
||||
|
||||
if tool.response_format == "content":
|
||||
content = result
|
||||
tool_message = result
|
||||
elif tool.response_format == "content_and_artifact":
|
||||
# should be (content, artifact)
|
||||
assert isinstance(result, tuple)
|
||||
assert len(result) == 2
|
||||
content, artifact = result
|
||||
tool_message, artifact = result
|
||||
|
||||
assert artifact # artifact can be anything, but shouldn't be none
|
||||
|
||||
# check content is a valid ToolMessage content
|
||||
assert isinstance(content, (str, list))
|
||||
if isinstance(content, list):
|
||||
assert isinstance(tool_message.content, (str, list))
|
||||
if isinstance(tool_message.content, list):
|
||||
# content blocks must be str or dict
|
||||
assert all(isinstance(c, (str, dict)) for c in content)
|
||||
assert all(isinstance(c, (str, dict)) for c in tool_message.content)
|
||||
|
||||
async def test_async_invoke_matches_output_schema(self, tool: BaseTool) -> None:
|
||||
"""
|
||||
If ainvoked with a ToolCall, the tool should return a valid ToolMessage content.
|
||||
"""
|
||||
tool_call = ToolCall(
|
||||
name=tool.name, args=self.tool_invoke_params_example, id=None
|
||||
name=tool.name,
|
||||
args=self.tool_invoke_params_example,
|
||||
id="123",
|
||||
type="tool_call",
|
||||
)
|
||||
result = await tool.ainvoke(tool_call)
|
||||
|
||||
if tool.response_format == "content":
|
||||
content = result
|
||||
tool_message = result
|
||||
elif tool.response_format == "content_and_artifact":
|
||||
# should be (content, artifact)
|
||||
assert isinstance(result, tuple)
|
||||
assert len(result) == 2
|
||||
content, artifact = result
|
||||
tool_message, artifact = result
|
||||
|
||||
assert artifact # artifact can be anything, but shouldn't be none
|
||||
|
||||
# check content is a valid ToolMessage content
|
||||
assert isinstance(content, (str, list))
|
||||
if isinstance(content, list):
|
||||
assert isinstance(tool_message.content, (str, list))
|
||||
if isinstance(tool_message.content, list):
|
||||
# content blocks must be str or dict
|
||||
assert all(isinstance(c, (str, dict)) for c in content)
|
||||
assert all(isinstance(c, (str, dict)) for c in tool_message.content)
|
||||
|
||||
def test_invoke_no_tool_call(self, tool: BaseTool) -> None:
|
||||
"""
|
||||
|
Reference in New Issue
Block a user