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
fix: fix checking optional params from logging object for function call
Krrish Dholakia889f0093e074
diff --git a/litellm/litellm_core_utils/prompt_templates/common_utils.py b/litellm/litellm_core_utils/prompt_templates/common_utils.pyindex 387c072ffd7..a99a2677e8f 100644--- a/litellm/litellm_core_utils/prompt_templates/common_utils.py+++ b/litellm/litellm_core_utils/prompt_templates/common_utils.py@@ -573,3 +573,12 @@ def get_tool_call_names(tools: List[ChatCompletionToolParam]) -> List[str]:if tool_call_name:tool_call_names.append(tool_call_name)return tool_call_names+++def is_function_call(optional_params: dict) -> bool:+ """+ Checks if the optional params contain the function call+ """+ if "functions" in optional_params and optional_params.get("functions"):+ return True+ return Falsediff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.pyindex dcc6ea36a30..5ae1dcf9889 100644--- a/litellm/litellm_core_utils/streaming_handler.py+++ b/litellm/litellm_core_utils/streaming_handler.py@@ -149,14 +149,14 @@ class CustomStreamWrapper:)def check_is_function_call(self, logging_obj) -> bool:+ from litellm.litellm_core_utils.prompt_templates.common_utils import (+ is_function_call,+ )+if hasattr(logging_obj, "optional_params") and isinstance(logging_obj.optional_params, dict):- if (- "litellm_param_is_function_call" in logging_obj.optional_params- and logging_obj.optional_params["litellm_param_is_function_call"]- is True- ):+ if is_function_call(logging_obj.optional_params):return Truereturn Falsediff --git a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.pyindex cd67be3545a..902f8257248 100644--- a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py+++ b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py@@ -455,9 +455,6 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):and value):optional_params["tools"] = self._map_function(value=value)- optional_params["litellm_param_is_function_call"] = (- True if param == "functions" else False- )elif param == "tool_choice" and (isinstance(value, str) or isinstance(value, dict)):@@ -880,8 +877,14 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):else:return "stop"- def _process_candidates(self, _candidates, model_response, litellm_params):+ def _process_candidates(+ self, _candidates, model_response, standard_optional_params: dict+ ):"""Helper method to process candidates and extract metadata"""+ from litellm.litellm_core_utils.prompt_templates.common_utils import (+ is_function_call,+ )+grounding_metadata: List[dict] = []safety_ratings: List = []citation_metadata: List = []@@ -918,9 +921,7 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):functions, tools = self._transform_parts(parts=candidate["content"]["parts"],index=candidate.get("index", idx),- is_function_call=litellm_params.get(- "litellm_param_is_function_call"- ),+ is_function_call=is_function_call(standard_optional_params),)if "logprobsResult" in candidate:@@ -1019,7 +1020,7 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):safety_ratings,citation_metadata,) = self._process_candidates(- _candidates, model_response, litellm_params+ _candidates, model_response, logging_obj.optional_params)usage = self._calculate_usage(completion_response=completion_response)