how-to-connect-api-from-chat-gpt-4o-with-chatbot-english-thumbnail
how-to-connect-api-from-chat-gpt-4o-with-chatbot-english-thumbnail
how-to-connect-api-from-chat-gpt-4o-with-chatbot-english-thumbnail
AI Chatbot

Saran Sunsang (Moss)

May 16, 2024

Use 'ChatGPT-4o' on LINE for personal use, as simple as copy and paste.

Use 'ChatGPT-4o' on LINE for personal use, as simple as copy and paste.


The year 2024 is shaping up to be the AI, as major companies are rapidly launching the latest flagship models in their Large Language Models (LLMs). At the end of 2023, Google launched Gemini AI. Just a few months later, Anthropic followed with the release of Claude AI. Recently,  OpenAI has introduced a new model equipped with even more spectacular technology, named 'ChatGPT-4o.'

ChatGPT-4o, pronounced 'Chat-G-P-T-four-o,' where 'o' stands for 'omni,' a Latin word meaning 'all-knowing' or 'wise.' The data for this model is updated as of October 2023. Sam Altman, CEO and co-founder of OpenAI, launched this model with a demonstration video that left everyone astounded. One might confuse this latest model withJ.A.R.V.I.S, the AI assistant from the Iron Man comic and movie, and these recent advancements in the industry suggest that that we might not be far from reaching the same level of sophistication in the near future.

How to Use the ChatGPT-4o API in a Chatbot

     Here we'll show you how to use ChatGPT-4o via LINE. We’ll, start by creating a LINE OA account and then demonstrate the results obtained by connecting through the API without needing to write any code. However, if you already own a personal chatbot you can skip to step 3.

Step 1: Creating a LINE OA 

For those new to the chatbot scene, you can create your own LINE official account by following this official video tutorial on account creation.

Step 2: Creating a Chatbot and Connecting it to LINE OA

The platform we will use to create the chatbot is botnoi.ai. You can follow this video for guidance:

or download a free handbook here

Step 3: Creating a ChatGPT-4o API Key

Go to the OpenAI API service page using this link. Then, log in by clicking the 'Log in' button and select your user account. Note that there is a fee to use  the GPT-4o API, costing $5 per 1,000,000 tokens., However,  this is still more affordable and cost-effective compared to the Chat GPT-4pro, which costs $10 per 1,000,000 tokens.

If you need to add credit to your OpenAI account, go to Settings > Billing, then click the green button to add payment method.

how-to-billing-a-chat-gpt-4o

Next, to create an API key for use, go to API Keys > Create new secret key > name your API > Create secret key. Once you’ve completed this completed, your key is ready to use. Don’t forget to copy it for safekeeping.

how-to-create-a-chat-gpt-4o-api-key

Step 4: Adding the API to botnoi.ai

Once you have connected LINE OA with Botnoi, you can easily create an API as follows: Go to API > Add > name your API > choose the POST method > paste the URL and Body > Save.

curl -v -X POST https://api.openai.com/v1/chat/completions \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {API KEY}' \
-d '{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": "{write down a short prompt for defining personality and response style. For example,Cheerful and polite young woman responds like a teenager. Not exceeding 100 characters.}"
    },
    {
      "role": "user",
      "content": "<<keyword>>"
    }
  ]
}'

Step 5: Using the API 

Go to Default Fallback to add the API you just created. The reason it needs to be in Default Fallback is so that if the chatbot can't answer a user's question, we have the Chat GPT-4o as an assistant that will respond to everything on our behalf. Navigate to Bot Response>Existing Object>API>find the API named in Step 4>click Add.

Once the Object is added, proceed to invoke the API. The syntax for calling an API in the chatbot creation site botnoi.ai is <<API_NAME.parameter>>. However, here we write it as <<API_chatgpt4o.choices.0.message.content>>. If you named your API differently, make sure to change the API name and then save. Try chatting with the bot to see if it works properly.

Tips: Try adding new features from LINE as well : How to Display a Loading Animation in LINE Chatbot within 5 Minutes via Botnoi.ai

preview-of-the-result-connect-chat-gpt-4o-with-botnoi-chatbot

Tutorial video for connecting LINE OA with Chat GPT-4o.

กลับ

Collaborate to Innovate

Together, We Build the Future.

Collaborate to Innovate

Together, We Build the Future.