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(utils.py): fix vertex ai optional param handling (#8477)
Krish Dholakia8903bd1c7f04
diff --git a/litellm/litellm_core_utils/get_supported_openai_params.py b/litellm/litellm_core_utils/get_supported_openai_params.pyindex 9358518930c..3d4f8cef6f4 100644--- a/litellm/litellm_core_utils/get_supported_openai_params.py+++ b/litellm/litellm_core_utils/get_supported_openai_params.py@@ -121,21 +121,26 @@ def get_supported_openai_params( # noqa: PLR0915)elif custom_llm_provider == "vertex_ai" or custom_llm_provider == "vertex_ai_beta":if request_type == "chat_completion":- if model.startswith("meta/"):- return litellm.VertexAILlama3Config().get_supported_openai_params()if model.startswith("mistral"):return litellm.MistralConfig().get_supported_openai_params(model=model)- if model.startswith("codestral"):+ elif model.startswith("codestral"):return (litellm.CodestralTextCompletionConfig().get_supported_openai_params(model=model))- if model.startswith("claude"):+ elif model.startswith("claude"):return litellm.VertexAIAnthropicConfig().get_supported_openai_params(model=model)- return litellm.VertexGeminiConfig().get_supported_openai_params(model=model)+ elif model.startswith("gemini"):+ return litellm.VertexGeminiConfig().get_supported_openai_params(+ model=model+ )+ else:+ return litellm.VertexAILlama3Config().get_supported_openai_params(+ model=model+ )elif request_type == "embeddings":return litellm.VertexAITextEmbeddingConfig().get_supported_openai_params()elif custom_llm_provider == "sagemaker":diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/llama3/transformation.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/llama3/transformation.pyindex 0278d198062..cf46f4a7429 100644--- a/litellm/llms/vertex_ai/vertex_ai_partner_models/llama3/transformation.py+++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/llama3/transformation.py@@ -1,10 +1,10 @@import typesfrom typing import Optional-import litellm+from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig-class VertexAILlama3Config:+class VertexAILlama3Config(OpenAIGPTConfig):"""Reference:https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/llama#streaming@@ -46,8 +46,13 @@ class VertexAILlama3Config:and v is not None}- def get_supported_openai_params(self):- return litellm.OpenAIConfig().get_supported_openai_params(model="gpt-3.5-turbo")+ def get_supported_openai_params(self, model: str):+ supported_params = super().get_supported_openai_params(model=model)+ try:+ supported_params.remove("max_retries")+ except KeyError:+ pass+ return supported_paramsdef map_openai_params(self,@@ -60,7 +65,7 @@ class VertexAILlama3Config:non_default_params["max_tokens"] = non_default_params.pop("max_completion_tokens")- return litellm.OpenAIConfig().map_openai_params(+ return super().map_openai_params(non_default_params=non_default_params,optional_params=optional_params,model=model,diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex 3f9a27f1c87..675dd5bba66 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -4,7 +4,4 @@ model_list:model: azure/chatgpt-v-2api_key: os.environ/AZURE_API_KEYapi_base: os.environ/AZURE_API_BASE- timeout: 0.000000001--litellm_settings:- request_timeout: 10000\ No newline at end of file+ timeout: 0.000000001\ No newline at end of filediff --git a/litellm/utils.py b/litellm/utils.pyindex dbefc90dc61..34a5dc596cd 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -3166,51 +3166,56 @@ def get_optional_params( # noqa: PLR0915else False),)- elif custom_llm_provider == "vertex_ai" and model in litellm.vertex_llama3_models:- optional_params = litellm.VertexAILlama3Config().map_openai_params(- non_default_params=non_default_params,- optional_params=optional_params,- model=model,- drop_params=(- drop_params- if drop_params is not None and isinstance(drop_params, bool)- else False- ),- )- elif custom_llm_provider == "vertex_ai" and model in litellm.vertex_mistral_models:- if "codestral" in model:- optional_params = litellm.CodestralTextCompletionConfig().map_openai_params(- model=model,+ elif custom_llm_provider == "vertex_ai":++ if model in litellm.vertex_mistral_models:+ if "codestral" in model:+ optional_params = (+ litellm.CodestralTextCompletionConfig().map_openai_params(+ model=model,+ non_default_params=non_default_params,+ optional_params=optional_params,+ drop_params=(+ drop_params+ if drop_params is not None and isinstance(drop_params, bool)+ else False+ ),+ )+ )+ else:+ optional_params = litellm.MistralConfig().map_openai_params(+ model=model,+ non_default_params=non_default_params,+ optional_params=optional_params,+ drop_params=(+ drop_params+ if drop_params is not None and isinstance(drop_params, bool)+ else False+ ),+ )+ elif model in litellm.vertex_ai_ai21_models:+ optional_params = litellm.VertexAIAi21Config().map_openai_params(non_default_params=non_default_params,optional_params=optional_params,+ model=model,drop_params=(drop_paramsif drop_params is not None and isinstance(drop_params, bool)else False),)- else:- optional_params = litellm.MistralConfig().map_openai_params(- model=model,+ else: # use generic openai-like param mapping+ optional_params = litellm.VertexAILlama3Config().map_openai_params(non_default_params=non_default_params,optional_params=optional_params,+ model=model,drop_params=(drop_paramsif drop_params is not None and isinstance(drop_params, bool)else False),)- elif custom_llm_provider == "vertex_ai" and model in litellm.vertex_ai_ai21_models:- optional_params = litellm.VertexAIAi21Config().map_openai_params(- non_default_params=non_default_params,- optional_params=optional_params,- model=model,- drop_params=(- drop_params- if drop_params is not None and isinstance(drop_params, bool)- else False- ),- )+elif custom_llm_provider == "sagemaker":# temperature, top_p, n, stream, stop, max_tokens, n, presence_penalty default to Noneoptional_params = litellm.SagemakerConfig().map_openai_params(diff --git a/tests/llm_translation/test_max_completion_tokens.py b/tests/llm_translation/test_max_completion_tokens.pyindex a15934e1342..c20ef3d1a06 100644--- a/tests/llm_translation/test_max_completion_tokens.py+++ b/tests/llm_translation/test_max_completion_tokens.py@@ -143,7 +143,8 @@ def test_all_model_configs():)assert (- "max_completion_tokens" in VertexAILlama3Config().get_supported_openai_params()+ "max_completion_tokens"+ in VertexAILlama3Config().get_supported_openai_params(model="llama3"))assert VertexAILlama3Config().map_openai_params({"max_completion_tokens": 10}, {}, "llama3", drop_params=Falsediff --git a/tests/llm_translation/test_optional_params.py b/tests/llm_translation/test_optional_params.pyindex 75fe7aa5b19..e7f2f8ac280 100644--- a/tests/llm_translation/test_optional_params.py+++ b/tests/llm_translation/test_optional_params.py@@ -1067,3 +1067,14 @@ def test_gemini_frequency_penalty():model="gemini-1.5-flash", custom_llm_provider="gemini", frequency_penalty=0.5)assert optional_params["frequency_penalty"] == 0.5+++def test_vertex_ai_ft_llama():+ optional_params = get_optional_params(+ model="1984786713414729728",+ custom_llm_provider="vertex_ai",+ frequency_penalty=0.5,+ max_retries=10,+ )+ assert optional_params["frequency_penalty"] == 0.5+ assert "max_retries" not in optional_params