How to Connect ChatGPT From OpenAI to Your Chatbot

Available with a paid pricing plan, as well as during the 7-day free trial

With SendPulse, you can connect the GPT model from OpenAI to your chatbot to provide your users with even more proficient automated replies and help them solve additional tasks.

Let’s learn how to create an OpenAI account and connect it to your chatbot and find out what AI models you can use and how to train your bot to solve your business tasks.

Getting Started

GPT (Generative Pre-trained Transformer) is an AI model developed by the OpenAI company. It is a large-scale neural network you can use to generate text and code.

The primary models can perform different tasks: analyze text materials of various difficulty levels, provide answers to questions, optimize text for SEO and SMM tasks, categorize text in tables, help with brainstorming, edit and translate text, work with code and mathematical tasks, and support conversations on any or specific topics.

To set up GPT and perform your business tasks using a chatbot, you need to choose a model and prompts — for example, you can add reply sentiments, limit your list of questions or topics, and add additional information about your business or an example of what you want to receive in response.

Create an Account

Go to OpenAI, and create an account. Click Sign up, enter your email address, and click Continue, or continue with your Google or Microsoft account.

If you entered your email address, enter a password in the next window. You will receive a confirmation email in your inbox. Click Verify in the email, and enter your name and the name of your organization.

Enter your phone number, and a confirmation code will be sent to it via SMS. Enter the code, and log into your account.

Before choosing a phone number to use, check OpenAI’s list of supported countries and territories.

Copy Your API Key

In the right-upper corner, click your avatar, and select “Manage account.”

Go to the “API Keys” tab, click Create new secret Key, and copy your key.

You need to save a key on your device because you cannot copy the same key on this page a second time. If you lose the key, you will need to generate a new one.

Set Up the Integration

Enter Your API Key

Choose a bot, and go to “Bot settings” > “Integrations.” Next to “OpenAI,” click Enable.

Select a connection method.

Use the token from the account settings If you use one OpenAI account for different SendPulse services, including the chatbot builder, you can add your token to general account settings.

To add a token, go to "Account settings" > the "API" tab.

In the "Integrations > OpenAI & ChatGPT" section, click Connect. Enter your key, and click Save.

Once you add a key, you can select the "Use the token from the account settings" option, and connect OpenAI to your chatbot.

Use a separate token for this bot If you need to use a dedicated OpenAI account for your current chatbot, select this option, and in the next field, enter your key.

Choose a Model

Select an AI model to generate bot replies.

ChatGPT (gpt-3.5-turbo) A model trained on human conversation data. Able to generate human-like responses with a more natural tone than other models and personalize its replies based on the topic and previous user messages.
ChatGPT (gpt-3.5-turbo-16k) A model with the same capabilities as the gpt-3.5-turbo model but with 4 times the context length.
ChatGPT (gpt-3.5-turbo-16k-instruct)
Custom fine-tuned model

Basic model, which you can train using your data and fine-tuning tools provided by OpenAI and create your original model.

To connect a custom model to your SendPulse chatbot, specify a unique model name in the OpenAI library.

Custom fine-tuned model (Instruct)
GPT-4

The latest and most advanced model of the ChatGPT family, designed to facilitate multi-turn conversations. The model is also useful for single-turn tasks without conversations.

Available only to users who received access to the model from OpenAI.

You can see how to use these models in “Examples” and “OpenAI Cookbook,” and experiment with models in “Playground.”

Add a Prompt to the Bot

GPT Models can perform various tasks ranging from complex text analysis to generating replies on various topics. You need to add prompts to limit certain topics you don’t want your bot to discuss, tailor your bot to a specific character or person, or add text sentiment or information about your company.

When creating a prompt, keep the following recommendations in mind:

  1. Add as much context as possible in each case. List all the bot interaction instructions: specify which users will contact your bot and when, which details should be included in bot replies, and which topics should be avoided.
    Give your model the task of generating several results so that you can compare and specify the one that suits your needs best.
  2. Show what you want to receive using examples. For example, if you want your model to sort a list of items alphabetically or classify paragraphs by sentiment, list your example queries, expected result format, or the effect you want to achieve. If you need the bot to reply in a certain way, provide examples of questions and answers.
  3. Provide high-quality and accurate data. Check your examples — your model is usually smart enough to identify basic spelling mistakes, but it also might assume that this is intentional and mistakes can affect the reply. If you want your model to reply in a certain language, specify it. Also, try to use words instead of figures. Remember that AI takes your prompts literally.
  4. Personify the model. To help your model reply how a certain person or character would, describe what they do, what characteristics they possess, their tone of voice, lexicon, and other aspects of your virtual assistant's persona.
  5. Test the result, and update your prompt. After setting up the prompts, make sure to test the result, review chats with users and, if necessary, adjust the bot's instructions by adding or removing details. Train the model until you get the results you want.

