Parsing text into multiple choice values for a Choice form component

Hello Gliders!

I have a workflow in which I want to show a user a set of options to choose from using a Choice component.

For example -
image

However, the set of values to choose from changes for each user and will come from an AI model response (e.g GPT) as part of an Action flow which returns the set of options as text and stores the values in a table cell.

I can affect the structure that GPT returns the options as.
For example -

  1. json object: { option: ‘option a’; option: ‘option b’; option: ‘option c’;}
  2. A sentence: "option a, option b, option c’ "

I know that the Choice component must get the values presented from a table column, and so I assume the question becomes - how can I parse a cell value from one table into multiple rows in another table?

Alternatively, any other ideas for how to present a user with a variable set of options to choose from? As far as I can see, all components which enable selection take their input from a column with each value/option coming from a different row.

Thanks!

Take a look at this:

Worked for me where I got a list of items in a single row and was able to add them to a helper table and display them in a choice component. Sounds exactly what you’re trying to accomplish

2 Likes

It’s a clever ‘transpose’ trick you invented there! But in your example you had a finite and predefined list of possible values which allowed you as the developer to enumerate the values from 0 to 7 in the Array Number column, which was necessary for the Single Value transform to return the next value in the array in each row (in column ‘1 or 0’).

Say I use a split transform on my GPT returned input (e.g “option A, option B, option C”) so now I have an array of values in a column, but I can’t predict how many values the array will have. Any proposals for how to transpose that data into rows?

Well I didnt create it, but my list is also dynamic. I scan an image and have AI extract information. From that information, I use the above method to put that information into individual rows. In my helper table, I added 50 rows to account for the variable # of rows needed. You could use 100 if you needed to. Any unused rows wont be included in your choice component.

I would recommend trying the above but adapting it to your needs

2 Likes

It’s the same method. You just need to ensure you have enough rows in your helper table to cover the maximum possible choices, and that the rows are indexed.

This is a very common pattern in Glide. Talk to almost any expert and they will tell you that they use this technique - and variations of it - in almost every App that they build. I certainly do.

2 Likes

Question : If you did have the need for a helper table that was 50 rows long, and your JSON return was 50 variables/elements long, would that constitute as 50 edits each time you populate the helper table ?

No.
These are computed columns/rows, and updates do not count for those.

1 Like

the rows are populated by a Set Column action and not an “Add Row” action.

1 Like

There is reasonable upper bound to the number of values I expect the AI model (e.g GPT) to return in my input string, so this should work well. I’ll give it a shot, thanks!

Given that this is a common pattern Glide app builders use (as Darren points out), if anyone from Glide is watching this thread it would be useful to have a first class explode or transpose Glide transform for this. Similar to the PySpark explode one.

There has been talk about it, and I guess it’s probably on the list somewhere, along with a bajillion other things we’ve asked for :wink: