Skip to main content

A simple interface for OpenAI GPT-3 and GPT-4 using Telegram bots

Project description

Telegram-Bot-GPT

A simple interface for OpenAI GPT-3 and GPT-4 using Telegram bots.

DISCLAIMER

This open-source module is only intended to provide an interface between bot and AI on top of the following services:

  • Bot provided for free by Telegram FZ-LLC
  • GPT AI capabilities as paid services from OpenAI LP

The creator of this library is not in any way responsible for any misuse of the module, including but not limited to any costs that may occur due to calls to the GPT AI.

Using this library states that you are agree with this disclaimer.


Installation

pip install telegram-bot-gpt

Usage

import bot_gpt as bot

mybot = bot.Engine("<YOUR_TELEGRAM_TOKEN>")
mybot.set_openai_key("<YOUR_OPENAI_KEY>")  # a filename also accepted

mybot.run()     # only polling method is provided

That's it!!


Special Features

  • Admin now has access to GPT-4
  • Using global OTP, changeable and resetable by admin
  • A small number of chats are stored encrypted as bot memory
  • Used tokens are recorded along with the model, useful for cost calculation
  • Modifiable bot parameters

Dev Functions

  • Settings

    The variable bot.DEFAULT_SETTING contains a dict of the initial values of accessible configurations:

    {
      "memory_length": 3,        # the number of previous lines involved
      "ai_temperature": 85,      # 0.75 in the API input
      "bot_active": 1,           # 0 is deactivated
      "daily_limit": 50,         # daily usage limit for common users, server time
      "admin_limit": 999,        # daily usage limit for admin, server time
      "password": ""             # will be set automatically at first run
    }
    

    Accessing variables:

    1. mybot.set_daily_limit(100) modify value
    2. mybot.reset_daily_limit() reset to default
    3. current_daily_limit = mybot.get("daily_limit") obtain the value
    4. mybot.reset_settings() reset all values to default

  • Bot name

    mybot.set_botname("My Bot")
    mybot.reset_botname()        # default is "Bot-GPT"
    

  • OpenAI key

    mybot.set_openai_key("<YOUR_OPENAI_KEY_OR_CORRESPONDING_FILENAME>")
    mybot.del_openai_key()       # AI capabilities will be deactivated
    

  • Memory length, only used when the input is short

    mybot.set_memory_length(5)   # more value leads to a more expensive cost
    mybot.reset_memory_length()  # default is 3
    memory_length = mybot.get_memory_length()
    

Bot Usage

  • Admin
    The first user is automatically set as the bot admin which is equipped with a list of commands such as password regulations and bot activations.

  • Password
    New users should enter a randomized code (password) created by the bot which can only be accessed by admin with these commands:

    • /get_password displays the current password
    • /new_passowrd changes the password without affecting current users
    • /reset_password force all users to enter the new password to continue using the bot

  • Deactivation
    The default setting for bot is active, whereas only admin has the right to modify it.

    • /deactivate_bot bot is off for all users, while admin still can use it
    • /activate_bot reactivates the bot for all users

    All users can check the bot status using /is_bot_active.


How To Get

Telegram Bot
Open Telegram app, chat with @BotFather and send the command /newbot.

OpenAI key
Login to OpenAI and follow the instructions there.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram-bot-gpt-0.3.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_bot_gpt-0.3.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file telegram-bot-gpt-0.3.0.tar.gz.

File metadata

  • Download URL: telegram-bot-gpt-0.3.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for telegram-bot-gpt-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f1f5fe78b0f4ccc1517368c4462ebfbd229f02651904d8a5bb054455e13d2618
MD5 82a5de1751a240225d38140287c9ddbc
BLAKE2b-256 1bbfb6ccb8e68136f94ba59cdec28e85fb534615356d73b50ea571ad1c7f9494

See more details on using hashes here.

File details

Details for the file telegram_bot_gpt-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_bot_gpt-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5aa2b9a1a4eaecc1c93022ea09c91a99af9a21830bba7129d43959d91b09d41e
MD5 cb2bbe2da40ecbcf221a528f24f1d3a0
BLAKE2b-256 ef6d39db33505557bae1d4cf6a3d5c48b058ef9c04fa55691fa88cce7db13786

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page