From a4e33c8c67bc1013a9e3f5eed23980be9b76e47d Mon Sep 17 00:00:00 2001 From: kan-bayashi Date: Wed, 14 Feb 2024 13:09:35 +0900 Subject: [PATCH 1/3] fix the issue when using multiple tools in gemini --- litellm/utils.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index e238b84d777..edd2b5c2170 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -4215,18 +4215,15 @@ def get_optional_params( if tools is not None and isinstance(tools, list): from vertexai.preview import generative_models - gtools = [] + gtool_func_declarations = [] for tool in tools: - gtool = generative_models.FunctionDeclaration( + gtool_func_declaration = generative_models.FunctionDeclaration( name=tool["function"]["name"], description=tool["function"].get("description", ""), parameters=tool["function"].get("parameters", {}), ) - gtool_func_declaration = generative_models.Tool( - function_declarations=[gtool] - ) - gtools.append(gtool_func_declaration) - optional_params["tools"] = gtools + gtool_func_declarations.append(gtool_func_declaration) + optional_params["tools"] = [generative_models.Tool(function_declarations=gtool_func_declarations)] elif custom_llm_provider == "sagemaker": ## check if unsupported param passed in supported_params = ["stream", "temperature", "max_tokens", "top_p", "stop", "n"] From 917525ee4349eb766e0035fc19c0cf5ce1fb1df1 Mon Sep 17 00:00:00 2001 From: kan-bayashi Date: Wed, 14 Feb 2024 14:49:42 +0900 Subject: [PATCH 2/3] fix args=None case --- litellm/llms/vertex_ai.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/litellm/llms/vertex_ai.py b/litellm/llms/vertex_ai.py index d42bd003f83..f7062fc6a1e 100644 --- a/litellm/llms/vertex_ai.py +++ b/litellm/llms/vertex_ai.py @@ -437,8 +437,9 @@ def completion( ): function_call = response.candidates[0].content.parts[0].function_call args_dict = {} - for k, v in function_call.args.items(): - args_dict[k] = v + if function_call.args is not None: + for k, v in function_call.args.items(): + args_dict[k] = v args_str = json.dumps(args_dict) message = litellm.Message( content=None, From 90775910e284b7870d2d7588d0f55b9c27911833 Mon Sep 17 00:00:00 2001 From: kan-bayashi Date: Wed, 14 Feb 2024 17:38:00 +0900 Subject: [PATCH 3/3] fix if-else condition when function_call exits but empty --- litellm/llms/vertex_ai.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/litellm/llms/vertex_ai.py b/litellm/llms/vertex_ai.py index f7062fc6a1e..f24b6c35879 100644 --- a/litellm/llms/vertex_ai.py +++ b/litellm/llms/vertex_ai.py @@ -432,14 +432,13 @@ def completion( tools=tools, ) - if tools is not None and hasattr( - response.candidates[0].content.parts[0], "function_call" + if tools is not None and bool( + getattr(response.candidates[0].content.parts[0], "function_call", None) ): function_call = response.candidates[0].content.parts[0].function_call args_dict = {} - if function_call.args is not None: - for k, v in function_call.args.items(): - args_dict[k] = v + for k, v in function_call.args.items(): + args_dict[k] = v args_str = json.dumps(args_dict) message = litellm.Message( content=None,