Repository navigation
Conversation
Signed-off-by: 1fanwang <1fannnw@gmail.com>
…stream-multiple-choices
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Main now requires OpenAI SDK 1.0 or newer, gzip-compresses OTLP exports and stores metadata values as JSON strings. This merge keeps the per-choice stream accumulation on top of that code. The regression test now decompresses the exported payload and expects the JSON-encoded finish reason. Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
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.
What does this PR do?
Applications streaming several OpenAI chat completions at once receive each choice separately, but Langfuse combines their text and tool calls into one output. The trace can show BA10 and invalid JSON arguments instead of the two replies.
Record each choice separately, ordered by its API choice index. Each keeps its own text and tool calls, matching how non-streaming responses already appear. Single-choice streams retain their existing output shape.
Fixes langfuse/langfuse#16998
Type of change
Verification
Testing Done
Python 3.12.13, Langfuse 5.0.4, OpenAI SDK 2.29.0, OpenTelemetry SDK 1.45.0.
The reproducer drives real sync and async OpenAI clients against a local SSE server and decodes the OTLP payload Langfuse sends over HTTP to a local collector. It exercises interleaved choices with fragmented tool calls and a single-choice text control. No live OpenAI service or deployed Langfuse backend was used.
The unchanged package for the first run comes from 0658c20.
Without the fix:
With the fix:
Reproducer source: repro_stream_choices.py
Reproducer source: repro_stream_choices_against_main.py
Checklist