With the OpenAI block, you can create a chat completion based on your user queries and display the answer back to your typebot.
This integration comes with a convenient message type called Dialogue. It allows you to easily pass a sequence of saved assistant / user messages history to OpenAI:
Then you can give the OpenAI block access to this sequence of messages:
The tools section allows you to add functions that the OpenAI model can execute. Here is an example of a function named getWeather
that returns ‘Sunny and warm’ if you ask about the weather of Paris and ‘Rainy and cold’ if you ask for any other city 😂.
A more useful example would be, of course, to call an API to get the weather of the city the user is asking about.
As you can see, the code block expects the body of the Javascript function. You should use the return
keyword to return value to give back to OpenAI as the result of the function.
If you’d like to set variables directly in this code block, you can use the setVariable
function.
This action allows you to talk with your OpenAI assistant. All you have to do is to provide its ID.
If you defined functions in your assistant, you can define the function to execute in the Functions
section.