Skip to content

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]

Add vertexai topLogprobs support (#9518)

Krish Dholakiaa619580bf8b9
diff --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.py
index 9ac1b1ffc49..73215b40489 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
@@ -207,6 +207,7 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):
"extra_headers",
"seed",
"logprobs",
+ "top_logprobs" # Added this to list of supported openAI params
]
def map_tool_choice_values(
@@ -365,6 +366,8 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):
optional_params["presence_penalty"] = value
if param == "logprobs":
optional_params["responseLogprobs"] = value
+ if param == "top_logprobs":
+ optional_params["logprobs"] = value
if (param == "tools" or param == "functions") and isinstance(value, list):
optional_params["tools"] = self._map_function(value=value)
optional_params["litellm_param_is_function_call"] = (
diff --git a/tests/litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio.py b/tests/litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio.py
new file mode 100644
index 00000000000..5e870b5af36
--- /dev/null
+++ b/tests/litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio.py
@@ -0,0 +1,33 @@
+import json
+import os
+import sys
+from unittest.mock import AsyncMock, MagicMock, patch
+
+import httpx
+import pytest
+
+sys.path.insert(
+ 0, os.path.abspath("../../../../..")
+) # Adds the parent directory to the system path
+
+from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import (
+ VertexGeminiConfig,
+)
+
+
+def test_top_logprobs():
+ non_default_params = {
+ "top_logprobs": 2,
+ "logprobs": True,
+ }
+ optional_params = {}
+ model = "gemini"
+
+ v = VertexGeminiConfig().map_openai_params(
+ non_default_params=non_default_params,
+ optional_params=optional_params,
+ model=model,
+ drop_params=False,
+ )
+ assert v["responseLogprobs"] is non_default_params["logprobs"]
+ assert v["logprobs"] is non_default_params["top_logprobs"]