mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
fix(vertex_ai): narrow field transformation to contents and systemInstruction
- Restrict recursive camelCase transformation to 'contents' and 'system_instruction' chunks to avoid breaking existing snake_case top-level fields (e.g. in generationConfig or extra_body). - Rename 'system_instruction' to 'systemInstruction' for Vertex AI REST API compliance. - Update context caching transformation with the same narrowed logic.
This commit is contained in:
parent
699cedb96e
commit
94c2db996a
2 changed files with 20 additions and 4 deletions
|
|
@ -14,6 +14,7 @@ from litellm.utils import is_cached_message
|
|||
from ..common_utils import get_supports_system_message
|
||||
from ..gemini.transformation import (
|
||||
_gemini_convert_messages_with_history,
|
||||
_transform_part_to_httpx_format,
|
||||
_transform_system_message,
|
||||
)
|
||||
|
||||
|
|
@ -198,8 +199,14 @@ def transform_openai_messages_to_gemini_context_caching(
|
|||
data["system_instruction"] = transformed_system_messages
|
||||
|
||||
if is_vertex_ai:
|
||||
from ..gemini.transformation import _transform_part_to_httpx_format
|
||||
|
||||
return _transform_part_to_httpx_format(data) # type: ignore
|
||||
if "contents" in data:
|
||||
data["contents"] = _transform_part_to_httpx_format(
|
||||
{"contents": data["contents"]}, parent_key=None
|
||||
)["contents"]
|
||||
if "system_instruction" in data:
|
||||
data["systemInstruction"] = _transform_part_to_httpx_format(
|
||||
{"system_instruction": data["system_instruction"]}, parent_key=None
|
||||
)["systemInstruction"]
|
||||
del data["system_instruction"]
|
||||
|
||||
return data
|
||||
|
|
|
|||
|
|
@ -827,7 +827,16 @@ def _transform_request_body( # noqa: PLR0915
|
|||
raise e
|
||||
|
||||
if custom_llm_provider in ["vertex_ai", "vertex_ai_beta"]:
|
||||
return _transform_part_to_httpx_format(data) # type: ignore
|
||||
if "contents" in data:
|
||||
data["contents"] = _transform_part_to_httpx_format(
|
||||
{"contents": data["contents"]}, parent_key=None
|
||||
)["contents"]
|
||||
if "system_instruction" in data:
|
||||
data["systemInstruction"] = _transform_part_to_httpx_format(
|
||||
{"system_instruction": data["system_instruction"]}, parent_key=None
|
||||
)["systemInstruction"]
|
||||
del data["system_instruction"]
|
||||
|
||||
return data
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue