test_json_output_key_tools_parser_multiple_matching_tools() — langchain Function Reference
Architecture documentation for the test_json_output_key_tools_parser_multiple_matching_tools() function in test_openai_tools.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 39649c8d_e512_5491_7dd9_d94ca30bcacd["test_json_output_key_tools_parser_multiple_matching_tools()"] 0f94a062_f577_31c7_fb9c_0f526b273e64["test_openai_tools.py"] 39649c8d_e512_5491_7dd9_d94ca30bcacd -->|defined in| 0f94a062_f577_31c7_fb9c_0f526b273e64 style 39649c8d_e512_5491_7dd9_d94ca30bcacd fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/output_parsers/test_openai_tools.py lines 595–651
def test_json_output_key_tools_parser_multiple_matching_tools(
*, use_tool_calls: bool
) -> None:
def create_message() -> AIMessage:
tool_calls_data = [
{
"id": "call_func1",
"function": {"name": "func", "arguments": '{"a":1}'},
"type": "function",
},
{
"id": "call_other",
"function": {"name": "other", "arguments": '{"b":2}'},
"type": "function",
},
{
"id": "call_func2",
"function": {"name": "func", "arguments": '{"a":3}'},
"type": "function",
},
]
if use_tool_calls:
return AIMessage(
content="",
tool_calls=[
{"id": "call_func1", "name": "func", "args": {"a": 1}},
{"id": "call_other", "name": "other", "args": {"b": 2}},
{"id": "call_func2", "name": "func", "args": {"a": 3}},
],
)
return AIMessage(
content="",
additional_kwargs={"tool_calls": tool_calls_data},
)
result = [ChatGeneration(message=create_message())]
# Test with first_tool_only=True - should return first matching
parser = JsonOutputKeyToolsParser(
key_name="func", first_tool_only=True, return_id=True
)
output = parser.parse_result(result) # type: ignore[arg-type]
assert output is not None
assert output["type"] == "func"
assert output["args"] == {"a": 1} # First matching tool call
# Test with first_tool_only=False - should return all matching
parser_all = JsonOutputKeyToolsParser(
key_name="func", first_tool_only=False, return_id=True
)
output_all = parser_all.parse_result(result) # type: ignore[arg-type]
assert len(output_all) == 2
assert output_all[0]["args"] == {"a": 1}
assert output_all[1]["args"] == {"a": 3}
Domain
Subdomains
Source
Frequently Asked Questions
What does test_json_output_key_tools_parser_multiple_matching_tools() do?
test_json_output_key_tools_parser_multiple_matching_tools() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/output_parsers/test_openai_tools.py.
Where is test_json_output_key_tools_parser_multiple_matching_tools() defined?
test_json_output_key_tools_parser_multiple_matching_tools() is defined in libs/core/tests/unit_tests/output_parsers/test_openai_tools.py at line 595.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free