# Connect ChatGPT with WhatsApp in Gallabox Chatbot

> **Who can use this Card?**
>
> * Gallabox Users having permission to either build and deploy bots or manage bots.
> * Available on Pro Plan.

## Overview

Embark on a journey of enhanced conversational AI with the Open AI connector. This guide navigates you through the seamless integration process, helping you choose actions like Create Completion and Chat Completion for a customized Open AI experience.

### Connect Open AI

1. Choose the connector - Open AI from the list of connectors.&#x20;

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2FSbwKpSp5wAmLPN13PVkc%2Fopen_Ai_connector.png?alt=media&#x26;token=42b9e740-ca87-4bcf-92d9-519f314e09dd" alt=""><figcaption></figcaption></figure>

2. After clicking on Open AI Connector, you will see the actions - Create Completion and Chat Completion.&#x20;

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2FCWFGGRe2jKAVnTockq6C%2Fopen_Ai_actions.png?alt=media&#x26;token=56130b23-50ab-4096-9b11-23029b169fc0" alt=""><figcaption></figcaption></figure>

3. After you click on one of the Actions, it will ask you to Add New Connection or Select Existing Connection. If you haven't made any connection, see if the Connection Name is fine with you and proceed with pasting the API Key. You will find the guide to find the key [here](https://platform.openai.com/docs/api-reference/authentication).&#x20;

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2FCxWyHQvA5KfTTmgPJkrj%2Fopen_Ai_create%20connection.png?alt=media&#x26;token=ffbb6acf-6704-4a2f-a6ee-44356c8f174f" alt=""><figcaption></figcaption></figure>

Paste the API Key and click on Create Connection.&#x20;

4. If the Open AI connection has already created, go to Select Existing Connection and click on Connect.&#x20;

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2F6b1h7768TBf4PBByLmpH%2Fopen_Ai_exisiting_connection.png?alt=media&#x26;token=91facfe1-5404-4c1f-acee-adbdd11beafe" alt=""><figcaption></figcaption></figure>

### Using Open AI Connector

1. Once the connection is created, click on **Connect** besides the connection to start configuring the connector and it will take you to the action that you selected.

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2F6b1h7768TBf4PBByLmpH%2Fopen_Ai_exisiting_connection.png?alt=media&#x26;token=91facfe1-5404-4c1f-acee-adbdd11beafe" alt=""><figcaption></figcaption></figure>

2. After clicking on connect the selected the Action - **Chat Completion** opens and you will have to edit the value for Context, user prompt, Model, Max Tokens, Temperature, and the variable. <br>

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2FilxxsMFdd9Xc4CaxLg5O%2Fopen_Ai_chat_completion_action.png?alt=media&#x26;token=9d602ceb-04f9-4669-a9f5-d3598361686c" alt=""><figcaption></figcaption></figure>

3. For the context, you can write - **If Intent is either Feedbacks, Products, Product, Register, Hi, Main menu, Match the user input to the correct intent give the intent as it is, If it does Match give as default.**

{% hint style="info" %}
You can change the Intents as per your bot, keep the rest of the text same for the card to work. The  context would be - If Intent is either *Intent 1, Intent 2, Intent 3, Intent 4, Intent 5, Intent 6*, match the user input to the correct intent give the intent as it is, If it does Match give as default.
{% endhint %}

<figure><img src="broken-reference" alt=""><figcaption></figcaption></figure>

4. In the User Prompt field, you have to add the variable as {{intent.text}}<br>

<figure><img src="broken-reference" alt=""><figcaption></figcaption></figure>

5. There is only one model for the action - **Chat Completion** that you have to select.<br>

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2FdZ5cMHI3XUro01erQ5vM%2Fopen_Ai_chat_completion_action_model.png?alt=media&#x26;token=4484f5b4-413e-4e3e-8587-4063eb11a6e7" alt=""><figcaption></figcaption></figure>

5. The Token is pieces of words. In terms of length:

* 1 token \~= 4 chars in English
* 1 token \~= ¾ words
* 100 tokens \~= 75 words

&#x20;                     **Or**

* 1-2 sentence \~= 30 tokens
* 1 paragraph \~= 100 tokens
* 1,500 words \~= 2048 tokens

Learn more about Tokens [here](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them).

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2FbnrXWyN8tt7JNFfLUr0n%2Fopen_Ai_chat_completion_action_max_tokens.png?alt=media&#x26;token=645adf3d-26b6-4559-86b9-6627a43897ee" alt=""><figcaption></figcaption></figure>

6. Sampling temperature controls the randomness of the text generated by Open AI. A higher temperature (e.g., 0.7) results in more diverse and creative output, while a lower temperature (e.g., 0.2) makes the output more deterministic and focused.

   The default temperature setting for Open AI is 0.7, which strikes a balance between creativity and consistency. You can experiment with different temperature settings to see what works best for you.&#x20;

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2F1ZSjDIgb94UKWAGvexJ7%2Fopen_Ai_chat_completion_action_temperature.png?alt=media&#x26;token=949b60c0-8c49-47b7-ae66-d8686400bdaa" alt=""><figcaption></figcaption></figure>

7. You have to create or select a variable to store the AI response.&#x20;

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2F0Hzd9sOmuZ1HLgBKbIhJ%2Fopen_Ai_chat_completion_action_variable.png?alt=media&#x26;token=a9f16d50-a2ab-4ece-8084-304b6ea2dbeb" alt=""><figcaption></figcaption></figure>

Once you have done pasting the values for all the fields in the action either Create Completion or Chat Completion, click on Save.&#x20;

The Card will look like the picture below in the Gallabox bot- builder.

<figure><img src="https://3137140735-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZcl3T6ePz95GpzjAeOLW%2Fuploads%2FYzNMbkUYXhyt1RVS7lsy%2Fopen_AI.png?alt=media&#x26;token=b2c7f5df-cb1c-460c-8298-cde555de9159" alt=""><figcaption></figcaption></figure>

In the above picture, the highlighted part has Green and Red Circle. They depict the <mark style="color:green;">success</mark> and <mark style="color:red;">failure</mark> conditions.&#x20;

Maximize the potential of your Open AI connector by carefully configuring actions - Chat Completion. Tailor the context, user prompts, model selection, and temperature settings to create an enriched conversational flow. With success and failure conditions visually depicted in the Gallabox bot-builder, you're set to unlock the power of AI in your chat-flow.
