pysergio/chibi

By pysergio

Updated about 21 hours ago

A Telegram Bot providing you ChatGPT experience

Image
Machine Learning & AI

10K+

logo

GitHubbuildCodeFactordocker hubdocker image forlicense

Chibi is a Python-based Telegram chatbot that allows users to interact with the powerful ChatGPT and DALL-E neural networks. The bot is asynchronous, providing fast response times and serving multiple users simultaneously without blocking each other's requests. Chibi supports session management, enabling ChatGPT to remember the user's conversation history. The conversation history is stored for a configurable duration and is preserved even if the bot is restarted.

Supported platforms

  • linux/amd64
  • linux/arm64
  • linux/arm/v7 (Yeah! Your Raspberry Pi is supported!)

Features

  • Optional "Public Mode", when no general OPENAI_API_KEY is required, but every user can provide one own.
  • Switch between GPT models (including GPT-4) at any time.
  • Session management for ChatGPT (by storing data locally or using Redis).
  • Request DALL-E to create an image from the same chat.
  • User and group whitelists.
  • Asynchronous code for quick and non-blocking performance.
  • Extensive configuration options through environment variables.
  • Docker image for easy deployment.
  • Cross-platform support (amd64, arm64, armv7).
  • MIT License.

Try it!

  • You can try a DEMO version of the Chibi bot by using @ChibiDemoBot. An OpenAI API Key is not required, but there are only 4 free requests available.
  • You can also use a public version of the Chibi bot by using @ChibiPublicBot. An OpenAI Key is required.

Prerequisites

  • Docker
  • Docker Compose (optional)

Getting Started

Using Docker Run
  1. Pull the Chibi Docker image:

    docker pull pysergio/chibi:latest
    
  2. Run the Docker container with the necessary environment variables:

    docker run -d \
      -e TELEGRAM_BOT_TOKEN=<your_telegram_token> \
      -e OPENAI_API_KEY=<your_chatgpt_api_key> \
      -v <path_to_local_data_directory>:/app/data \
      --name chibi \
      pysergio/chibi:latest
    

    Replace <your_telegram_token>, <your_chatgpt_api_key>, and <path_to_local_data_directory> with appropriate values.

Using Docker Compose
  1. Create a docker-compose.yml file with the following contents:

       version: '3'
    
       services:
         chibi:
          restart: unless-stopped
          image: pysergio/chibi:latest
          environment:
            OPENAI_API_KEY: <your_chatgpt_api_key>
            TELEGRAM_BOT_TOKEN: <your_telegram_token>
          volumes:
            - chibi_data:/app/data
       
       volumes:
         chibi_data:
    

    Replace <your_telegram_token> and <your_chatgpt_api_key> with appropriate values.

  2. Run the Docker container:

    docker-compose up -d
    

Please, visit the examples directory of the current repository for more examples.

Configuration

You can configure Chibi using the following environment variables:

Required variables:

VariableDescriptionDefault Value
TELEGRAM_BOT_TOKENYour Telegram bot token

Provider access related variables:

VariableDescriptionDefault Value
PUBLIC_MODEIf true, every user will be asked to provide ones own API key to interact with provider(s). Otherwise the API keys set via the variables below will be usedfalse
ANTHROPIC_API_KEYAnthropic (Claude-3) API key. If not provided, the user will be asked to provide it while interacting with the bot.
MISTRALAI_API_KEYMistralAI API key. If not provided, the user will be asked to provide it while interacting with the bot.
OPENAI_API_KEYOpenAI API key. If not provided, the user will be asked to provide it while interacting with the bot.

Variables responsible for the basic behavior of the bot:

VariableDescriptionDefault Value
ALLOW_BOTSAllow other bots to interact with Chibifalse
ANSWER_DIRECT_MESSAGES_ONLYIf True, the bot in group chats will respond only to messages containing its name (see the BOT_NAME setting)true
ASSISTANT_PROMPTInitial assistant prompt for OpenAI ClientYou're a helpful and friendly assistant. Your name is <BOT_NAME>
BOT_NAMEName of the botChibi
LOG_PROMPT_DATALog user's prompts and GPT answers for debug purposesfalse
MESSAGE_FOR_DISALLOWED_USERSMessage to show disallowed usersYou're not allowed to interact with me, sorry. Please contact my owner first.
MODELS_WHITELISTComma-separated list of allowed models, e.g., "gpt-4,gpt-3.5-turbo"
MODEL_DEFAULTDefault OpenAI model to usegpt-3.5-turbo
USERS_WHITELISTComma-separated list of whitelisted usernames, e.g., "@YourName,@YourFriendName,@YourCatName"
HIDE_MODELSHide "models" option from bot menufalse
HIDE_IMAGINEHide "imagine" option from bot menufalse

Proxy & data storage settings:

VariableDescriptionDefault Value
PROXYProxy setting for your application
REDISRedis connection string, e.g., redis://localhost or redis://:my-secret-password@127.0.0.1:6379/1
REDIS_PASSWORDDEPRECATED! Please use REDIS instead. Redis password (optional)

Setting up image generation using DALL-E:

VariableDescriptionDefault Value
DALL_E_MODELDALL-E model. Available values: dall-e-2, dall-e-3dall-e-3
IMAGE_GENERATIONS_LIMITThe number of images that a typical non-whitelisted user can generate per month. 0 - no limits.0
IMAGE_GENERATIONS_WHITELISTComma-separated list of user IDs (not usernames) for whom the image generation limit does not apply
IMAGE_QUALITYQuality of the image generated by DALL-E. Available values: standard, hdstandard
IMAGE_SIZESize of the image generated by DALL-E. Available values: 256x256, 512x512, 1024x1024, 1792x1024, 1024x17921024x1024

Fine-tuning response generation. Already preconfigured and tested. You probably won't want to touch it:

VariableDescriptionDefault Value
FREQUENCY_PENALTYOpenAI frequency penalty0
GROUPS_WHITELISTComma-separated list of whitelisted group IDs, e.g., "-799999999,-788888888"
MAX_CONVERSATION_AGE_MINUTESMaximum age of conversations (in minutes)60
MAX_HISTORY_TOKENSMaximum number of tokens in conversation history1800
MAX_TOKENSMaximum tokens for the OpenAI Client1000
OPENAI_IMAGE_N_CHOICESNumber of choices for image generation in DALL-E1
PRESENCE_PENALTYOpenAI presence penalty0
TEMPERATUREOpenAI temperature for response generation0.5
TIMEOUTTimeout (in seconds) for processing requests120

Please, visit the examples directory for the example of .env-file.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Docker Pull Command

docker pull pysergio/chibi