def test_get_tool_calls_from_response():
    """Test extracting tool calls from a chat response."""
    tool_call = ResponseFunctionToolCall(
        id="call_123",
        call_id="123",
        type="function_call",
        name="test_function",
        arguments='{"arg1": "value1", "arg2": 42}',
        status="completed",
    )

    # Create a mock chat response with tool calls
    chat_response = MagicMock()
    chat_response.message.additional_kwargs = {"tool_calls": [tool_call]}

    with (
        patch("llama_index.llms.openai.responses.SyncOpenAI"),
        patch("llama_index.llms.openai.responses.AsyncOpenAI"),
    ):
        llm = OpenAIResponses(model="gpt-4o-mini")
        tool_selections = llm.get_tool_calls_from_response(chat_response)

    assert len(tool_selections) == 1
    assert tool_selections[0].tool_id == "123"
    assert tool_selections[0].tool_name == "test_function"
    assert tool_selections[0].tool_kwargs == {"arg1": "value1", "arg2": 42}
Test extracting tool calls from a chat response.
llama-index-integrations/llms/llama-index-llms-openai/tests/test_openai_responses.py