Repository navigation
fix(gemini): accept snake_case function_call/function_response parts - #662
Merged
Merged
Conversation
commit: |
The Gemini API accepts proto field names in snake_case, and LiteLLM's Gemini/Vertex transformation sends tool calls and results that way. The request parser only read functionCall/functionResponse, so a snake_case tool result became an empty user turn and tool-result fixtures did not match (404). Map the snake_case keys onto the camelCase names before parsing; camelCase parts pass through unchanged. Fixes #658
jpr5
force-pushed
the
fix/gemini-snake-case-function-parts
branch
from
December 3, 2026 23:33
4494be7 to
b80d5a7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #658
The Gemini API takes the proto field names in snake_case as well as camelCase, and LiteLLM's Gemini / Vertex AI transformation (so Google ADK agents on
LiteLlm) sends tool calls and results asfunction_call/function_response. The request parser insrc/gemini.tsonly looked atfunctionCall/functionResponse, so a snake_case tool result turned into an empty user turn andhasToolResult/toolResultContains/userMessagefixtures didn't match (404).The fix maps
function_call/function_responseonto the camelCase names before the parts are read, in both the user and model branches ofgeminiToCompletionRequest. A part that already uses camelCase is returned as the same object, so camelCase requests behave exactly as before. If a part somehow has both spellings, camelCase wins.Red / green
New test
src/__tests__/gemini-snake-case-parts.test.tsstarts a real aimock server with the fixture from the issue and sends the issue's three-turn request to bothstreamGenerateContent?alt=sseandgenerateContent, once with snake_case parts and once with camelCase (control).Before the fix (unmodified main):
After the fix:
I also ran the issue's repro (empty fixtures, fixture added through
/__aimock/fixtures, then the streaming request) against the CLI:Not in this PR
src/ws-gemini-live.ts) reads the same part keys, but a snake_case Live client would also sendclient_content/tool_response/function_responsesat the message level, which that handler doesn't read either. Fixing only the parts there wouldn't help anyone, so I left Live alone.inline_data/file_data. The request parser doesn't readinlineData/fileDataeither, so both spellings are already treated the same way and there is nothing to fix for matching.