def test_prepare_chat_with_tools_tool_not_required():
    """Test that tool_required is correctly passed to the API request when False."""
    # Mock the client to avoid authentication issues
    mock_client = MagicMock()

    llm = OCIGenAI(
        model="cohere.command-r-16k",
        service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
        compartment_id="test_compartment_id",
        client=mock_client,
    )

    # Test with tool_required=False (default)
    result = llm._prepare_chat_with_tools(
        tools=[search_tool],
        user_msg="Test message",
    )

    # When tool_required is False, tool_choice should not be included
    assert "tool_choice" not in result
    assert len(result["tools"]) == 1
    # CohereTool objects have a `name` attribute directly
    assert result["tools"][0].name == "search_tool"
Test that tool_required is correctly passed to the API request when False.
llama-index-integrations/llms/llama-index-llms-oci-genai/tests/test_llms_oci_genai.py