def test_prepare_chat_with_tools_tool_not_required():
    """Test that tool_required=False is correctly passed to the API request."""
    llm = OpenAI(api_key="test-key")

    result = llm._prepare_chat_with_tools(
        tools=[search_tool], user_msg="Search for Python tutorials", tool_required=False
    )

    assert "messages" in result
    assert "tools" in result
    assert "tool_choice" in result
    assert len(result["tools"]) == 1
    assert result["tools"][0]["function"]["name"] == "search_tool"
    assert result["tool_choice"] == "auto"
Test that tool_required=False is correctly passed to the API request.
llama-index-integrations/llms/llama-index-llms-openai/tests/test_llms_openai.py