fix(vertex_httpx.py): Fix tool calling with empty param list

Fixes https://github.com/BerriAI/litellm/issues/5055
This commit is contained in:
Krrish Dholakia 2024-08-21 09:02:24 -07:00
parent a34aeafdb5
commit 07bd92b527
3 changed files with 38 additions and 1 deletions

View file

@ -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)

View file

@ -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,

View file

@ -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