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.

Enter your key.

Choose a Model

Choose what AI model to use to generate bot replies.

Model Description Recommended use cases

The most comprehensive yet expensive and slower model, as it works with a large amount of data. It can perform the same tasks as other models but requires fewer prompts in the “Bot instructions” field.

Use it to perform tasks where it needs to analyze the context deeper and generate more complex text or code. Also, you can use it to solve logic problems involving cause and effect.

Analyzing complex intent and cause-and-effect problems, summarization, and explaining and generating code

The model can analyze text, answer direct questions, and provide key points.

Use it for Q&A in chatbots. For example, in the “Instruction for bot” field, you can enter your questions and answers that the bot will use.

Translation, complex classification, text sentiment analysis, and summarization

The model is good at picking up obvious text patterns and using them as references to generate new text.

Use it to classify information and assign categories. For creative applications, Babbage is able to understand structure just enough to be able to create simple plots and titles.

Moderate classification, and semantic search classification
Ada The fastest and cheapest model. Use it when you need to parse text faster without too much nuance. Parsing text, simple classification, address correction, keywords
ChatGPT A gpt-3.5-turbo 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. Generating replies for messaging apps and virtual assistants and implementing QA systems. Giving the software a natural language interface. Providing tutoring in various subjects. Simulating characters for video games and much more.
ChatGPT (gpt-3.5-turbo-16k) Same capabilities as the gpt-3.5-turbo model but with 4 times the context length.
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 Generating text, emails, and code, translation, modeling characters for video games, answering questions about a set of documents, working with user interface, and tutoring in various subjects.
Custom Fine-tuned model* You can train one of the basic models using your data and fine-tuning tools provided by OpenAI and create your original model. Generating text and code, information retrieval, syntactic analysis, tone analysis, and other machine learning tasks — ordinary and tailored to your business requirements.

* Only davinci, curie, ada, and babbage models are available for fine-tuning. To connect a custom model to your SendPulse chatbot, specify a unique model name in the OpenAI library. The custom model is only available with your API key to the corresponding account.

In this field, you can also specify one of the OpenAI system models that aren’t in the standard list. The full list is available in the OpenAI documentation.

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*
Сurie / Babbage /Ada / Fine-tuned up to 2048 up to 1024
Davinci / ChatGPT up to 4096 up to 2048
ChatGPT (gpt-3.5-turbo-16k) up to 16348 up to 8174
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. Token fees vary depending on the model used. For example, the Davinci model in a live environment costs $0.1200 per a thousand tokens, while the Ada model in a test environment costs $0.0004.

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.

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.

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 Davinci 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:

Question: What elements can be added to my bio link page?
Answer: Text, Cover, Gallery, Button, Subscription form, Payments. Read more:

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 Davinci 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 Davinci 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 Davinci 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 Ada 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 Davinci 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 Davinci 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

    Popular in Our Blog

    Try creating a chatbot for Facebook Messenger for free