LLM JSON stream to NDJSON stream #56
matteobortolazzo
started this conversation in
Show and Tell
Replies: 1 comment
-
|
Thanks for sharing this streaming option @matteobortolazzo with the Foundry Developer Community! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
A simple Minimal API that parses LLM-generated JSON while still streaming from Semantic Kernel, and produces an NDJSON stream for the client.
This is especially useful to populate a user interface incrementally.
Here's the example code!
The README describes the approach and the challenges.
Features and Screenshots
Technical Details
Challenges and Solutions
IAsyncEnumerable<StreamingTextContent>, which can't be used directly withUtf8JsonReaderUtf8JsonReaderis aref struct, which makesasynccode challenging to useUtf8JsonReaderreads tokens and forwards. So, a state machine is used to understand when to create an event for the clientSystem.Jsonpolymorphism and source generators are used to generate JSON eventsBeta Was this translation helpful? Give feedback.
All reactions