Fix for tool_calls finish reason when last streamed message is empty#4074
Open
dkalinowski wants to merge 1 commit intomainfrom
Open
Fix for tool_calls finish reason when last streamed message is empty#4074dkalinowski wants to merge 1 commit intomainfrom
dkalinowski wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes OpenAI-compatible streaming serialization so finish_reason is correctly reported as "tool_calls" even when the final streamed chunk is empty (a known behavior with some streamers where the last callback may produce "" but still carry STOP).
Changes:
- Add per-stream state tracking (
toolCallsDetectedInStream) to remember whether tool calls were emitted earlier in the stream. - Update
serializeStreamingChunk()to mapSTOPto"tool_calls"if tool calls were detected in any prior chunk. - Add a regression test covering the “tool call ended with
NONE, followed by emptySTOPchunk” scenario.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/test/http_openai_handler_test.cpp |
Adds a regression test ensuring "finish_reason":"tool_calls" is emitted when an empty STOP chunk follows tool-call streaming. |
src/llm/apis/openai_completions.hpp |
Introduces toolCallsDetectedInStream state to track tool-call presence across streamed chunks. |
src/llm/apis/openai_completions.cpp |
Sets the state when tool-call deltas appear and uses it when mapping the final streamed finish_reason. |
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.
🛠 Summary
CVS-182445