Skip to content

fix(azure-openai): show the max-output notice when a streamed reply hits the length limit - #1495

Open
pcbeingused333 wants to merge 1 commit into
SciSharp:masterfrom
pcbeingused333:fix/azure-stream-length
Open

pcbeingused333 wants to merge 1 commit into
SciSharp:masterfrom
pcbeingused333:fix/azure-stream-length

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

No linked issue (sibling of #1488: found by comparing the streaming and non-streaming finish handling of the Azure OpenAI provider).

When a streamed Azure OpenAI response ends with finish_reason=length, GetChatCompletionsStreamingAsync took the generic else if (choice.FinishReason.HasValue) branch and returned the truncated text as if it were a complete answer, with no warning. The non-streaming paths (GetChatCompletions, GetChatCompletionsAsync) already log a warning and return "AI response exceeded max output length" for the same case, and the OpenAI streaming provider handles Length too.

Fix: ProviderHelper.ResolveStreamedContent maps the finish reason to the final content: Length returns the same notice as the non-streaming path (new shared MaxTokensMessage constant), anything else keeps the collected text. The streaming branch also logs the same warning as the non-streaming ones.

Test: AzureOpenAiStreamedContentTests covers Stop (text and empty) and Length (text and empty). The Length cases fail with the old behaviour (the helper does not exist on main; the old branch returned the collected text). Adds a project reference to the AzureOpenAI plugin in BotSharp.Core.UnitTests.

This change was prepared with the assistance of an AI coding tool (Claude Code); the author is responsible for the submission.

…its the length limit

The streaming path returned the truncated text as a normal answer when
finish_reason was length; the non-streaming paths already return the
"AI response exceeded max output length" notice.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

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.

1 participant