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.

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