Repository navigation
Conversation
Real Gemini ends a function-call turn with finishReason "STOP". Its FinishReason enum has no "FUNCTION_CALL" value, and the live drift reader does not list one. The mock sent "FUNCTION_CALL" by default on every tool-call path: generateContent, streamGenerateContent, the content+toolCalls and blocks paths, audio turns with a tool call, and the same paths on Vertex AI. The default is now "STOP" on all of these paths. An explicit fixture finishReason still wins and maps as before, so "FUNCTION_CALL" and "tool_calls" fixtures still produce "FUNCTION_CALL". Gemini Live does not send a finishReason and is unchanged. Tests that pinned the old default now expect STOP, and the gemini-sse frame goldens are regenerated (only the finishReason value changed).
The Gemini REST API accepts proto field names in snake_case as well as camelCase. PR 662 handled function_call / function_response parts, but the request parser still ignored the snake_case top-level keys that LiteLLM-style and Python REST clients send. - system_instruction, so systemMessage fixtures did not match - tools[].function_declarations (and parameters_json_schema), so the tools were dropped and toolName fixtures did not match - generation_config and its max_output_tokens / top_p / top_k, so the request max_tokens and sampling values were lost normalizeGeminiRequest maps these onto their camelCase names when the camelCase key is absent; camelCase wins if both are set, and a camelCase request is returned as the same object. It runs before body validation in generateContent / streamGenerateContent (Gemini and Vertex AI) and in countTokens, which also accepts a snake_case generate_content_request wrapper. The raw body is still what record mode proxies upstream. Gemini Live is out of scope. The parser does not read toolConfig, inlineData or fileData from request parts, so those keys are not mapped.
commit: |
This branch has not been deployed
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.
Two small fixes to the Gemini handler in
src/gemini.ts. They're in one PR because both touch that file; each is its own commit. Related to #658.1. Tool-call turns end with
finishReason: "STOP"Real Gemini ends a function-call turn with
STOP. Its FinishReason enum has noFUNCTION_CALLvalue, and the live drift reader insrc/__tests__/drift/gemini.drift.tsdoesn't list one either. The mock sentFUNCTION_CALLby default on every tool-call path: tool-only, content+toolCalls,blocks, and audio turns with a tool call, on generateContent and streamGenerateContent, for both Gemini and Vertex AI. All of those now default toSTOP.An explicit fixture
finishReasonstill wins and maps exactly as before:"FUNCTION_CALL"passes through, and"tool_calls"still maps toFUNCTION_CALL(mapGeminiFinishis untouched). Gemini Live doesn't send a finishReason, so it's unchanged.Tests that pinned the old default now expect
STOP. None were deleted. Thegemini-sseframe-codec goldens were regenerated, and only the finishReason value changed.docs/fixturesgets one sentence about the default.Red (unmodified main), with
src/__tests__/gemini-tool-call-finish-reason.test.tsagainst a real server on port 0:Every failure was
expected 'FUNCTION_CALL' to be 'STOP'. The 12 passing tests are the explicit-override controls.Green:
2. snake_case top-level request fields
#662 handled
function_call/function_responseparts. The parser still ignored the snake_case top-level keys that LiteLLM-style and Python REST clients send:system_instruction:systemMessagefixtures didn't matchtools[].function_declarations(andparameters_json_schema): tools were dropped, sotoolNamefixtures didn't matchgeneration_configwithmax_output_tokens/top_p/top_k: the request'smax_tokensand sampling values were lostnormalizeGeminiRequestcopies these onto their camelCase names when the camelCase key is absent. camelCase wins if both are set, and a camelCase request comes back as the same object. It runs before body validation on generateContent and streamGenerateContent (Gemini and Vertex AI), and in countTokens, which also accepts agenerate_content_requestwrapper. Record mode still proxies the raw body. Gemini Live is out of scope.The parser doesn't read
toolConfig,stopSequences,responseMimeType,thinkingConfig, orinlineData/fileDatain request parts, so those aren't mapped.Red (unmodified main), with
src/__tests__/gemini-snake-case-request.test.tsagainst a real server on port 0. It covers all four routes plus countTokens. These are the generateContent and countTokens rows; the stream and Vertex rows fail the same way:The 16 passing tests are the camelCase controls and the "camelCase wins" checks.
Green:
Checks
npx vitest run src/__tests__/gemini*.test.ts src/__tests__/vertex*.test.ts: 408 passedpnpm run typecheck: cleanpnpm build && pnpm api:report: noetc/changeresponse-errors-routesandvalidate-cli, and both files pass on their own (180/180). The machine was heavily loaded.