test_tool_choice() — langchain Function Reference
Architecture documentation for the test_tool_choice() function in test_chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD f2ba217d_7c22_353a_b0ef_55ecf0f9ea59["test_tool_choice()"] af57ae60_607e_c138_9ab0_fb8bb1c5916a["test_chat_models.py"] f2ba217d_7c22_353a_b0ef_55ecf0f9ea59 -->|defined in| af57ae60_607e_c138_9ab0_fb8bb1c5916a style f2ba217d_7c22_353a_b0ef_55ecf0f9ea59 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/groq/tests/integration_tests/test_chat_models.py lines 404–431
def test_tool_choice() -> None:
"""Test that tool choice is respected."""
llm = ChatGroq(model=DEFAULT_MODEL_NAME)
class MyTool(BaseModel):
name: str
age: int
with_tool = llm.bind_tools([MyTool], tool_choice="MyTool")
resp = with_tool.invoke("Who was the 27 year old named Erick? Use the tool.")
assert isinstance(resp, AIMessage)
assert resp.content == "" # should just be tool call
tool_calls = resp.additional_kwargs["tool_calls"]
assert len(tool_calls) == 1
tool_call = tool_calls[0]
assert tool_call["function"]["name"] == "MyTool"
assert json.loads(tool_call["function"]["arguments"]) == {
"age": 27,
"name": "Erick",
}
assert tool_call["type"] == "function"
assert isinstance(resp.tool_calls, list)
assert len(resp.tool_calls) == 1
tool_call = resp.tool_calls[0]
assert tool_call["name"] == "MyTool"
assert tool_call["args"] == {"name": "Erick", "age": 27}
Domain
Subdomains
Source
Frequently Asked Questions
What does test_tool_choice() do?
test_tool_choice() is a function in the langchain codebase, defined in libs/partners/groq/tests/integration_tests/test_chat_models.py.
Where is test_tool_choice() defined?
test_tool_choice() is defined in libs/partners/groq/tests/integration_tests/test_chat_models.py at line 404.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free