Repository navigation
fix(llm-mapper): map Gemini STOP with function calls to tool_calls finish_reason - #5868
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
…nish_reason Gemini returns finishReason STOP even when the turn ended with functionCall parts, so the gateway reported finish_reason 'stop' to OpenAI clients that rely on 'tool_calls' to run tools. Map STOP to tool_calls when the candidate has tool calls, in both the non-streaming and streaming converters.
|
@pcbeingused333 is attempting to deploy a commit to the Helicone Team on Vercel. A member of the Team first needs to authorize it. |
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.
Ticket
No existing issue; found while reading the Google → OpenAI mapper.
Component/Service
Type of Change
Deployment Notes
Extra Notes
Root cause: Gemini reports
finishReason: "STOP"even when the turn ended withfunctionCallparts.mapGoogleFinishReasononly mapped the legacyFUNCTION_CALLreason totool_calls, so the Gemini → OpenAI conversion returnedfinish_reason: "stop"next totool_calls, and OpenAI clients that branch onfinish_reason === "tool_calls"never run the tool. The Anthropic mapper already handles this case.Fix:
mapGoogleFinishReasontakes an optionalhasToolCallsflag;STOPbecomestool_callswhen the candidate has tool calls. Applied in both the non-streaming converter and the streaming converter (using the existingtoolCallIndex).MAX_TOKENS, safety, etc. are unchanged.Test:
packages/__tests__/llm-mapper/google-finish-reason.test.tscovers non-streaming and streaming with and without tool calls, plusMAX_TOKENSwith tool calls stayinglength. Two of its cases fail without the fix.This PR was prepared with AI assistance (Claude Code) and reviewed before submission.
Note
Low Risk
Localized mapper fix with regression tests; no auth, data, or API surface changes beyond correct finish_reason for Gemini tool responses.
Overview
Fixes Gemini → OpenAI mapping when a turn ends with
functionCallparts but Google reportsfinishReason: "STOP". Clients that only run tools whenfinish_reason === "tool_calls"were previously gettingstopalongsidetool_callsand skipping execution.mapGoogleFinishReasonnow accepts optionalhasToolCalls. ForSTOP, it returnstool_callswhen tool calls are present andstopotherwise; other reasons (e.g.MAX_TOKENS→length) are unchanged.Both non-streaming (
toOpenAI/ candidate mapping) and streaming (GoogleToOpenAIStreamConverter, using accumulatedtoolCallIndex) pass whether tool calls were emitted.Adds
google-finish-reason.test.tsfor non-streaming and streaming cases with and without tool calls, includingMAX_TOKENSstill mapping tolengthwhen tools are present.Reviewed by Cursor Bugbot for commit 58246a4. Bugbot is set up for automated code reviews on this repo. Configure here.