fix: native llama reasoning stream and provider options#216
Open
JKobrynski wants to merge 3 commits into
Open
Conversation
|
@JKobrynski is attempting to deploy a commit to the Callstack Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the @react-native-ai/llama adapter to (1) prefer native structured streaming fields (tokenData.reasoning_content / tokenData.content) when available, and (2) forward providerOptions.llama into llama.rn completion options via a shared builder helper.
Changes:
- Update the stream parser to emit incremental deltas based on native accumulated
reasoning_content/contentfields, while keeping the placeholder-based fallback path. - Extract completion option construction into
buildLlamaCompletionOptionsand addproviderOptions.llamapassthrough. - Add/extend unit tests for native streaming behavior and completion option passthrough.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/llama/src/streamParser.ts | Prefer native parsed content/reasoning_content and emit suffix deltas; adjust tool-call flushing logic. |
| packages/llama/src/completionOptions.ts | New helper for preparing messages (multimodal) and building completion options with providerOptions.llama passthrough. |
| packages/llama/src/ai-sdk.ts | Refactor to use shared completion-options builder and message preparation helper. |
| packages/llama/src/index.ts | Export completion-options helpers from the package entrypoint. |
| packages/llama/src/tests/streamParser.test.ts | Add coverage for native parsed streaming and tool-call edge cases. |
| packages/llama/src/tests/completionOptions.test.ts | Add focused tests for providerOptions.llama passthrough behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+328
to
+335
| const hasNativeParsedContent = | ||
| tokenData.content !== undefined || | ||
| tokenData.reasoning_content !== undefined | ||
|
|
||
| if (hasNativeParsedContent) { | ||
| processNativeParsedContent(tokenData) | ||
| return | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Good point, addressed
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.
Related issue - #199
Summary
Improves the
@react-native-ai/llamastreaming adapter by preferring native parsed reasoning/content fields fromllama.rnwhen they are available, instead of relying only on placeholder parsing of raw token text.Previously, the adapter inferred reasoning boundaries entirely from streamed token markers like
<think>...</think>. That fallback parser remains useful, but newerllama.rnversions can expose native structured fields such astokenData.reasoning_contentandtokenData.content, which are a more reliable source of truth.This change updates the stream parser to use native parsed fields when present, emit proper incremental deltas from their accumulated values, preserve fallback placeholder parsing when native fields are absent, and keep tool-call behavior intact across both paths.
Changes
tokenData.reasoning_contentfor reasoning stream output when availabletokenData.contentfor normal text stream output when available<think>markers inside tool-call payload text untouched<think>markers inside tool-call payload text untouchedbuildLlamaCompletionOptionsproviderOptions.llamapassthroughTesting
bun test packages/llama/src/__tests__/streamParser.test.tsbun test packages/llama/src/__tests__/completionOptions.test.ts./node_modules/.bin/tsc --noEmit --project packages/llama/tsconfig.json./node_modules/.bin/tsc --noEmit --project packages/llama/tsconfig.build.jsonbun lint<think>markers<think>markers inside tool-call payloads