# OPENAI & PRIMECHAT

OpenAI is a versatile AI platform, comparable to Dialogflow, that allows users to engage through AI-driven interactions. It has capabilities that range from responding to user inquiries to generating images, making it a robust tool for an array of tasks.

When integrated with PrimeChat, OpenAI's ChatGPT can offer businesses substantial advantages in engaging with their customers across a multitude of channels. PrimeChat supports a wide array of channels, including Messenger, Instagram, WhatsApp, Google Business Messenger, Voice, SMS, Viber, Line, VK, web chat, WeChat, and others. \
\
By connecting with ChatGPT, businesses can provide AI-powered conversational capabilities that can comprehend and address customer inquiries in a way that closely resembles human interaction. This enhancement not only improves the customer experience but also drives greater engagement.

The sophisticated natural language understanding and generation abilities of ChatGPT allow our chatbot to grasp the context of conversations and deliver tailored responses that are directly relevant to customers' questions. This personalization, when paired with PrimeChat's multi-channel support, means businesses can consistently engage with customers on their preferred platforms, significantly improving the overall experience.

The integration leads to heightened customer satisfaction, more dynamic engagement, and a more efficient customer support process—all of which contribute to business growth and success.

PrimeChat provides a seamless integration with OpenAI, enabling users to effortlessly establish complex workflows with just a click. Let's take a look at how to set up a connection between OpenAI and PrimeChat.

### **Learn how to use ChatGPT with PrimeChat to create a unique customer experience**

