How to Connect Generative AI (ChatGPT, Gemini, Claude) with Line OA [Update] Claude API
In this article, we will explore how to connect various Generative AI platforms such as ChatGPT and Gemini through their APIs to a Line Official Account.
From this point forward, we will refer to the OpenAI Platform (ChatGPT) API, Gemini API, Claude API (Anthropic Console) and similar others collectively as "GenAI API."
INFO
By the end of this article, you will have a Line chatbot that can respond to users as if they were directly conversing with GenAI API.
Overview
Overview Due to Line OA's inability to directly utilize APIs or communicate with the GenAI platforms, connections to external systems must be established through what is known as a Webhook.
If we do not develop our own Webhook, we must look for an intermediary to perform this function, as illustrated in the diagram below.
The connection between the three systems
In this case, I have chosen to use Botnoi Chatbot as the intermediary for establishing connections. This choice is due to its ease of integration with the Line side and the minimal need for additional coding.
Prepare Line OA
What you need to prepare on the Line side
- 1 Line Official Account
Create and prepare your chatbot in advance. If you're unsure how to do this, check here
- Enable Webhook Connection
Normally, Line bots have automatic reply settings enabled. We need to disable these settings and enable Webhook connections as shown in the image.
- Connect Line to Botnoi Chatbot
Prepare AI Platform API
The next thing to prepare is to sign up for the Platform API of each provider.
This part is not the usual front-end where we chat with AI, but the back-end of the Platform that allows us to use the API to call external systems.
- OpenAI Platform (ChatGPT)
Create an API Key from the OpenAI Platform see the steps.
- Google AI Studio (Gemini Pro)
Create an API Key from Google AI Studio on this page
- Claude by Anthropic
Create an API Key from Anthropic Console see the steps
- Dify.ai
Create an API Key for the desired application see the steps
Connect GenAI API KEY with Botnoi
For this chatbot integration, we'll configure it so that every message sent by a user is forwarded to one of the GenAI APIs backend that we set for every message.
- OpenAI Platform (ChatGPT)
WARNING
Using the OpenAI Platform without adequate usage control can result in high costs.
Connect Chat GPT via chat/completion see the steps here
- Google AI Studio (Gemini Pro)
NOTE
Currently free, but to gain more benefits, it might be necessary to connect with Dify.ai below to create prompts for directional data responses. Otherwise, it will result in broad responses from Gemini.
Take the API information and connect it with Botnoi see the steps here
- Anthropic Platform (Claude AI)
WARNING
Using the Claude API without adequate usage control can result in high costs.
Connect Claude API via chat/completion see the steps here
- Dify.ai
Connecting with Dify.ai for a Bot that does not require input (Text Generation Only) see the steps here
Creating More Specialized Bots
The direct API connections made with Gemini and ChatGPT as is, means we haven't set any configurations. Thus, the interaction would be similar to directly talking to ChatGPT or Gemini within Line OA.
To make our bot more versatile, we might need to connect the API with an Assistant or prepare the bot through tools like Dify.ai, then modify the connection as follows:
How to Add Input
(Text Generation with 1 input)
The example of Dify above is a Code of the day with a prompt that simply returns a quote.
However, in this example, we'll adjust it to accept an additional input from the user. Whatever the user types, the bot will generate a related quote for them.
Then, we modify the botnoi API to include the user's typed input as shown in the code below.
{
"inputs": {
"topic": "<<keyword>>" // The changing part
},
"response_mode": "blocking",
"user": "abc-123"
}
Update this in the Body section of the botnoi API as shown in the example below.
When we chat with the bot using any message, it will generate a related quote for us.
TIP
Line OA can act as a frontend in certain contexts. The owner of the GenAI APP must select the appropriate frontend for their AI's functionality.
Cautions
After this setup, your Line OA will always respond with the Generative AI connected through the Botnoi Chatbot.
If you choose Generative AI that charges based on the number of words in the prompt, like ChatGPT or Dify.ai, which might link to a cost-incurring LLM API,
WARNING
You must take care not to distribute your Line OA to individuals other than your target users. Anyone who becomes a friend with your Line OA will be able to use our Generative API immediately by chatting with the bot.
As for Gemini Pro, which is still free, concerns might be lesser.
Good Luck