3 ms·
how do you do that exactly?
by tough 1y ago
how do you do that exactly?
- richin13 1y agoNot the original commenter but I’ve done this too with Pydantic AI (actually the library does it for you). See “Streaming Structured Output” here https://ai.pydantic.dev/output/#streaming-structured-output https://ai.pydantic.dev/output/#streaming-structured-output
- tough 1y agoThanks yes! Im aware of structured outputs, llama.cpp has also great support with GBNF and several languages beyond json. I've been trying to create go/rust ones but its way harder than just json due to all the context/state they carry over
- danenania 1y agoOne way is to eagerly call JSON.parse as fragments are coming in. If you also split on json semantic boundaries like quotes/closing braces/closing brackets, you can detect valid objects and start processing them while the stream continues.
- tough 1y agoInteresting approach! thanks for sharing
- deleted 1y ago[deleted]