is there any way, I can receive a sse response fro...
# http4k
k
is there any way, I can receive a sse response from other server? just like I send sse with http4k?
d
I'm afraid there is no SSE client in http4k currently, so you'll have to search for one without the http4k types 🙂
k
OK
d
I'd probably recommend the OKhttp one out of what I could find: https://github.com/square/okhttp/tree/master/okhttp-sse
a
Is this for a server listening to SSE? If so, you would usually use a dedicated message broker like Kafka or Amazon SNS with SQS. They would help you deal with retries and ensure messages are delivered at least once. It's much more fault tolerant than SSE, and helps ensure services don't get out of sync. This is likely part of the reason why http4k doesn't have any support for an SSE client.
k
I listen stream api from openAi(or some other ai), then process it and send it one by one to the client( my frontend). so I use http4k sse to send the msg. I use a lib to receive openai stream chat. but for other ai there is no lib, so I have to impl it myself. that's why I want to know, is http4k has same sse client like http client
🆗 1
d
If you want you can use a standard http4k client, intercept the stream and chunk it manually on double newline. We do have an openai API module in http4k connect, but it doesn't currently implement the streaming chat action - this wouldn't be too hard to adapt I think to return a Sequence instead of the full response..
k
yes. I use
com.theokanning.openai-gpt3-java:service
who use
retrofit
to do the stream. now I try okhttp-sse to impl the other ai stream response. at the same time, I think, in http4k, http as a Function. so http4k server and http4k client are all function that invoke request to get response. is there a way that we can do the same with sse as http4k server and client?