A Telegram chatbot built with Python, implementing chatGPT by applying OpenAI API.
Install or upgrade python-telegram-bot library via
$ pip3 install python-telegram-bot --upgrade
Get your own OpenAI API key from OpenAI API.
Create a telegram bot and get your bot token.
Create .env
file.
$ touch .env
Inside .env
, set the following variables with the api key and bot token from above.
BOT_TOKEN=your_own_bot_token
OPENAI_API_KEY=your_own_api_key
Start running the bot with the command below.
python3 main.py
Note: The default model used here is chat-3.5-turbo
which is the chat completion model. If you wish to switch to text completion model (text-davinci
), you can uncomment the code under # completion model (text-davinci)
and comment out the code under # chat completion (chat-3.5-turbo)
.