def test_prepare_chat_with_tools_tool_required(mock_gemini_context: MagicMock):
    """Test that tool_required=True correctly sets FunctionCallingMode.ANY in the request."""
    llm = Gemini(model="models/gemini-1.5-flash", api_key="fake_key")

    # Test with tool_required=True
    result = llm._prepare_chat_with_tools(tools=[search_tool], tool_required=True)

    assert "tool_config" in result
    assert "function_calling_config" in result["tool_config"]
    assert (
        result["tool_config"]["function_calling_config"]["mode"]
        == FunctionCallingMode.ANY
    )
    assert len(result["tools"]["function_declarations"]) == 1
    assert result["tools"]["function_declarations"][0].name == "search_tool"
Test that tool_required=True correctly sets FunctionCallingMode.ANY in the request.
llama-index-integrations/llms/llama-index-llms-gemini/tests/test_llms_gemini.py