Table of Contents

GPT-4 in Landbot

Abby Updated by Abby

After a long wait, GPT-4 is now available to the general public! So, how does it differ from GPT3.5?

In a casual conversation, the distinction between GPT-3.5 and GPT-4 can be subtle.

The difference comes out when the complexity of the task reaches a sufficient threshold—GPT-4 is more reliable, creative, and able to handle much more nuanced instructions than GPT-3.5.

One downside, however, is the processing time for tokens. It takes longer than previous versions of GPT which can cause timeouts, so for languages other than English or Spanish, we recommend sticking with GPT3.5 until this has improved

Unfortunately, this iteration doesn't include image recognition, hopefully this will be available soon!

GPT-4 Set Up

So, how do we use GPT-4 in Landbot?

If you want to skip ahead you can download the template and start using it right away, you'll just need your API key from OpenAI

You'll see that it's very similar to GPT3.5, the only thing that changes is the name of the model in the webhook block

We will imagine that you are a food delivery company that needs a customer support bot that attends to customers with delivery incidents. The only objective of the bot is to retrieve what is the incident about, the order number and the user email and finish the conversation when it accomplishes its goal. To do so we will need to adapt the input we send to the OpenAI API with what it expects to receive. Let’s see how to do that

Let’s take a look to the template. Here's a basic overview of what the builder looks like:

Fortunately, downloading the template requires minimal modifications on our end. However, we will proceed by analyzing each block individually to understand its function. To begin, we'll focus on the first half of the flow:

After the Starting point block, we'll add a text question asking how we can help, and we'll save the answer of the user in a variable called @user_text.

We'll connect this text block to a Set Variable block with the following:

[{"role": "system", "content": "your role is to collect complaint information for a food delivery company, the user is writing to us because something went wrong you need to act as an information collector and find out what went wrong, make sure to get their order number and email address, your role is not to help find a solution, only to document what went wrong to then report it, once the information is collected reply with I have all the information I need and say goodbye, rules: only ask one question at a time, and don't provide support you are only an information collector"},{"role": "user", "content": "@user_text"}]

We'll save this in an array type variable called @message_object. This is the format that the API expects to receive the input. As you can see, this array has two elements: the first one ({"role”: “system”, “content”: "..."}) sets the context we will provide to ChatGPT and the second one ({"role”: “user”, “content”: "@user_text"}) is the first message from our user we previously stored.

Notice that by defining the role as “system” is how we say to the model that the content of that message must be used to provide the context we want. Here is where we set the behaviour of the AI and set the instructions we want it to follow. Take into account that the better and clearer instructions we give the better results we will obtain. For example in our case, by stating “your role is not to help find a solution” is how we try to limit hallucinations in its responses and force the model to focus on its goal.

Here's where we can change our use case, in this example we're building a bot for a food delivery company, and then saving the important information to later pass to our database. If you want a use case that better fits your needs you just have to set a different system content.

Next we'll add our OpenAI API key, you can find it here if you already have an account.

In the next Webhook block, we're sending the information to chatGPT and saving the response:

The variable @gpt_content is where we will store the text response we want to show to our user. We’re also saving a variable @gpt_role_message_object which has the following format: `{"role":"assistant", "content": "..."}`. This will make our lives easier in a moment.

In the Question Text, we want to display the response, so we will add the @gpt_content variable and save the user input in the variable @user_text.

We'll connect the Question Text to a Conditions block to check if @gpt_content contains any of the keywords that GPT will use to signal that it has all of the information.

In this case, we've instructed GPT to say 'I have all the information I need' and 'Goodbye' when it has all the required information, so we're checking if that's the case here.

Case 1: Information is not complete

In the case, that not all of the information has been collected, the flow will continue through the red output, where we'll create a loop

The first block after the red output is a Set Variable block, where we'll format the new user input as we need and save it in an array type variable called @user_role_message_object

The next step is to push both the AI response (@gpt_role_message_object already formatted) and the user last message we just wrapped (@user_role_message_object) to our message object that we'll send to GPT.

Push(Push(@message_object, @gpt_role_message_object), @user_role_message_object)

By doing that the @message_object variable will look like:

[
{"role": "system", "content": "<context and rules>"},
{"role": "user", "content": "<first user message>"},
{"role": "assistant ", "content": "<first AI message>"},
{"role": "user", "content": "<second user message>"}, ...
]

That way we can keep the full context of the conversation.

Keep in mind that it has a limit extension that if exceeded may cause the model to underperform so the loop may not last forever.

This then loops back to the webhook block.

Case 2: All information collected

If all the information has been collected correctly, we'll ask GPT to format it into a JSON object, this is completely optional.

To do so, we'll add a Set Variable block with the following:

{"role": "user", "content": "extract all information collected from the previous conversation in json format to be sent to a database with no extra text. The json must follow this structure: {"incident": "", "order_number": "", "email": ""}.}

We'll save that as an array type variable called @user_role_message_object.

Next, using a formula, we'll push this to the array that contains all the conversation the user has had.

Push(Push(@message_object, @gpt_role_message_object), @user_role_message_object)

This will be saved as @message_object as before.

We're then sending that to GPT with another webhook block, it will be identical to the previous webhook block, so we can just duplicate the previous one and add it here.

If everything worked as expected the variable @gpt_content will now store the information retrieved from the conversation with the expected format.

Here's an example of the JSON object with the information collected during the conversation:

How did we do?

How to build a FAQ chatbot with GPT-3

OpenAI

Contact