fix(provider): throw NoContentGeneratedError when a response has no choices - #500
Open
shoemoney wants to merge 1 commit into
Open
fix(provider): throw NoContentGeneratedError when a response has no choices#500shoemoney wants to merge 1 commit into
shoemoney wants to merge 1 commit into
Conversation
openAIResponseSchema allows an empty choices array, so a 200 response with no choices crashed doGenerate with an unhandled TypeError when dereferencing response.choices[0].message. Throw NoContentGeneratedError with a clear message instead, in both the V2 and V3 language models. Adds a regression test per model: a 200 response with empty choices now produces NoContentGeneratedError rather than a TypeError.
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.
openAIResponseSchemaallows an emptychoicesarray, so an HTTP 200 response of{"choices": [], "usage": {...}}crashesdoGeneratewith an unhandledTypeErroratresponse.choices[0].messagein bothStripeLanguageModel(V2) andStripeLanguageModelV3. The dereference sits outside the try/catch, which only wrapspostJsonToApi, so callers get a rawTypeErrorinstead of a typed SDK error.This adds an explicit guard after
response.choices[0]in both models that throwsNoContentGeneratedErrorfrom@ai-sdk/provider, the SDK's standard error for a response with no generated content, with a clear message.Tests: one regression test per model asserting a 200 response with empty choices rejects with
NoContentGeneratedError. Both fail withTypeErrorbefore the fix and pass after. Full suite: 331 passing.