Help: How to get data from Open AI JSON request

Hei Bubblers, I still working with Open AI and trying to create an Assistant. And I dont understand the logic of giving a response and retrieve an information from the response. I would really appreciate if you help me with that.

Task overall: To create a system of generating OpenAI messages depends on users input and save it into a database in order to reuse responses later.

workflow Id

My issues/current task:
I am getting a response (JSON from Open AI) but when I am trying to save the response to a variable somehow I am getting an information not from the latest item but from 3rd item in JSON.

What I am doing and how:
Step 1: I set a connection with Open AI through API connector. You can check a screen with a response in the attachment.

Step 2: My workflow and Interface. I have few elements.
A. Input Element - A user can upload text
B. Text element - Displays of Open AI response
C. Button Element - When user click β†’ Launch Workflow:
Step 1: Create POST request to send users message
Step 2: Run a Run. (put message into a thread)
Step 3: Make a pause (I added that step just to be sure that Open AI created a response)
Step 4: (Issue step) Create a custom state with latest item id. (screen attached) β†’ Get external data AND ID.

But, what I need is to get ID from the latest message in a thread. Instead it is taken from third message. I tried different combinations such as:

  • Get data from ext. api β†’ data β†’ Last item β†’ id
  • Get data from ext. api β†’ data β†’ Last item β†’ item Number

I assume that JSON is request to give an id and JSON requested to POST a message somehow working asynchronically or request are sent asynchronically.
I dont understand how it works in bubble.

Anyone can help me with that?

1 Like

Just as a resource, have you checked out @jamesdevonport’s newsletter that talks through integrating and using OpenAI’s JSON requests?

I created small video about what is wrong - Bubble | No-code apps - 7 May 2024 | Loom

Could you help me to retrieve latest msg id? And if it would be possible may be you can explain what I am doing wrong?

If the JSON response is constant, you can setup another API request to actually process the JSON structure

Explained in this thread: You can’t stream natively in Bubble. Your best bet is to poll it efficiently (atleast for now)

Check this out: How to Poll OpenAI in Bubble's Backend

1 Like