Streaming function responses with SSE

I’m working on a serverless function in my Redwood app to stream the output of ChatGPT to the client. OpenAI is using server-sent events (SSE) to stream from their API, and I would like to do the same from my Redwood server.

It looks like AWS started supporting streaming responses from Lambda functions earlier this year (Introducing AWS Lambda response streaming | AWS Compute Blog) but I am not sure if Redwood already supports this functionality. AWS seems to provide a global “streamifyResponse” helper that isn’t available locally, and I am not hosting my Redwood app on AWS anyway, so I don’t want to venture into AWS-specific ways to do this.

Is anyone using Redwood with streaming HTTP responses? I’m curious if there is already a “Redwood way” to do so.

Have a look here GitHub - redwoodjs/redwoodjs-streaming-realtime-demos: This app showcases both subscriptions and live queries. It also demonstrates how you can handle streaming responses, like those used by OpenAI chat completions. :slightly_smiling_face:

I was about to share the same thing as Tobbe.

More docs to come but there are two examples that use Live Queries and Subscriptions.

I intend to add Defer and Stream to the Redwood Real-time package as well which I think might work better for OpenAI.

See Defer and Stream – GraphQL Yoga

Actually if you are running and deployed in a serverful manner you could likely just add that plugin to your GraphQL config now.

All above use SSE.