Create a Typetalk bot using OpenAI's ChatGPT API.
This Typetalk bot operate according to the following specifications.
- Follow the tone and answers according to the pre-defined character settings.
- Summarise the message as a start point of conversation in approximately 30 words and set tag.
- Create conversation flow by passing the part of conversation thread to the ChatGPT API each time you speak.
- The conversaton history pass to ChatGPT API limit latest four messages.
- Because of the API sepcification that the maximum number of token is 4,096 for the conversation history,questions, and answers combined.
- You can handle this bot specfication by changing
max_tokens
parameter of ChatGPT API and pre-defined character settings.
Wait a few seconds to receive a response from the ChatGPT API.
Japanese version is on Qiita.
- Python 3.11.3 (Python 3.9, 3.10 is also OK.)
- bottle 0.12.25
- openai 0.27.6
- ngrok 3.3.0
Create your OpenAI API account and API Key.
Create your Nulab account and singin to the Nulab account from Typetakl.com.
- Create a new topic
- Add a bot and get Typetalki token
- Check both
API Scope
- Not Check
Using Outgoing Webhook
- After clicking on the
Create
button, you will receive a Typetalk Token on the bot detailed view.
- Check both
- Copy the Typetalk token from the bot detailed view, and paste it
TYPETALK_TOPIC_ID
in const.py.
Create your ngrok account and download ngrok binary, crate configuration file following setup document. You can also download ngrok binary for each OS from Install ngrok page.
Add environment variables to your shell dotfile like .zshenv
. You can find the Typetalk topic ID on the bot detailed view page.
export OPENAI_API_KEY="yyyy"
export TYPETALK_TOKEN="xxxx"
export TYPETALK_TOPIC_ID="zzzzzz'
Apply shell configuration.
exec $SHELL
pip3 install --upgrade pip
pip3 install -r requirements.txt
python3 index.py
Server Start
Bottle v0.12.25 server starting up (using WSGIRefServer())...
Listening on http://0.0.0.0:8080/
Hit Ctrl-C to quit.
I reccomend you to open this on the another console window or tab.
ngrok http 8080
Session Status online
Account [YOUR EMAIL_ADDRESS] (Plan: Free)
Version 3.3.0
Region Japan (jp)
Latency 34ms
Web Interface http://127.0.0.1:4040
Forwarding https://xxxx-xxx-xxx-xxx-xxx.ngrok-free.app -> http://localhost:8080