Issue with OpenAI API in WeWeb: Variable Not Updating in Request Body

Hello everyone,

I’m facing an issue integrating OpenAI’s API to generate embeddings with WeWeb.

Context:

  • I’m using OpenAI’s "text-embedding-ada-002" model.
  • I want to dynamically send the value of a variable called “Last Question” as “input” in the API request.
  • I have set up my API in WeWeb with a dynamic JSON body.

Current Request:

In WeWeb, I have configured the request body as follows:

{
“model”: “text-embedding-ada-002”,
“input”: “@{variables[‘Last Question’]}”
}


🔹Problem: The OpenAI API always returns the same embedding, regardless of the value of `Last Question`. It seems that the variable is not being correctly passed into the request body.

The variable Last Question variable is updating correctly (I displayed it on the page to verify).

How should I properly bind the `Last Question` variable to the JSON body in WeWeb so that its value is correctly passed to OpenAI? Is there an issue with the syntax, or how WeWeb handles variable injection in API requests?

Thanks in advance for your help!

Someone to help me? Thanks :slight_smile:

I take it you are running a REST API request from weweb? I don’t know where the “configure as follows” is getting set up. That’s not parallel to what the nocode setup looks like. If you share screenshots or a video, might be easier for you to get help from the very nice people on this forum.

Sounds like something wrong with the way you are calling the open AI model rather than a problem with the input being passed to it…

Thank you for your feedback. To further explain my issue, here are some additional details.

I am working on creating a legal chatbot that uses RAG technology.
I use Supabase to host my legal documentation and WeWeb for the user interface.

On WeWeb, I have a very simple front end with a question form that triggers a workflow when the user submits a question by clicking the validation button.

The first step of my workflow is saving the user’s question in a variable called Last Question.

The second step is making an API call to OpenAI via a REST API request. I want to retrieve the embedding vector of the user’s question. Here’s how I have configured my REST API request:

Type: REST API Request
Method: POST
URL: https://api.openai.com/v1/embeddings

Header:

  • Key: Authorization
  • Value: Bearer my API key

Content Type: application/json

I clicked on raw body and in the body, I have the following formula:

{
“model”: “text-embedding-ada-002”,
“input”: “@{variables[‘Last Question’]}”
}

I think there is a problem with my formula because the API request always returns the same vector, regardless of the question asked.

In the video, I can see that my question is correctly saved in Supabase, and I do get an embedding vector, but it does not change when a user asks a new question.

Watch the video