Read more: the “Prompt design” and “Prompt Optimization” sections. Note that OpenAI has moderation rules — read more about them in the “Usage policies” and “Moderation” sections.

You can test models with different bot prompts on the Prompt Compare page.

If you need inspiration for context prompts, take a look at the following examples: 160 ChatGPT Prompts You Can't Miss To Try Out In 2023.You can also use and add your own prompts in the GitHub repository: Awesome ChatGPT Prompts.

In the “Bot instructions” field, provide your free-form prompts, following the recommendations.

Note: models have different context length limits, which refers to the amount of tokens you can use. Learn more in the model overview table.

AI analyzes text in all languages and can answer in a language you specify, but it interacts better in English. If you do not specify a language, the bot will answer in English by default.

If you have any questions about how to create bot prompts or possible scenarios, you can check existing discussions or start a new one in the OpenAI community.

Add a Token Number 

A token is a part of a word used for natural language processing. For English text, 1 token equals approximately 4 characters or 0,75 words. For other languages and more accurate calculations, you can use the OpenAI calculator.

In the “Maximum number of tokens in response” field, specify a number from the last column.

Model The max number of characters in the "Instructions for the bot" field* The max number of tokens in a reply to a subscriber*
ChatGPT (gpt-3.5-turbo) up to 4096 up to 2048
ChatGPT (gpt-3.5-turbo-16k) up to 16348 up to 8174
ChatGPT (gpt-3.5-turbo-16k-instruct)
Custom fine-tuned model up to 2048 up to 1024
Custom fine-tuned model (Instruct)
GPT-4 up to 8192 up to 4096

*For each request, the tokens are counted in the following places: the “Bot Promt” field; last messages in a chat with a bot; current question that a user asks a bot; current answer that a bot provides a user with.

If you use the max amount of tokens in the "Bot instructions" field, your total token data may exceed the OpenAI limit. As a result, your request will end with an error, and your subscriber won't receive a reply.

In such cases, you can check the error appeared as a notification in the upper-right corner in your SendPulse account: OpenAI: This model's maximum context length is 4097 tokens, however you requested 4131 tokens (2083 in your prompt; 2048 for the completion). Please reduce your prompt; or completion length. To resolve it, lower the amount of tokens in the "Bot instructions" field or the amount of tokens in a reply.

During the first registration, OpenAI gives $18 dollars for 3 months. This money will be withdrawn when you use tokens. 

Note: Token fees vary depending on the model used. For example, gpt-3.5-turbo-16k model costs twice as much as the gpt-3.5-turbo model, because it uses more context. Read more: What are tokens and how to count them and about OpenAI’s pricing plans in the Pricing section.

To see how many tokens you have left, log in to your OpenAI account, and go to the “Usage” tab.

To check your token usage history, scroll the page down to the “Daily usage breakdown (UTC)” section. You can see the whole history or filter it by specific date or team member.

Set Up the Temperature

Choose a temperature indicator value from 0 to 2.

Temperature is a parameter that affects the response abstractness. For example, if you ask a question, the output will vary according to the selected temperature: abstract or more precise. A higher temperature ​​closer to 2, for example, 1.3, will make the answers more random. Lower temperature ​​closer to 0, for example, 0.2, will make them more comprehensive while retaining the same meaning.

Click Save, and you can test your bot.

Limit the number of subscriber requests

To avoid subscribers from submitting an excessive number of paid requests to your chatbot, you can set limits.

In the Limiting AI bot triggering to one contact field, specify an amount of requests and a number of days, hours, or minutes within which users can send them.

By default, a subscriber can send 100 requests daily.

Usage Features

When you integrate with OpenAI, your "Standard reply" flow will be disabled for your chatbot. Therefore, you need to make sure users know that your bot can reply to them. For example, add your bot communication guidelines to a welcome or trigger flow that you add to your menu.

When using OpenAI with chatbots, note that AI uses an internal information library — it processes users’ requests and gives results directly in the chat with a client.

AI does not have a long memory. When processing a request, only the last couple of user messages are taken into account. We recommend you monitor your bot’s conversations with customers to correct its prompts.

AI does not integrate with additional applications and does not process client data in your bot's audience. For these features, add a menu, or create commands to run flows where you can add the "API request," "User input," and "Action" elements.

You can add an OpenAI bot to your Telegram group. You will be able to trigger this bot using @mentions, /commands, keywords, and OpenAI requests if this integration is enabled.

Make sure your bot has admin rights in your Telegram group, including permissions to assign other admins.

