Revert "Fix case where only system messages are passed to Gemini (#9992)" (#10027)

This reverts commit 2afd922f8c.
This commit is contained in:
Krish Dholakia 2025-04-15 13:34:03 -07:00 committed by GitHub
parent 2afd922f8c
commit 6b5f093087
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 95 deletions

View file

@ -331,7 +331,7 @@ def _gemini_convert_messages_with_history( # noqa: PLR0915
raise e
def _transform_request_body( # noqa: PLR0915
def _transform_request_body(
messages: List[AllMessageValues],
model: str,
optional_params: dict,
@ -342,35 +342,13 @@ def _transform_request_body( # noqa: PLR0915
"""
Common transformation logic across sync + async Gemini /generateContent calls.
"""
# Duplicate system message as user message for Gemini
duplicate_system_as_user = optional_params.pop("duplicate_system_as_user_for_gemini", True)
# Check if all messages are system messages
all_system_messages = all(message["role"] == "system" for message in messages)
# Separate system prompt from rest of message
supports_system_message = get_supports_system_message(
model=model, custom_llm_provider=custom_llm_provider
)
system_instructions = None
# If all messages are system messages, add a user message to the end
if (all_system_messages and supports_system_message and messages):
# Always create system instruction
system_content = messages[0].get("content", "")
system_part = PartType(text=system_content) # type: ignore
system_instructions = SystemInstructions(parts=[system_part])
# Only duplicate as user message if flag is set
if duplicate_system_as_user or litellm.modify_params:
user_message = cast(AllMessageValues, {
"role": "user",
"content": system_content
})
messages = [user_message]
else:
messages = []
system_instructions, messages = _transform_system_message(
supports_system_message=supports_system_message, messages=messages
)
# Checks for 'response_schema' support - if passed in
if "response_schema" in optional_params:
supports_response_schema = get_supports_response_schema(