mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(vertex_ai): route xai/grok through completion adapter on generateContent
POST /v1beta/models/{model}:generateContent treated vertex_ai/xai/grok-*
as a native Gemini model: get_provider_google_genai_generate_content_config()
only falls back to the litellm.completion() adapter for Vertex Partner
models, and PartnerModelPrefixes has no xai/ entry. Grok is dispatched to
VertexAIGoogleGenAIConfig and fails with a protocol mismatch.
xai/ publisher models are Model Garden OpenAI-compatible, matching how
get_vertex_ai_model_route() already serves them (MODEL_GARDEN). Route them
through the completion adapter on the unified Gemini-style endpoint, the
same way openai/gpt-oss-, moonshotai/, minimaxai/, etc. are handled.
Signed-off-by: Rainmemery <152621457+Rainmemery@users.noreply.github.com>
This commit is contained in:
parent
e484a7c89c
commit
843189740b
2 changed files with 59 additions and 0 deletions
|
|
@ -9767,6 +9767,19 @@ class ProviderConfigManager:
|
|||
if VertexAIPartnerModels.is_vertex_partner_model(model):
|
||||
return None
|
||||
|
||||
#########################################################
|
||||
# Model Garden publisher models served via the OpenAI-compatible
|
||||
# route (e.g. xai/grok-*) are not Vertex Partner "raw" models, but
|
||||
# they still go through the litellm.completion() adapter (which
|
||||
# dispatches them to the Model Garden OpenAI-compatible handler),
|
||||
# never through the Google Gen AI config. Without this case the
|
||||
# unified Gemini-style endpoint POST /v1beta/models/{model}:generateContent
|
||||
# would treat e.g. vertex_ai/xai/grok-* as a native Gemini model
|
||||
# and fail with a protocol mismatch.
|
||||
#########################################################
|
||||
if model.startswith("xai/"):
|
||||
return None
|
||||
|
||||
#########################################################
|
||||
# If the model is not a Vertex Partner model, return the Vertex AI Google Gen AI Config
|
||||
# This is for Vertex `gemini` models
|
||||
|
|
|
|||
|
|
@ -5796,3 +5796,49 @@ def test_calculate_max_parallel_requests_precedence(
|
|||
)
|
||||
== expected
|
||||
)
|
||||
|
||||
def test_get_provider_google_genai_generate_content_config_vertex_partner_models():
|
||||
"""
|
||||
https://github.com/BerriAI/litellm/issues/41835
|
||||
Vertex Grok (vertex_ai/xai/grok-*) is rejected on /v1beta/models/{model}:generateContent
|
||||
because get_provider_google_genai_generate_content_config() only falls back to the
|
||||
litellm.completion() adapter for Vertex Partner models, and xai/ was missing from
|
||||
PartnerModelPrefixes. Ensure xai/grok-* now returns None (i.e. the generateContent
|
||||
endpoint routes it through the chat-completions adapter like other Model Garden
|
||||
OpenAI-compatible partners), while gemini models still get the native config.
|
||||
"""
|
||||
from litellm.types.utils import LlmProviders
|
||||
|
||||
# Grok via Model Garden -> through the completion adapter (None)
|
||||
assert (
|
||||
ProviderConfigManager.get_provider_google_genai_generate_content_config(
|
||||
model="xai/grok-4.6", provider=LlmProviders.VERTEX_AI
|
||||
)
|
||||
is None
|
||||
)
|
||||
assert (
|
||||
ProviderConfigManager.get_provider_google_genai_generate_content_config(
|
||||
model="xai/grok-4.1-fast-non-reasoning", provider=LlmProviders.VERTEX_AI
|
||||
)
|
||||
is None
|
||||
)
|
||||
|
||||
# Other existing partner models are unaffected
|
||||
assert (
|
||||
ProviderConfigManager.get_provider_google_genai_generate_content_config(
|
||||
model="claude-3-5-sonnet-20241022", provider=LlmProviders.VERTEX_AI
|
||||
)
|
||||
is None
|
||||
)
|
||||
|
||||
# Native Gemini models still get the Vertex Google Gen AI config
|
||||
from litellm.llms.vertex_ai.google_genai.transformation import (
|
||||
VertexAIGoogleGenAIConfig,
|
||||
)
|
||||
|
||||
assert isinstance(
|
||||
ProviderConfigManager.get_provider_google_genai_generate_content_config(
|
||||
model="gemini-1.5-pro", provider=LlmProviders.VERTEX_AI
|
||||
),
|
||||
VertexAIGoogleGenAIConfig,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue