Skip to content

fix: unwrap the json fence when streaming in schema-less JSON mode - #6

Open
Abhishek-B-R wants to merge 1 commit into
InterfazeAI:mainfrom
Abhishek-B-R:fix/stream-json-fence
Open

Abhishek-B-R wants to merge 1 commit into
InterfazeAI:mainfrom
Abhishek-B-R:fix/stream-json-fence

Conversation

@Abhishek-B-R

Copy link
Copy Markdown

doGenerate strips the ```json fence Interfaze puts around json_object output, but doStream didn't. so streamText with Output.json() never produced a partial object and await output threw NoObjectGeneratedError, while generateText with the same arguments worked fine. that's the combination the run tasks docs show for the AI SDK.

this adds a small streaming version of stripJsonFence. it only holds text back while it can't yet tell whether a fence is opening or closing (the first few chars, and trailing whitespace or backticks), so partial JSON still streams as it arrives. it only runs in the same mode doGenerate unwraps (json, no schema).

tests: a fixture with the fence split across chunks, doStream in both modes, an end to end streamText + Output.json() case, and unit tests for the filter. the two new stream tests fail on main; all 86 pass with the fix. type-check, prettier, build and check:pkg are clean.

@Abhishek-B-R

Copy link
Copy Markdown
Author

@Khurdhula-Harshavardhan friendly bump: this brings doStream in line with doGenerate by stripping the ```json fence in schema-less JSON mode, so streamText with Output.json() yields partial objects instead of ending in NoObjectGeneratedError. It merges cleanly with main, and the one workflow only needs maintainer approval to run. Happy to adjust anything if the approach doesn't fit.

@Abhishek-B-R

Copy link
Copy Markdown
Author

@Khurdhula-Harshavardhan checking back once more: this is still the single commit 9337632 and merges cleanly with main; the one workflow just needs maintainer approval to run on this fork PR. If you'd prefer the fence handling in doStream done differently, I'm happy to rework it.

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