Read more: How to create posts in a Telegram channel or group via your SendPulse chatbot.

Use Cases

Let's see various examples of how you can use a chatbot with an OpenAI integration. You can see more examples on the Examples page.

Business Q&A

If you have a bot for a feature-loaded service, you can train it to independently manage conversations with clients and generate answers to questions about your products and working hours.

For this example, the ChatGPT model used 2048 tokens. We added short info about the company, its business, and contacts. The bot can develop a dialog based on the data received.

Prompt example: You are a bot assistant to the "Paper and pencil" company. Our company sells stationery and office supplies. A lot of items are in stock, but it is better to clarify by phone: (856) 267-5442.

Store address: 4472 Central Avenue, Newark.
Working hours: 9:00 AM – 7 PM.

Use the following text to answer questions about product availability and price: "Let us check and get back to you."
Use the following text to answer questions not related to office supplies: "Sorry, I have no information about it."

For the second example, we collected a database of frequently asked questions and answers to limit the scope of bot answers and provide accurate information about our services.

For this example, the model used 700 tokens. In the “Bot instructions” field, we added basic questions and answers to them. Users don’t have to ask these questions verbatim, and the AI will know enough about your business to be able to answer naturally.

Prompt example: The bot analyzes and provides information only from the given Q&A list.

Question: What is a bio link page?
Answer: A bio link page is a one-page site that can help you promote your brand on social media. Create a SendPulse account and build a bio link page using the landing page builder. Read more: https://sendpulse.com/en/features/landing-page-builder

Question: What elements can be added to my bio link page?
Answer: Text, Cover, Gallery, Button, Subscription form, Payments. Read more: https://sendpulse.com/knowledge-base/landing-page/builder/create-landing-page#adding-elements

Encyclopedia Q&A

Let’s say that your bot is of entertaining and informational nature. It does not need to answer specific questions, but simply provide facts on, for example, history or any other topic from the Internet.

For example, the model used 700 tokens. We only specified the language in which we want the bot to answer and the bot’s name. If you don’t choose specific topics, the bot will provide answers to questions about any topic without limits.

Prompt example: The bot's name is Marl, and it can provide answers to encyclopedic questions in English. The bot answers using 1 word.

Solving Life Issues

If you have a helper bot, users can describe their life situation and ask for advice on what to do.

For example, the model used 700 tokens. In the “Bot instructions” field, we added specific prompts only for vital questions. If a certain situation happens, the bot will tell users who to contact.

Prompt example: The bot helps people cope with critical situations. It empathizes with people and replies with care. In especially critical cases, such as death, suicide, acute poisoning, etc., please call +380501010200.

Solving Math Tasks

If you have a student helper bot, users can add their task and indicate what needs to be solved.

For example, the model used 700 tokens. In the “Bot instructions” field, we added prompts that do not allow the bot to answer non-math-related questions.

Prompt example: The bot provides answers only to math-related questions. In other cases, the bot reminds users that it only helps with math.

Text Optimization

If you have an SMM or SEO tool, your bot can help users choose keywords or proofread and optimize the entered text for SEO.

For example, the model used 1024 tokens. In the “Bot instructions” field, we added prompts that allow the bot optimize text for SEO and search for keywords. If users do not run a command, the bot will remind them how to work with it.

Prompt example: This bot is an SEO expert. It knows how to find keywords and suggest related topics. The bot answers in English.

Code Decryption

If you teach programming, your bot can help users decode parts of code or errors and tell you how a particular element or function works. Also, users can ask your bot to generate code using natural language.

For example, the model used 700 tokens. In the “Bot instructions” field, we added prompts that allow the bot to decrypt and explain code or parts of code. We also added a tone so that the bot responds in a sarcastic manner using simple words.

Prompt example: The bot explains Python code in a way that even a beginner will understand. It can also describe functions and create simple applications. If users ask about something non-code-related, the bot reminds them that it only helps with coding.

Text Generation

If you have a creative marketing agency, your bot can offer to generate text for an advertising campaign or come up with a brand name, and so on.

For example, the model used 1024 tokens. In the “Bot instructions” field, we added the bot’s name and wrote that it works at a marketing agency and helps clients create advertising slogans and create plans.

Prompt example: The bot works for a marketing agency and helps clients write ad slogans and feature descriptions.

    Rate this article about "How to Connect ChatGPT From OpenAI to Your Chatbot"

    User Rating: 4 / 5

    Previous

    How to Add an Image Generator to Your Chatbot Using OpenAI Tools

    Next

    How to Transfer Data from Google Sheets to Chatbots

    Popular in Our Blog

    Try creating a chatbot for Facebook Messenger for free