-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
fix(vertex_ai): strip LiteLLM-internal keys from extra_body before merging to Gemini request #23131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -529,12 +529,18 @@ def _gemini_convert_messages_with_history( # noqa: PLR0915 | |||||
| raise e | ||||||
|
|
||||||
|
|
||||||
| # Keys that LiteLLM consumes internally and must never be forwarded to the | ||||||
| _LITELLM_INTERNAL_EXTRA_BODY_KEYS: frozenset = frozenset({"cache", "tags"}) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded internal-key list is Vertex AI-only and incomplete
Additionally, LiteLLM's proxy layer reads other internal keys from A more robust approach would be to centralise this filtering at the point where
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type annotation on frozenset is redundant The type annotation
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||
|
|
||||||
|
|
||||||
| def _pop_and_merge_extra_body(data: RequestBody, optional_params: dict) -> None: | ||||||
| """Pop extra_body from optional_params and shallow-merge into data, deep-merging dict values.""" | ||||||
| extra_body: Optional[dict] = optional_params.pop("extra_body", None) | ||||||
| if extra_body is not None: | ||||||
| data_dict: dict = data # type: ignore[assignment] | ||||||
| for k, v in extra_body.items(): | ||||||
| if k in _LITELLM_INTERNAL_EXTRA_BODY_KEYS: | ||||||
| continue | ||||||
| if k in data_dict and isinstance(data_dict[k], dict) and isinstance(v, dict): | ||||||
| data_dict[k].update(v) | ||||||
| else: | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Truncated comment
The comment on line 532 is cut off mid-sentence — it currently reads
# Keys that LiteLLM consumes internally and must never be forwarded to thewith no completion. This should be finished to explain what the keys must not be forwarded to.