How do I deal with variable inputs?

Hi All,

I would love some help or advice on the following.
I’m trying to build a site where users can input unformatted strings - I send them via API to ChatGPT which organizes and returns the strings in a structured format that I can then save and send to the user.

The problem I’m running into is setting up workflows when I have unknown variable amounts of inputs and outputs. I have grouped the inputs into ONE send because chatGPT can separate the strings but I don’t know how many will come back. Therefore, using plugins like “Read Json and get value by key” don’t do me any good because I don’t know if I should setup 4 step worksflows of 14 to read and extract each data point.

Can you give an example of response you get? (JSON format)

Totally. Here is user 1’s response:

[
  {
    "rec_name": "La Alquimia vinos naturales",
    "category": "Drink",
    "location": "C. de Amador de los Ríos, 1, 28010 Madrid, Spain",
    "user_com": "Fantastic spot, wines from around Europe but with a focus on Spain, super helpful and friendly staff.",
    "website": "https://www.facebook.com/LaAlquimiaMadrid",
    "money": "Unknown"
  },
  {
    "rec_name": "FUN FUN vino natural",
    "category": "Drink",
    "location": "Calle de Don Pedro 20, 28005 Madrid Spain",
    "user_com": "The name is on point .. super hip, no set wine menu it’s always on rotation, also super helpful staff.",
    "website": "https://funfunmadrid.com/",
    "money": "Unknown"
  },
  {
    "rec_name": "La Trainera",
    "category": "Eat",
    "location": "not found",
    "user_com": "Huge seafood spot, fantastic food, felt like a locals spot. Came recommended by a madrileños we met there who also lived in BK.",
    "website": "not found",
    "money": "Unknown"
  }
]

Here is user 2’s response:

[
  {
    "rec_name": "Ob-La-Di",
    "category": "Eat",
    "location": "54 rue de Saintonge, 75003 Paris, France",
    "user_com": "A charming cafe in Le Marais known for its coffee and vegan options, with a cozy atmosphere perfect for breakfast or brunch.",
    "website": "https://www.facebook.com/ObLaDiParis",
    "money": "Unknown"
  },
  {
    "rec_name": "Dreamin Man",
    "category": "Drink",
    "location": "not found",
    "user_com": "Could not find specific details, please provide more or check a dedicated Paris guide.",
    "website": "not found",
    "money": "Unknown"
  },
  {
    "rec_name": "Paperboy",
    "category": "Eat",
    "location": "not found",
    "user_com": "Could not find specific details, please provide more or check a dedicated Paris guide.",
    "website": "not found",
    "money": "Unknown"
  }
]

And what do you want to do with this data? The JSON is well formatted and there’s no need to use a plugin to read it as Bubble will do it from API Connector.

I want to show it back to the user and allow them to save it if they’re happy with it.

So user flow would be something like this:

  1. User navigates to page
  2. User inputs a list of recommendations
  3. Those recommendations get formatted and returned from chatGPT
  4. The recommendations are shown to the user and they can save them to their profile

I thought I could do this with a repeating group where I set a repeating group (to show the recommendation) and within each group would be the specifics of the recommendation (i.e. category, location, user comment, website, money). What I’m running into when I try to use the plugins I’ve seen or the workflows in Bubble is that to extract specific data I need to set up the steps for a pre-determined number of responses.
(i.e. step 1 “read json and get value by key” for first item “recommendation_name”. Step 2 read json and get value by key for first item “category”.) And this would work if I knew that users would only submit 3 recommendations to be formatted but what if they send 6 or 10? I can’t have a workflow that looks for the json response’s second item, third item, fourth item, and then within each item the name, category, website, location, comment, etc…

I’m hoping there is a much more straightforward way to do this

There’s no need to use a plugin. When you get the JSON with API Connector, and set it to be parsed by Bubble, this is already usable. You can use a RG of the type or API Call and set the source with the RG. Each line will be an object of JSON Array. (exemple, line 1 will be

{
    "rec_name": "La Alquimia vinos naturales",
    "category": "Drink",
    "location": "C. de Amador de los Ríos, 1, 28010 Madrid, Spain",
    "user_com": "Fantastic spot, wines from around Europe but with a focus on Spain, super helpful and friendly staff.",
    "website": "https://www.facebook.com/LaAlquimiaMadrid",
    "money": "Unknown"
  }

You will be able to set a text element for rec_name, category, location, user_com, website and money. Add a button “save” and just add workflow to save current cell API Data type to Bubble DB

Thanks so much for trying to help, however I keep running into issues when I’ve tried this approach.

  1. Here I am trying to set the Repeating Group to receive the response from the API…it keeps forcing me to go down several layers and if I leave it at the level I want (Open AI - Chat GPT call’s body choices: each item’s message content) then I get the red text indicating an error.
    Screen Shot 2024-03-20 at 12.47.12 PM

  2. Likewise if I try to set up a workflow to display text in a repeating group, I have the same problem.
    Screen Shot 2024-03-20 at 12.47.36 PM

Does this mean that I have an issue with the full response of the API call?
When I run this in the Debugger it seems fine (I get the response I expected) but no text is showing!

Would you be willing to chat on the Discord server @jici?

The RG should be set as “Open AI - Chat GPT Call’s body choices” (maybe message content, I don’t have the whole JSONpayload, so not sure what is your setting) for the type.
In API Connector, you should set this call to “Data”
In action display list, this should be the API Call in Data source (or you could set it directly in the RG depending of your setting)
You will be able to select

I guess that rex_type is a Bubble DB?.. this is what you will create when user will click save…

Hi Jici, I really appreciate this.

I tried adjusting as you suggested but I still can’t complete this.
It seems to be caused by the fact that when I am selecting the API response, Bubble keeps showing me a red selection if I stop at Message Content.


Screen Shot 2024-03-20 at 1.24.36 PM

I wonder if it is related to how the response is coming back initially?

I don’t see this in your API Connector initialization screen

{
    "rec_name": "La Alquimia vinos naturales",
    "category": "Drink",
    "location": "C. de Amador de los Ríos, 1, 28010 Madrid, Spain",
    "user_com": "Fantastic spot, wines from around Europe but with a focus on Spain, super helpful and friendly staff.",
    "website": "https://www.facebook.com/LaAlquimiaMadrid",
    "money": "Unknown"
  }

Where this should be?
Actually, your are getting red error because the type of content + data source are not the same…

Hello, Can you share the solution?