Skip to main content

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.

Metadata

Release files for telegram-bot-gpt 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for telegram-bot-gpt 0.3.0
File Size Uploaded
telegram-bot-gpt-0.3.0.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telegram-bot-gpt 0.3.0
File Interpreter ABI Platform
telegram_bot_gpt-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.2 kB

Release files / telegram-bot-gpt-0.3.0.tar.gz

Download URL telegram-bot-gpt-0.3.0.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f1f5fe78b0f4ccc1517368c4462ebfbd229f02651904d8a5bb054455e13d2618
BLAKE2b-256 checksum
How to use checksums
1bbfb6ccb8e68136f94ba59cdec28e85fb534615356d73b50ea571ad1c7f9494
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / telegram_bot_gpt-0.3.0-py3-none-any.whl

Download URL telegram_bot_gpt-0.3.0-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5aa2b9a1a4eaecc1c93022ea09c91a99af9a21830bba7129d43959d91b09d41e
BLAKE2b-256 checksum
How to use checksums
ef6d39db33505557bae1d4cf6a3d5c48b058ef9c04fa55691fa88cce7db13786
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.1.1

2 release files

0.0.40

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page