GithubHelp home page GithubHelp logo

txsing / chatgpt-telegram-bot-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from n3d1117/chatgpt-telegram-bot

0.0 0.0 0.0 288 KB

馃 A Telegram bot that integrates with OpenAI's official ChatGPT APIs to provide answers, written in Python

License: GNU General Public License v2.0

Python 98.02% Dockerfile 1.98%

chatgpt-telegram-bot-python's Introduction

ChatGPT Telegram Bot

python-version openai-version license

A Telegram bot that integrates with OpenAI's official ChatGPT APIs to provide answers. Ready to use with minimal configuration required.

Screenshots

demo.pdf

Features

  • Support markdown in answers
  • Reset conversation with the /reset command
  • Typing indicator while generating a response
  • Access can be restricted by specifying a list of allowed users
  • Docker support
  • Proxy support
  • (NEW!) Support multiple answers via the n_choices configuration parameter
  • (NEW!) Customizable model parameters (see configuration section)
  • (NEW!) See token usage after each answer
  • (NEW!) Multi-chat support
  • (NEW!) Image generation using DALL路E via the /image command

Additional Features - help needed!

  • Group chat support

PRs are always welcome!

Prerequisites

Getting started

Configuration

Customize the configuration by copying .env.example and renaming it to .env, then editing the parameters as desired:

OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
TELEGRAM_BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN"

# Optional parameters
ALLOWED_TELEGRAM_USER_IDS="USER_ID_1,USER_ID_2,..." # Defaults to "*" (everyone)
PROXY="YOUR_PROXY" # e.g. "http://localhost:8080", defaults to none
SHOW_USAGE=true # Defaults to false
  • OPENAI_API_KEY: Your OpenAI API key, you can get it from here
  • TELEGRAM_BOT_TOKEN: Your Telegram bot's token, obtained using BotFather (see tutorial)
  • ALLOWED_TELEGRAM_USER_IDS: A comma-separated list of Telegram user IDs that are allowed to interact with the bot (use getidsbot to find your user ID). Note: by default, everyone is allowed (*)
  • PROXY: Proxy to be used for OpenAI and Telegram bot
  • SHOW_USAGE: Whether to show OpenAI token usage information after each response

Additional model parameters can be configured from the main.py file:

{
    # 'gpt-3.5-turbo' or 'gpt-3.5-turbo-0301'
    'model': 'gpt-3.5-turbo',
    
    # An initial system message that sets the tone and controls the behavior of the assistant.
    'assistant_prompt': 'You are a helpful assistant.',
    
    # Number between 0 and 2. Higher values like 0.8 will make the output more random,
    # while lower values like 0.2 will make it more focused and deterministic. Defaults to 1
    'temperature': 1,
    
    # How many answers to generate for each input message. Defaults to 1
    'n_choices': 1,
    
    # The maximum number of tokens allowed for the generated answer. Defaults to 1200
    'max_tokens': 1200,
    
    # Number between -2.0 and 2.0. Positive values penalize new tokens based on whether
    # they appear in the text so far, increasing the model's likelihood to talk about new topics. Defaults to 0
    'presence_penalty': 0,
    
    # Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing
    # frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. Defaults to 0
    'frequency_penalty': 0,
    
    # The DALL路E generated image size. 256x256, 512x512, or 1024x1024. Defaults to 512x512
    'image_size': '512x512'
}

See the official API reference for more details.

Installing

  1. Clone the repository and navigate to the project directory:
git clone https://github.com/n3d1117/chatgpt-telegram-bot.git
cd chatgpt-telegram-bot

From Source

  1. Create a new virtual environment with Pipenv and install the required dependencies:
pipenv install
  1. Activate the virtual environment:
pipenv shell
  1. Use the following command to start the bot:
python main.py

Using Docker Compose

  1. Run the following command to build and run the Docker image:
docker-compose up

Credits

Disclaimer

This is a personal project and is not affiliated with OpenAI in any way.

License

This project is released under the terms of the GPL 2.0 license. For more information, see the LICENSE file included in the repository.

chatgpt-telegram-bot-python's People

Contributors

n3d1117 avatar rogerrordo avatar slippersheepig avatar txsing avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google 鉂わ笍 Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.