How to use Server Sent Events with HttpClient
I'm working with an API framework (https://docs.mistral.ai/api/#operation/createChatCompletion) in which you send a chat request. If you set the stream parameter to true:
To handle this, I created an SssEvent class with the following properties:
I have the code working for non-streaming calls, but I'm confused as to how to send my initial message and then stream back the response. My code currently looks like this:
https://paste.mozilla.org/BD3gMX5o
4 Replies
I'm not too sure of what you mean with server sent events but do you perhaps mean websockets?
No I mean server sent events
https://en.wikipedia.org/wiki/Server-sent_events
Server-sent events
Server-Sent Events (SSE) is a server push technology enabling a client to receive automatic updates from a server via an HTTP connection, and describes how servers can initiate data transmission towards clients once an initial client connection has been established. They are commonly used to send message updates or continuous data streams to a b...
In the wikipedia it looks like SignalR would be SSE compliant , or you could use https://docs.servicestack.net/server-events
if you want to only use HttpClient, I'm guessing you'd have to end up doing a
GetStreamAsync
and handle that input streamIdeally using only httpclient as I’m writing a library and would like to avoid external dependencies if possible