How to load Open API response to a variable which is then displayed

I followed the “OpenAI plugin in Weweb- Live Demo” to make a simple question and answer app to learn how this works.

I have successfully retrieved the response:
'‘Call openAI.result.choices[0].message.content’

How do I capture this response into a variable, and then display it in text field?

The video shows that the next steps in the workflow are:

  1. Return value
  2. Change value variable

But doesnt go into the detail, i’ve been trying for hours to figure out which forumla to use and where with no success!

If you have received the response from OpenAI you can use return value or change variable value actions and as the value you can bind to the result of a previous action

I have the result.

How do I bind the value from the message I received to a variable?

I did a drill down like what shows on your screen shot and the following shows the result:

Call openAI.result.choices[0].message.content

How do bind that to a variable.

I tried the following in the function box:

My variable = Call openAI.result.choices[0].message.content

But I must be missing something.

Have you tried the “change variable value” action step after you complete your chat request? Here’s a quick screenshot of how that would look:

Hi Ray,

Yes. It’s that formula inside that second action that I’m stuck with.

How do I retrieve the message and populate in the second action?

Hi @Dervish99 :wave:

Before you can use the result from action 1 in action 2, you will need to test action 1 to get a result. Then, you will be able to access that result and use it in action 2.

Here’s an example of a file upload workflow that uses similar logic.

1 Like

Thank you Joyce, after following your link, i go to the solution via a similar doc.

For other users benefit, the solution was to:

  1. Capture the OPENAI response from the workflow, by selecting the path in the ‘context’ next to the foruma, the path can be seen in the formula box,
  2. and then assigning this to the ‘Change Value Variable’ . The examples online had "return a value’ step instead. which i’m not show how is used, anyway using the below it worked. Hope it helps:

Overview of workflow:

Details of the third action:

3 Likes

Awesome! Thanks a lot for taking the time to share the solution for this use case as well, I’m sure it will help future readers :blush:

“change a variable” then select your result from open ai api call, then bind your text on your page with the variable.