[Connecting your OpenAI Account](#bridging-connection-with-openai-account)

[OpenAI Native Actions](#openai-native-actions)

[Create Text Completion](#create-text-completion)

* 3.1 Input:
* 3.2 Response:
* 3.3 Map the response to a custom field
* 3.4 Sample Response Data
* 3.5 Best Practices:

[Image Generation](#image-generation)

* 4.1 Input:
* 4.2 Response:
* 4.3 Sample Response Data
* 4.4 Best Practices:

[Speech to Text](#speech-to-text)

* 5.1 Input:
* 5.2 Response:
* 5.3 Sample Response Data
* 5.4 Best Practices:

[Translate Audio to English](#translate-audio-to-english)

* 6.1 Input:
* 6.2 Response:
* 6.3 Sample Response Data
* 6.4 Best Practices:

### Connecting With Your OpenAI Account <a href="#bridging-connection-with-openai-account" id="bridging-connection-with-openai-account"></a>

1\. Visit [https://platform.openai.com](https://platform.openai.com/)

2\. Login using your credentials.

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2FnI3RWEc0BODtN6GIqsdT%2FPrimeChat%20and%20OpenAI%20ChatGPT1.png?alt=media&#x26;token=5504dd89-9f7a-474b-a36e-e6936bd130fb" alt=""><figcaption></figcaption></figure>

3\. Click on the top-right corner of the “Personal” tab.

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2F4zTUtkHsZJxRqh0nzU5N%2FPrimeChat%20and%20OpenAI%20ChatGPT2.png?alt=media&#x26;token=0ceb3d11-9899-4cf8-a1bf-611808b7dc50" alt=""><figcaption></figcaption></figure>

4\. From here, you can generate an API key.

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2FSLcjPanh4oxwNdxrwslb%2FPrimeChat%20and%20OpenAI%20ChatGPT3.png?alt=media&#x26;token=9bebda9a-412b-4d93-bd3f-55e02d01608e" alt=""><figcaption></figcaption></figure>

You will only be able to see your API key once, so you can save the copy to a safe place.

5\. Paste your API key inside PrimeChat and click “Save” to establish the connection.

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2F1P6qiJqxvv0axdoOJrnw%2FPrimeChat%20and%20OpenAI%20ChatGPT4.png?alt=media&#x26;token=b6a96287-7a1e-4750-a502-1016549aed86" alt=""><figcaption></figcaption></figure>

Your account has successfully been connected with PrimeChat.

### OpenAI Native Actions <a href="#openai-native-actions" id="openai-native-actions"></a>

PrimeChat gives a lot of actions with OpenAI, which users can use for their needs.

We will now discuss them in detail one by one.

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2FuGkIvOeuVCQ0YFEYZarp%2FPrimeChat%20and%20OpenAI%20ChatGPT5.png?alt=media&#x26;token=6fa991ea-d0cc-4e72-b91a-493fa208a44e" alt=""><figcaption></figcaption></figure>

### **Create Text Completion** <a href="#create-text-completion" id="create-text-completion"></a>

Text completion offers the functionality of sending prompts to OpenAI in textual form and based on the prompt receiving an answer.

#### **Input:** <a href="#input" id="input"></a>

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2Fi4Me5vE3gqjhJNTN14ML%2FPrimeChat%20and%20OpenAI%20ChatGPT6.png?alt=media&#x26;token=dd804cf7-6145-4c32-8aa5-a05ee65f0fe2" alt=""><figcaption></figcaption></figure>

Prompt: This is your main input for which you want the AI to give you an answer or output of. This can be a question, an instruction, etc.

Model: The model you want to use inside OpenAI for the task. By default, text-DaVinci-003 has been selected.

Max Tokens: Each task inside OpenAI consumes tokens. These tokens can be replenished using credit. This field puts a limit on the maximum number of tokens you want to use for a particular task.

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2F7sbk7hA1q5DJv1OjVrhH%2FPrimeChat%20and%20OpenAI%20ChatGPT7.png?alt=media&#x26;token=05160888-de3d-4ee1-9262-c5d487527ef1" alt=""><figcaption></figcaption></figure>

Temperature: This acts as an accuracy gauge where higher values give more random answers and lower values give more deterministic and focused answers. It defaults to 1

Presence Penalty: This value makes OpenAI use unique phrases and texts when completing a task. The higher the value, the less repetitive the words. It defaults to 0.

Number of Completions: The number of times you want the AI to generate a response based on your prompt. The higher value will result in more responses. It defaults to 1 to avoid the consumption of tokens.

Best of Completions: This returns the best possible response(s) for your prompt. It defaults to 1. This works with the Number of Completion field to choose the best possible answer from a group of responses.

#### **Response:** <a href="#response" id="response"></a>

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2FwureYnySqPhWWCYJo4XJ%2FPrimeChat%20and%20OpenAI%20ChatGPT8.png?alt=media&#x26;token=a0c2ff87-9138-4e15-9672-78c78756109a" alt=""><figcaption></figcaption></figure>

#### Map the response to a custom field <a href="#map-the-response-to-custom-field" id="map-the-response-to-custom-field"></a>

You can select the text under the choices, and then you can see the JSON Path selected, and then you can save the response into your own user custom field and then use this response in your flow builder.

#### **Sample Response Data** <a href="#sample-response-data" id="sample-response-data"></a>

`{ "id": "cmpl-6zchlUy0OiAjX91LHOPBcZjuXaDgE", "object": "text_completion", "created": 1680144809, "model": "text-davinci-003", "choices": [ { "text": " 1. Understand Your Target Audience - Before you begin any marketing campaign, it’s important to have a clear understanding of who you’re targeting with your message. Researching and understanding your target audience will help you create campaigns specifically tailored to their interests. 2. Leverage Social Media - Social media has become one of the most effective ways to communicate with your target audience. Utilizing social media channels such as Facebook, Twitter, and Instagram can help you build", "index": 0, "logprobs": null, "finish_reason": "length" } ], "usage": { "prompt_tokens": 4, "completion_tokens": 100, "total_tokens": 104 } }`

**Id**: The id of the text completion. A unique value.

**Object**: The action/task you gave to OpenAI. In our case “text\_completion”

**Created**: A date-time field that tells the instance of the creation of the response. It is in Unix timestamp format.

**Finish reason**: The reason for the stoppage of the said task.

**Prompt tokens**: The number of tokens used to complete the task.

#### **Best Practices:** <a href="#best-practices" id="best-practices"></a>

Sometimes the completed response you get back seems to be cut off. This is due to the lack of the number of tokens required for the completion of the task. Simply adjusting the value of Max tokens inside the input fields will fix this issue.

It is also advised to adjust values like temperature, the number of completions, best of completions, etc to your use case by means of split testing. Every use case is unique and you should want the best possible utilisation of the resources available.

### **Image Generation** <a href="#image-generation" id="image-generation"></a>

Image Generation is used to generate images based on the user-input prompts. This feature will generate the best possible image that matches your given prompt.

#### **Input:** <a href="#input-.1" id="input-.1"></a>

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2FdU89OVakERoVC7yPks4P%2FPrimeChat%20and%20OpenAI%20ChatGPT40.png?alt=media&#x26;token=4a0d6bf3-86f3-4d2c-80cc-dbd91be5d125" alt=""><figcaption></figcaption></figure>

**Prompt**: This is your main input for which you want the AI to generate an image for you. This can be a question, an instruction, etc.

**Number of Images**: The number of images you want the AI to generate for you. It defaults to 1

**Size**: The dimensions you want the image to be. OpenAI supports three sizes which are:&#x20;

&#x20;          512x512&#x20;

&#x20;          256x256

&#x20;          1024x1024

#### **Response:** <a href="#response-.1" id="response-.1"></a>

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2FjaHMzwyOTUvu2IVO23QX%2Fimage%20creation%20response.png?alt=media&#x26;token=ec28cbc5-7fe7-4f1a-a667-ca74f80ea0f3" alt=""><figcaption></figcaption></figure>

#### **Sample Response Data** <a href="#sample-response-data.1" id="sample-response-data.1"></a>

`{`

`"created": 1680145479,`&#x20;

`"data": [`

&#x20;`{`&#x20;

`"url": "https://oaidalleapiprodscus.blob.core.windows.net/private/org-2FEbJIRL7GXfKmGw2BT9wh9b/user-nk6UUN7L9nFqzGEw67uTMonD/img-FhZpxMrCbiDBR4O62e7pPF08.png?st=2023-03-30T02%3A04%3A39Z&se=2023-03-30T04%3A04%3A39Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-03-29T17%3A40%3A49Z&ske=2023-03-30T17%3A40%3A49Z&sks=b&skv=2021-08-06&sig=4DF0dw/peG7FSVMUml4ShuQP98T0xECW1gE%2BeutdRAw%3D"`&#x20;

`}`

&#x20;`]`

&#x20;`}`

**Created**: A date-time field that tells the instance of the creation of the response. It is in Unix timestamp format.

**Url**: The public URL for your image(s).

#### **Best Practices:** <a href="#best-practices-.1" id="best-practices-.1"></a>

Generating Images consumes more computational power, and hence, the replies can be delayed based on the prompts you give.

AI is a developing field and hence the images produced can be quite inaccurate given the complexity of the prompts provided. Hence, finding the correct prompt complexity can sometimes be a challenge.

### **Speech to Text** <a href="#speech-to-text" id="speech-to-text"></a>

Speech-to-text action is used when you want to convert audio input into text. This has variety of use cases, such as implementation in IVRs.

#### **Input:** <a href="#input-.2" id="input-.2"></a>

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2F5iCH7BSUYoPSCC8LZR4S%2Fspeech%20to%20text.png?alt=media&#x26;token=21996fbe-8add-4202-914e-127eaca5d129" alt=""><figcaption></figcaption></figure>

**File Url**: This is the URL for the audio that you want to convert to text. Make sure that the url is a publicly hosted url ending with audio formats such as mp3. mpeg etc

{% hint style="info" %}
Please note the url need to start with https\:// and end with mp3, or mp4, mpeg, mpga, m4a,wav, webm
{% endhint %}

**Language**: The language you want the speech to be converted into. We use ISO-639-1 format which means you need to put languages as ‘en’, ‘es’ etc.

#### **Response:** <a href="#response-.2" id="response-.2"></a>

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2FhJrlx4i2hJNl38ozvefx%2Fsample%20data%20response%202.png?alt=media&#x26;token=ab9f852d-39e3-4280-a4fd-162836ac8f98" alt=""><figcaption></figcaption></figure>

#### **Sample Response Data** <a href="#sample-response-data.2" id="sample-response-data.2"></a>

`{ "text": "Welcome to Rensen. This is a test to see if everything works well. And if the IVR can guide you to your work." }`

Text: The text that is converted from the speech.

#### **Best Practices:** <a href="#best-practices-.2" id="best-practices-.2"></a>

You can convert speech to text quite accurately using this feature. It is considered a best practice to provide the audio in the same language as that of the desired output for more accurate results and latency.

### **Translate Audio to English** <a href="#translate-audio-to-english" id="translate-audio-to-english"></a>

Translate audio to English action is used when you want to convert audio input into text in English language. This has a variety of use cases, such as implementation in IVRs.

#### **Input:** <a href="#input-.3" id="input-.3"></a>

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2F7G5iYXsnnc1m3JVSyROy%2Ftranslate%20audio%20to%20english.png?alt=media&#x26;token=90f92455-84e2-4a43-b657-0bc69b76654d" alt=""><figcaption></figcaption></figure>

**File Url**: This is the URL for the audio that you want to convert to text. Ensure the url is a publicly hosted url ending with audio formats such as mp3. mpeg etc

{% hint style="info" %}
Please note the url need to start with https\:// and end with mp3, or mp4, mpeg, mpga, m4a,wav, webm
{% endhint %}

#### **Response:** <a href="#response-.3" id="response-.3"></a>

<figure><img src="https://1845383182-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0a8LLhirT2ZqXdY3anD6%2Fuploads%2FP8CCs37G4v5iLrMnpXp0%2Fresponse%20translation.png?alt=media&#x26;token=39afaba7-3ad1-4b44-aa8e-fc2fa1b64cf0" alt=""><figcaption></figcaption></figure>

#### **Sample Response Data** <a href="#sample-response-data.3" id="sample-response-data.3"></a>

`{ "text": "Welcome to Rensen. This is a test to see if everything works well. And if the IVR can guide you to your work." }`

Text: The text that is converted from the speech.

#### **Best Practices:** <a href="#best-practices-.3" id="best-practices-.3"></a>

Experimenting with different formats of audio can provide more (or less) accurate results. This is simply due to the audio quality provided, so make sure you split test with different formats to achieve the best possible format for your use case.
