OpenAI

Abby Updated by Abby

OpenAI is a powerful Natural Language Processing tool, that provides an API that can be easily integrated into your chatbot flow!

OpenAI is known for the creation of the GPT model, a powerful deep learning model capable of producing human-like text.

In this tutorial, we'll show you how to set it up in your bot and start using it right away

TLDR: Download the template here and start playing with GPT3 (must add api key for it to work)

Here's what the builder will look like:

Details
Before starting you'll need to set up an OpenAI account and create an API key

We'll start with a Text Question, here's how we set it up:

We added @response at the top, as that's where the output text from OpenAI will go once we loop back, if there's no response (like in the first iteration) it will simply not appear

The most important thing here is to save @text as the variable, as that's what we're sending to OpenAI

Next we'll add a webhook block with the following url: https://api.openai.com/v1/chat/completions

Next we'll toggle on the Header, and add Authorization as the key, as the Token we'll add Bearer followed by the API key from OpenAI

Next we'll scroll down to Body and toggle it on, we'll then add the following:

{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "@summary @text"
}
]
}

For "role": "system" the "content" contains the system instructions that the model uses.

For "role": "user" the "content" contains the user question to the model.

@text is the variable we saved from the input in the welcome message, this is what will be sent to the API, along with the @summary which is the summary of our previous questions, this will allow us to keep the context of the conversation and let us ask follow up questions.

Let's test this and see if it works! We can add a test phrase and hit 'Test the request'

The response should look something like the above.

In order to show only the text we'll need to save that part by clicking on the purple banner in the save response

Once we've selected choices.0.message.content we'll save it as @response and then loop the webhook back to the welcome message after the formula.

We'll connect the green output of the Webhook to a formula, which will create an array that saves each question asked

This is the formula we'll add: Push(@summary, @text) we'll save it as an array called @summary

Just in case something goes wrong, we'll need an escape route, so we'll connect the red output of the Webhook to the Question Block, allowing the user to try again.

If you'd like, you can use our pre-made template

If you want to learn more about GPT models, we recommend checking Open AI docs here.

Looking to fine-tune your model? Check here

GPT Assistant

Check out our GPT assistant template here

Please note that for this template to work, you must add your OpenAI API key to the Set Variable block, in beginning of the bot

Generate Images with DALLE

Check out our DALLE template here

Please note that for this template to work, you must add your OpenAI API key to the Webhook, in the same format as previously mentioned in this article

OpenAI in WhatsApp

Click here for OpenAI in WhatsApp

How did we do?

GPT-4 in Landbot

Prompt Engineering for GPT-3

Contact