The project involves step by setp tutorial for implementing an intelligent LINE chatbot that integrates the OpenAI API with LINE developer tools.
Additionally, the functions are deployed on Google Cloud Functions, eliminating the need for self-hosted servers.
-
First, go to line developer and register for a LINE Developer account.
-
Create a provider based on the Messaging API.
-
Now, you can have a conversation with the default bot in the LINE app using the QR code found in the 'Messaging API' option.
-
In the 'Messaging API' option, locate the 'Webhook settings' and enable the 'Use webhook' option.
-
In the 'Messaging API' option, find the Channel access token and remember this token, as it will be used later.
-
Log in or register for an OpenAI account.
-
After logging in, find the 'API Keys' option in the menu in the top left corner.
-
Create a new Secret Key and remember this key. This key will only be displayed once; if you miss it, you can delete it and create another one.
-
Ensure you have enough credits to use this API. If you don't have credits, you can still find the 'Settings' option in the top left corner menu, go to 'Billing', and purchase sufficient credits there.
-
Log in or register for an Google Cloud api account
-
Select the console in the upper right corner.
-
Search for Cloud Functions in the search field.
-
Click on CREATE FUNCTION.
-
Make some basic settings for the function, and remember to check the 'Allow unauthenticated invocations' option.
-
Under the 'Runtime, build connections and security settings', find 'Runtime environment variables', we need to Add two variables:
in the Name1 field, enter API_KEY and in Value1, input the OpenAI Secret Key you copied earlier;
in the Name2 field, enter LINE_ACCESS_TOKEN and in Value2, input the Channel access token you copied earlier.
-
After filling in all the details, click on ADD TRIGGER to create a new function.
-
You will see two files, main.py and requirement.txt. Copy the corresponding code from this repository. Be aware that the model and the API endpoints below may change over time, so please pay attention to the official documentation.
https://api.openai.com/v1/chat/completions
gpt-3.5-turbo-1106
https://api.line.me/v2/bot/message/reply
-
Next, click on the 'deploy' option and copy the URL that is generated.
-
Return to the LINE Developer page, find 'Messaging API' and the 'Webhook settings', paste the URL you just generated into the 'Webhook URL'. This is the final step, and now your LINE bot should be operational.