Share feedback, ideas and get community help

Updated 2 months ago

Dynamic button generation with OpenAI Assistant

I ask an OpenAI assistant to generate a list of three subjects. Here's my prompt:

...

Present these 3 topics strictly in a list in json format without any other surrounding text like this:
["Subject 1",Subject 2",Subject 3"].

The result will then be used dynamically to propose a multiple-choice block to the user.

...

Then I save the response in a variable.

But when I reuse the variable to display buttons dynamically afterwards, it doesn't work, I just get a button containing the whole list.

How can I correct this misinterpretation?
1
B
F
B
22 comments
I still don't understand how to do it.

There are several avenues to explore to make this work:

  • assistant functions: I don't understand if I should implement it in Typebot or in OpenAI and how to do it
  • there's also a generate variable module, but I don't understand how to use it in this context either
I've discovered something strange: if I display the result in a text bubble just before offering dynamic choices then it works, I get dynamic choices.
There was some kind of bug in typebot for the past couple of days that was causing issues with array and object handling. I can confirm that dynamically displaying array values in a button works for me now so it's probably fixed. Try removing that text bubble to see if it still works.

If you're working with real data and cannot get that to work, issue might be the way you're mapping data back from your API call. See this issue when you need to map it in the strange way I would not expect:
https://discord.com/channels/1155799591220953138/1296874455116812391

If the data you're looking for is inside of array of objects, you can map individual properties into new array with something like this:
Attachment
image.png
notice the JSON.Parse function which is neccessary because Typebot doesn't store Objects, but wraps them inside quotes and stores them as Strings inside array/list variable
Shouldn't I be able to correctly format directly with OpenAI Assistant ?

OpenAI assistant sends me

["Subject 1",Subject 2",Subject 3"]

I store this in a variable. I am not sure to understand why it is not working this way.
Also you propose to use set variable bloc. if really I need to set a variable with json code why not using function option in OpenAI Assistant bloc ?
if you receive simple array like you posted, I think you should be able to map it to variable like you suggested - directly in the block. However I'm not using OpenAI Assistant so cannot verify that for you.
Also, it seems that the array you've posted here for 2 times is missing some quotes. Not sure if it's your typo or if OpenAI returned it to you this way πŸ˜€, but each string in the array needs to be wrapped inside " ". So
["Subject 1",Subject 2",Subject 3"] should be
["Subject 1","Subject 2","Subject 3"]

Here is where the quotes were missing and also how to test that it works:
Attachment
image.png
thank you for your help. I will try this tomorrow.
deleting text bubble does not make it work. my problem does not come from a Typebot bug but from the fact that the Assistant, even if returning the result to the correct format, can not be used a list because it is a text. Weirdly, the fact that I display it before using it as dynamic for buttons make it works. I can’t explain that. I would be interested in having the opinion of an expert here.
the quotes missing were not the problem
I tried it but does not work. Can we access the console in Typebot ?
I found a solution. I generate my result from OpenAI assistant like topic1,topic2,topic3.
Then I use a script that turn it into a json array. It works, but also does not feel very natural and afraid of Assistant not respecting the asked format. So if there is a better and safer solution I am interested.
I get the same issue not being able to display the outputs in the buttons.
Can you show how you do it?
I tried but did not succeed.

In fact I want to generate a variable that allows me to use dynamic buttons in the next block. I tried using the Generate Variables block but it didn't work.

  1. I didn't know how to map the variable. Should I use enum in my case? Let's say I'm trying to generate a list of 3 study subjects. What should I put in the prompt and how should I map this?
  2. Furthermore, the Generate Variables block doesn't allow you to call up an assistant, so you don't get as precise an answer as you would with a wizard trained specifically for your task, am I wrong?
Indeed we are missing the array type
but even with this future improvement, would it be possible to generate arraytype by calling an openai assistant ? currently generate variables can't call an assistant, or am I wrong ?
Oh indeed, it works by prompting a model but not an assistant.
yes so if I want to be sure to generate my variable from the Assistant, I have no choice and have to build something with json by myself right ? If yes, could I request an improvement that will be variable creation from Assistant ?
You will have to do it manually yes with JSON parsing for now πŸ™
Add a reply
Sign up and join the conversation on Discord