openai / openai-dotnet

The official .NET library for the OpenAI API
https://www.nuget.org/packages/OpenAI/AbsoluteLatest
MIT License
722 stars 62 forks source link

Replace custom SSE reader with source for System.Net.ServerSentEvents #33

Closed stephentoub closed 2 weeks ago

stephentoub commented 3 weeks ago

A stable package for the new System.Net.ServerSentEvents library isn't yet available, but until one is we can switch the code over to using a source copy.

The natural replacement for ServerSentEvent is SseItem<string>, but I used SseItem<byte[]> instead just to avoid an unnecessary UTF8->UTF16->UTF8 roundtrip. It could be taken further in the future to avoid allocation by doing more of the parsing inside of the callback passed to SseParser.