From 07bd92b527404d1fcddba3e9dd70d42c2c534a1f Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 21 Aug 2024 09:02:24 -0700 Subject: [PATCH] fix(vertex_httpx.py): Fix tool calling with empty param list Fixes https://github.com/BerriAI/litellm/issues/5055 --- litellm/llms/vertex_httpx.py | 3 ++- ...odel_prices_and_context_window_backup.json | 12 ++++++++++ litellm/tests/test_function_calling.py | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/litellm/llms/vertex_httpx.py b/litellm/llms/vertex_httpx.py index 8af8f6894e..1b0ef52bcd 100644 --- a/litellm/llms/vertex_httpx.py +++ b/litellm/llms/vertex_httpx.py @@ -205,8 +205,9 @@ class GoogleAIStudioGeminiConfig: # key diff from VertexAI - 'frequency_penalty gtool_func_declaration = FunctionDeclaration( name=tool["function"]["name"], description=tool["function"].get("description", ""), - parameters=_parameters, ) + if len(_parameters.keys()) > 0: + gtool_func_declaration["parameters"] = _parameters gtool_func_declarations.append(gtool_func_declaration) optional_params["tools"] = [ Tools(function_declarations=gtool_func_declarations) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index ab36dbb6c9..0f483b083b 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -2796,6 +2796,18 @@ "tool_use_system_prompt_tokens": 159, "supports_assistant_prefill": true }, + "openrouter/anthropic/claude-3.5-sonnet:beta": { + "max_tokens": 4096, + "max_input_tokens": 200000, + "max_output_tokens": 4096, + "input_cost_per_token": 0.000003, + "output_cost_per_token": 0.000015, + "litellm_provider": "openrouter", + "mode": "chat", + "supports_function_calling": true, + "supports_vision": true, + "tool_use_system_prompt_tokens": 159 + }, "openrouter/anthropic/claude-3-sonnet": { "max_tokens": 200000, "input_cost_per_token": 0.000003, diff --git a/litellm/tests/test_function_calling.py b/litellm/tests/test_function_calling.py index 5f97dbf87d..a42a253005 100644 --- a/litellm/tests/test_function_calling.py +++ b/litellm/tests/test_function_calling.py @@ -337,3 +337,27 @@ def test_groq_parallel_function_call(): print("second response\n", second_response) except Exception as e: pytest.fail(f"Error occurred: {e}") + + +@pytest.mark.parametrize("model", ["gemini/gemini-1.5-pro"]) +def test_simple_function_call_function_param(model): + try: + litellm.set_verbose = True + messages = [{"role": "user", "content": "What is the weather like in Boston?"}] + response = completion( + model=model, + messages=messages, + tools=[ + { + "type": "function", + "function": { + "name": "plot", + "description": "Generate plots", + }, + } + ], + tool_choice="auto", + ) + print(f"response: {response}") + except Exception as e: + raise e