Skip to content

AmirMuratov/ChatGptTgBot

Repository files navigation

ChatGPT Telegram Bot

A simple Telegram bot that allows users to communicate with OpenAI's ChatGPT

Getting Started

To start using the bot, you will need to first obtain two API keys: a Telegram API key and an OpenAI API key.

Telegram API Key

To obtain a Telegram API key, you will need to create a telegram bot using @BotFather. You can follow the instructions here to create a bot and obtain an API key.

OpenAI API Key

To obtain an OpenAI API key, you will need to create an account with OpenAI. You can follow the instructions here to create an account and obtain an API key.

Installing

After obtaining both API keys, you will need to install Docker in order to run the bot. You can follow the instructions here to install Docker on your machine.

Once Docker is installed, you can start the chatgpt container with the following command:

docker run --name chatgpt \
        -e TG_APIKEY=<TELEGRAM_API_KEY> \
        -e OPENAI_APIKEY=<OPENAI_API_KEY> \
        amirmuratov/chatgpt-tg-bot:latest

Make sure to replace <TELEGRAM_API_KEY> and <OPENAI_API_KEY> with your actual API keys.

Usage

After starting the container, you can interact with the bot by sending messages to it on Telegram. The bot will respond with messages generated by the GPT model based on the context of the conversation.

You can also use the following commands:

  • /clean - clears the context of the bot, starts new conversation with empty context.
  • /config - prints the current configuration of the bot.

Additionally, there are several environment variables you can use to customize the behavior of the bot:

  • OPENAI_MODEL_NAME - specifies the name of the GPT model to use. You can find a full list of available models here.
  • OPENAI_TEMPERATURE - controls the creativity of the generated responses. Higher temperatures lead to more creative responses, while lower temperatures lead to more safe and predictable responses. You can find more information here.
  • OPENAI_TOP_P - controls the diversity of the generated responses. A high value leads to more diverse responses, while a low value leads to more repetitive responses. You can find more information here.
  • WHITELIST - a comma-separated list of Telegram usernames that are allowed to interact with the bot. If this variable is not set, the bot will be open to all users.
  • CHAT_GPT_PROMPT - a prompt that will be added to the beginning of the conversation history sent to the GPT model.

You can set these environment variables by adding them to the docker run command with the -e flag. For example:

docker run --name chatgpt \
        -e TG_APIKEY=<TELEGRAM_API_KEY> \
        -e OPENAI_APIKEY=<OPENAI_API_KEY> \
        -e OPENAI_MODEL_NAME="gpt-3.5-turbo" \
        -e OPENAI_TEMPERATURE=1 \
        -e OPENAI_TOP_P=1 \
        -e WHITELIST="a0037,some_random_username" \
        amirmuratov/chatgpt-tg-bot:latest

Releases

No releases published

Packages

No packages published

Languages