[v6.0] fix(provider/xai): extract reasoning text from content in responses doGenerate#16798
Merged
Conversation
…oGenerate (#13372) xAI's non-streaming responses API returns reasoning text in the `content` field on reasoning output items (as `reasoning_text` parts), not in the `summary` field. the SDK only read from `summary`, so reasoning was silently dropped in `generateText` - streaming worked fine since it uses `reasoning_summary_text.delta` events - add `content` field to the reasoning output item schema in `xai-responses-api.ts` - read reasoning text from `content` when `summary` is empty in doGenerate - add test for the content fallback path - add generate-text reasoning example <details> <summary>before: no reasoning shown</summary> ``` $ pnpm tsx src/generate-text/xai/responses-reasoning.ts --- text --- The word "strawberry" contains **3** instances of the letter "r". ``` </details> <details> <summary>after: reasoning properly extracted</summary> ``` $ pnpm tsx src/generate-text/xai/responses-reasoning.ts --- reasoning --- First, the user asked: "How many 'r's are in the word 'strawberry'?" I need to count the number of times the letter 'r' appears in the word "strawberry". Let me spell out the word: S-T-R-A-W-B-E-R-R-Y. Now, let's go through each letter: 1. S - Not an 'r' 2. T - Not an 'r' 3. R - This is an 'r' (first one) 4. A - Not an 'r' 5. W - Not an 'r' 6. B - Not an 'r' 7. E - Not an 'r' 8. R - This is an 'r' (second one) 9. R - This is an 'r' (third one) 10. Y - Not an 'r' So, the 'r's are at positions 3, 8, and 9. That means there are 3 'r's in "strawberry". --- text --- The word "strawberry" contains **3** instances of the letter "r". ``` </details> - [x] tests have been added / updated (for bug fixes / features) - [ ] documentation has been added / updated (for bug fixes / features) - [x] a _patch_ changeset for relevant packages has been added (run `pnpm changeset` in root) - [x] i have reviewed this pull request (self-review) --------- Co-authored-by: Felix Arntz <felix.arntz@vercel.com> (cherry picked from commit 12115e9)
Contributor
|
|
Contributor
|
🚀 Published in:
|
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.
Backport of #13372 to the release-v6.0 branch. xAI's non-streaming responses API returns reasoning text in the
contentfield on reasoning output items (asreasoning_textparts), not only insummary, so reasoning was silently dropped ingenerateText. This ports the fix: the reasoning output item schema gains thecontentfield, and doGenerate falls back to reading reasoning text fromcontentwhensummaryis empty. During conflict resolution, v6's existing condition (reasoningText || part.encrypted_contentwith thehasMetadataproviderMetadata spread, which supports encrypted content with empty reasoning text) was kept intact instead of main's olderif (reasoningText)structure, and both v6's existing encrypted-content test and the new content-fallback regression test were retained. Part of the v6.0 backport tracking issue #16767.