Home / Function/ test_function_calling_and_structured_output() — langchain Function Reference

test_function_calling_and_structured_output() — langchain Function Reference

Architecture documentation for the test_function_calling_and_structured_output() function in test_responses_api.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  3c881793_63c8_cced_a400_5cd01d90e119["test_function_calling_and_structured_output()"]
  992496d5_b7d4_139f_00cf_3e585d851f81["test_responses_api.py"]
  3c881793_63c8_cced_a400_5cd01d90e119 -->|defined in| 992496d5_b7d4_139f_00cf_3e585d851f81
  style 3c881793_63c8_cced_a400_5cd01d90e119 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py lines 322–343

def test_function_calling_and_structured_output(schema: Any) -> None:
    def multiply(x: int, y: int) -> int:
        """return x * y"""
        return x * y

    llm = ChatOpenAI(model=MODEL_NAME, use_responses_api=True)
    bound_llm = llm.bind_tools([multiply], response_format=schema, strict=True)
    # Test structured output
    response = llm.invoke("how are ya", response_format=schema)
    if schema == Foo:
        parsed = schema(**json.loads(response.text))
        assert parsed.response
    else:
        parsed = json.loads(response.text)
        assert parsed["response"]
    assert parsed == response.additional_kwargs["parsed"]

    # Test function calling
    ai_msg = cast(AIMessage, bound_llm.invoke("whats 5 * 4"))
    assert len(ai_msg.tool_calls) == 1
    assert ai_msg.tool_calls[0]["name"] == "multiply"
    assert set(ai_msg.tool_calls[0]["args"]) == {"x", "y"}

Domain

Subdomains

Frequently Asked Questions

What does test_function_calling_and_structured_output() do?
test_function_calling_and_structured_output() is a function in the langchain codebase, defined in libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py.
Where is test_function_calling_and_structured_output() defined?
test_function_calling_and_structured_output() is defined in libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py at line 322.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free