How to use button click action to submit OpenAI request and display as repeating group text?

I’m learning about Bubble and OpenAI API integrations and created a single page that will send a pre-structured prompt to OpenAI when visitors push the Submit button. I use a pre-structured prompt that integrates their star rating for “quality” and Unusual/Happy/Classic modifiers to request poems from GPT, which I then want to display in the repeating text item. I already created and initialized this call using Bubble’s API connector.

Here’s how that API is linked to the repeating text.

image

My mental model is that I can now link a workflow to the Submit button that fills that text result (a short poem) with results of the OpenAI API call.

I can pick a star rating in Preview mode, yet my Submit button does not seem to trigger any action and the repeating text does not show any response. Do I have the right mental model for this API interaction? Thanks in advance for help!

Okay so I believe the actual JSON structure of the OpenAI response is different

If you are using the completions endpoint, the response should be “choices” “content”

If you can show me the JSON body of the API response, I can try to help you debug this further. The JSON body whenever I set this up looks like

And you can see here the information you always want is “content” first item.

:link: Connect with me

Thanks, I changed the request to match your endpoint and tweaked my request. Here’s an example response, a short review of a London pub.

This is how I define the RepeatingGroup text.

image

Something does seem to happen when I click the Submit button in Preview mode. Note the review text in the blue rectangle using Inspect for that RepeatingGroup.

Perhaps I missed another command that makes the fetched text visible in that text box? :grimacing:

Could you show me your workflows as-well?

Could you set it up similar to this? I call the endpoint, and then display the result in the next step. This waits for the content to be finished first before returning a response

If not, I would be happy to jump in your editor quickly and take a look at your setup if you are still having problems :slight_smile:

Sure thing, my workflow’s one step: tell the repeating text group to fill its contents from the configured API connector. To be honest, I expected to find my API call in this list, so I could make the process more explicit.

When I pick GPT chat completion, however, it looks like I’d use this to send a GPT request independent of my existing API, since I can paste in my API key, size of request, and the text of a prompt.

Appreciate your help with this! Before asking more inside the editor, should I expect my API connector to show up in the plugin menu somehow? Is that the wrong mental model?