Author's note: Because of this project, my free API quota has been used up, so I am now using
ChatGPT Plus
.If I want to update myself in the future, I may have to wait until I switch to the ChatGPT API one day...
The latest version is now thanks to the PR provided by netizen @willismax: #17
But also because I don’t have the quota for the ChatGPT API... So I can’t test it and just merge it directly.
If you can’t move it, please help me send an Issue/PR. Thank you everyone.
本篇教學無經驗的新手也可學習,無須寫任何程式。
It can be completed in 15 to 20 minutes if you have no experience. An experienced person can get it done in as little as 5 minutes.
不需寫code
, just go to the web page to set some content, and novices can create their own ChatGPT-Linebot in 15 minutes免費
! ! ! The free quota is enough for general use and is a good choice after Heroku is no longer free.
Note: ChatGPT and gpt are models for the same task, and currently only GPT-3 can be used through the API (the method used by this program)
Instead of GPT-3.5 used by ChatGPTIt has been changed to GPT-4, which is the same as the latest ChatGPT, but is implemented using the OpenAI API.
There are four main places to go: (這部份不看也沒關係,以下照著做就可以了!
)
Go to the github repo of my project
Click the button below to fork a file to your account. We will use it later.
可以的話,旁邊的Star 也幫我按一下,是對創作者最大的鼓勵!
You can go directly here, scroll down, find this button, and generate an API KEY
Please be sure to copy it. We name this KEY
OPENAI_API_KEY
Those familiar with this area should move very quickly and can be skipped.
The following instructions are for novices with no experience at all
Let's first go to the line developer homepage to register. After registration, click on Messaging API.
The first time you use it, you need to create a new provider and channel. A provider can have many channels,而一個channel 對應的就是一個chatbot
." Here, just fill in the name and facts you want.
In the Basic Settings tab, scroll down to find the channel secret
Please be sure to copy it. We name this KEY
LINE_CHANNEL_SECRET
Next, let's go to the top and select the Messaging API tab. Let's first turn off some things that may be noisy (preset automatic replies and the like).
這邊可以順便掃一下QR code 或透過line ID ,加機器人的line 好友!
My own settings are as follows:
自動回復訊息必關!!!
", that is line's automatic reply, not what we want.Finally, at the bottom of the Messaging API page, find the channel access token, click Issue on the right, and write it down.
Please be sure to copy it. We name this KEY
LINE_CHANNEL_ACCESS_TOKEN
Please do not share this key with others, others may use it to do bad things! ! !
然後這邊網頁先不要關,等等還會用到!!!!
Go to the vercel homepage and add new project
Import Git Repository, select the project you just forked to import
Select "Environment Variables", set the OPENAI_API_KEY, LINE_CHANNEL_SECRET, and LINE_CHANNEL_ACCESS_TOKEN we just recorded to environment variables, press Deploy and wait for a while to complete!
Go to the vercel page where the deployment has been completed. You can get the URL we want to use in the red box.
把這個網址複製下來,等等要用
We can also click on this URL, and the Hello, World! we pre-written in the program should appear (it should be a web page with only Hello, World!). We can use this to ensure that the program has been deployed normally.
Go back to the Messaging API page of line developer, fill in the URL just in step 4-3., and add "/webhook" after it. For example, you can use Verify in the picture below to see if there are any problems. Usually it should say "Success" "
記得開啟下面的使用Use webhook
"This was originally used by me for debugging, because sometimes it would be noisy to reply to some weird things. It unexpectedly received good reviews, so this function was retained.
但一段時間會自動再起動
). After shutting up, it will not respond to any dialogue. Type "speak" to start the conversation again. Referring to the method from memochou1993/gpt-ai-assistant, the following parameters can also be controlled by setting the environment variables of vercel.
Environment variable name | default value | illustrate |
---|---|---|
OPENAI_MODEL | text-davinci-003 | Please refer to OpenAI’s description of the model |
OPENAI_TEMPERATURE | 0 | Please refer to OpenAI’s description of temperature |
OPENAI_FREQUENCY_PENALTY | 0 | Please refer to OpenAI’s description of frequency_penalty |
OPENAI_PRESENCE_PENALTY | 0.6 | Please refer to OpenAI’s description of presence_penalty |
OPENAI_MAX_TOKENS | 240 | Please refer to OpenAI’s description of max_tokens |
MSG_LIST_LIMIT | 20 | The prompt parameter refers back to the number of sentences |
INIT_LANGUAGE | zh | Determine the initial language, which can be set to "zh" or "en" |
At present, the basic functions are already available, but I am too busy and may not have time to update QQ all the time.
還有很多可以優化的地方,歡迎提供PR!
The current algorithm is to "
紀錄使用者與AI 的前20句對話
" and try to deduce what the next sentence should be. To achieve the effect of continuing the topic.