The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test: refactor gemini test to use mock, prevent ratelimit error
Krrish Dholakiaaa4c2827e876
diff --git a/tests/llm_translation/test_vertex.py b/tests/llm_translation/test_vertex.pyindex 8bd1ddf3296..c5699d8cebc 100644--- a/tests/llm_translation/test_vertex.py+++ b/tests/llm_translation/test_vertex.py@@ -178,3 +178,55 @@ def test_vertex_function_translation(tool, expect_parameters):assert ("parameters" not in optional_params["tools"][0]["function_declarations"][0])+++def test_function_calling_with_gemini():+ from litellm.llms.custom_httpx.http_handler import HTTPHandler++ litellm.set_verbose = True+ client = HTTPHandler()+ with patch.object(client, "post", new=MagicMock()) as mock_post:+ try:+ litellm.completion(+ model="gemini/gemini-1.5-pro-002",+ messages=[+ {+ "content": [+ {+ "type": "text",+ "text": "You are a helpful assistant that can interact with a computer to solve tasks.\n<IMPORTANT>\n* If user provides a path, you should NOT assume it's relative to the current working directory. Instead, you should explore the file system to find the file before working on it.\n</IMPORTANT>\n",+ }+ ],+ "role": "system",+ },+ {+ "content": [{"type": "text", "text": "Hey, how's it going?"}],+ "role": "user",+ },+ ],+ tools=[+ {+ "type": "function",+ "function": {+ "name": "finish",+ "description": "Finish the interaction when the task is complete OR if the assistant cannot proceed further with the task.",+ },+ },+ ],+ client=client,+ )+ except Exception as e:+ print(e)+ mock_post.assert_called_once()+ print(mock_post.call_args.kwargs)++ assert mock_post.call_args.kwargs["json"]["tools"] == [+ {+ "function_declarations": [+ {+ "name": "finish",+ "description": "Finish the interaction when the task is complete OR if the assistant cannot proceed further with the task.",+ }+ ]+ }+ ]diff --git a/tests/local_testing/test_function_calling.py b/tests/local_testing/test_function_calling.pyindex 851850a691f..81d31186c04 100644--- a/tests/local_testing/test_function_calling.py+++ b/tests/local_testing/test_function_calling.py@@ -612,34 +612,3 @@ def test_passing_tool_result_as_list():print(resp)assert resp.usage.prompt_tokens_details.cached_tokens > 0---def test_function_calling_with_gemini():- litellm.set_verbose = True- resp = litellm.completion(- model="gemini/gemini-1.5-pro-002",- messages=[- {- "content": [- {- "type": "text",- "text": "You are a helpful assistant that can interact with a computer to solve tasks.\n<IMPORTANT>\n* If user provides a path, you should NOT assume it's relative to the current working directory. Instead, you should explore the file system to find the file before working on it.\n</IMPORTANT>\n",- }- ],- "role": "system",- },- {- "content": [{"type": "text", "text": "Hey, how's it going?"}],- "role": "user",- },- ],- tools=[- {- "type": "function",- "function": {- "name": "finish",- "description": "Finish the interaction when the task is complete OR if the assistant cannot proceed further with the task.",- },- },- ],- )