Skip to content

fix(OpenAI): keep logprobs on streamed chat choices - #849

Merged
iBotPeaches merged 1 commit into
openai-php:mainfrom
pcbeingused333:fix/stream-logprobs-c3208
Nov 14, 2026
Merged

iBotPeaches merged 1 commit into
openai-php:mainfrom
pcbeingused333:fix/stream-logprobs-c3208

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

What:

  • Bug Fix
  • New Feature

Description:

Chat completion chunks requested with logprobs => true carry choices[].logprobs, but CreateStreamedResponseChoice::from() read only index, delta and finish_reason, so the token log probabilities were dropped from every streamed chunk. The non-streamed CreateResponseChoice already exposes them.

CreateStreamedResponseChoice now has a nullable logprobs, parsed with the existing CreateResponseChoiceLogprobs. Chunks without logprobs keep logprobs null and toArray() omits the key, so existing payloads round-trip unchanged.

Tests cover a chunk with logprobs, a chunk without, and toArray() with logprobs. The first and last fail on main. The Chat tests pass (98 passed, deprecation notices already on main). Pint and PHPStan are clean.

This change was prepared with an AI coding assistant.

Streamed chat chunks requested with logprobs=true carry choices[].logprobs, but CreateStreamedResponseChoice dropped them. Parse it with CreateResponseChoiceLogprobs, as the non-streamed choice does.
@iBotPeaches

Copy link
Copy Markdown
Collaborator

thanks!

@iBotPeaches
iBotPeaches merged commit 41e2808 into openai-php:main Nov 14, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants