Stream server-sent events as a response from an API (e.g., GPT-3)

We've been using the GPT-3 Completions API a lot in the work we've been doing, and one nice feature is the ability to "stream" GPT-3's completions out as server-sent events.

I'd love to have a Query that pings their API and gets back this stream and inserts it into a textbox, but I can't for the life of me figure out how to do this. Has anyone done this before with GPT-3 or another, similar service?

Hi @casetextjake, have you created a resource for this API yet? With the links you sent, it looks like you should be able to connect using a REST API. Here's our docs for Connecting to a REST API in case you haven't checked it out yet. :slightly_smiling_face:

Hey @casetextjake, stepping in with some more context.

Retool currently does not officially have support for long-lived connection types (WebSockets, Server-Sent Events, etc.) Theres an old popular community post that describes hacking SSE in Retool, but since it's a bit dated it may not apply to current versions.

Our best recommendation is to create a Custom Component to read in those server-sent events.

Hi, @shawntax .
I am very interested in this and I was testing this custom component solution.

The problem is. Once I am implementing the post request inside this custom component on the app, how can I pass my api key to it?
It seems the EXPOSED_API_ env var is only accessible from the resources page.

Any ideas?

Hi @henriquebonadio!

Unfortunately it not currently possible to reference RETOOL_EXPOSED_* environment variables in apps, and by extension, in custom components. So if you need to make an API request in your custom component model, you'll need to hard-code the API key directly.