fix(gemini): add missing role="user" to function_response (refs [#206…#20692
fix(gemini): add missing role="user" to function_response (refs [#206…#20692ZqinKing wants to merge 1 commit intoBerriAI:mainfrom
Conversation
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile OverviewGreptile SummaryThis PR adjusts the Vertex/Gemini message transformation so that standalone tool/function response turns are emitted as The change is localized to Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/llms/vertex_ai/gemini/transformation.py | Ensures tool/function response content blocks are emitted with role="user" when converting OpenAI messages to Gemini/Vertex contents; no regressions spotted in the transformation logic, but the PR needs a unit test to cover this formatting requirement. |
Sequence Diagram
sequenceDiagram
participant Client as LiteLLM Client
participant Tx as gemini/transformation.py
participant Vertex as Vertex/Gemini API
Client->>Tx: OpenAI-format messages
Note over Tx: _gemini_convert_messages_with_history()
Tx->>Tx: Convert user/system messages -> Content(role="user")
Tx->>Tx: Convert assistant messages -> Content(role="model")
Tx->>Tx: Convert tool/function result -> Part(function_response)
Tx->>Tx: Append tool/function response Content(role="user", parts=[...])
Tx->>Vertex: RequestBody(contents=[Content...])
Vertex-->>Tx: generateContent response
Tx-->>Client: Mapped response
| messages[msg_i]["role"] not in tool_call_message_roles | ||
| ): | ||
| if len(tool_call_responses) > 0: | ||
| contents.append(ContentType(parts=tool_call_responses)) | ||
| contents.append(ContentType(role="user", parts=tool_call_responses)) |
There was a problem hiding this comment.
Missing regression test
This change fixes Vertex/Gemini request formatting by adding role="user" when appending function_response parts, but the PR doesn’t add a unit test to lock the behavior. Please add a test under tests/litellm/ that builds a message sequence with an assistant tool call followed by a tool/function role message, then asserts the transformed contents includes a ContentType with role == "user" for that function response turn.
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!
|
Fix merged into staging. |
(#20690))
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes