Telegram ChatGPT Bot

1. Background

We all love OpenAI, but... But sometimes it's laggy, with daily limits, and is only accessible through an archaic web interface. This open source program is ChatGPT re-created with GPT-3.5 LLM as Telegram Bot.

2. Deployment

  • Get OpenAI api key
    Go to OpenAI account - User - API keys - Create new secret key
    Note: Do keep the key well, for it only appears once. If you lose the key and want to make further configuration, you will have to re-generate a new key.

  • Get Telegram bot token
    Go to Telegram, find user @BotFather.
    Use command /start, click /newbot, follow instructions to finish setups.
    Click API token, save the token

  • Get chatgpt_telegram_bot repo

git clone https://github.com/karfly/chatgpt_telegram_bot.git
cd chatgpt_telegram_bot
nano config/config.example.yml

Fill in the info you got (you can delete the price section if you want) keep the quotation marks

telegram_token: "<your_telegram_token>"
openai_api_key: "<your_openai_api_key>"
use_chatgpt_api: true
allowed_telegram_usernames: []  # if empty, the bot is available to anyone. pass a username string to allow it and/or user ids as integers
new_dialog_timeout: 600  # new dialog starts after timeout (in seconds)
enable_message_streaming: true  # if set, messages will be shown to user word-by-word

# prices
chatgpt_price_per_1000_tokens: 0.002
gpt_price_per_1000_tokens: 0.02
whisper_price_per_1_min: 0.006
  • Make .env and .yml files effective
mv config/config.example.yml config/config.yml
mv config/config.example.env config/config.env

  • Build Docker image
docker-compose --env-file config/config.env up --build
  • Bring up container in the background
(if it’s up) docker-compose down
docker-compose up -d
systemctl enable docker
  • The repo is under frequent update. Feel free to rebuild image if you need the latest feature

3. Bot commands

  • /retry – Regenerate last bot answer
  • /new – Start new dialog
  • /mode – Select chat mode
  • /balance – Show balance
  • /help – Show help
    You can edit/add all kinds of features before building the docker image.

Enjoy!

Important: DO NOT abuse ChatGPT with crawler, public shared account, or intensive requests.


Copyright statement: Unless otherwise stated, all articles on this blog adopt the CC BY-NC-SA 4.0 license agreement. For non-commercial reprints and citations, please indicate the author: Henry, and original article URL. For commercial reprints, please contact the author for authorization.