OpenAI GPT, driven by Telegram
Project description
TeLLMgramBot
The basic goal of this project is to create a bridge between a Telegram Bot and a Large Langage Model (LLM), like ChatGPT.
Telegram Bot + LLM Encapsulation
- The Telegram interface handles special commands, especially on some basic "chatty" prompts and responses that don't require LLM, like "Hello".
- The more dynamic conversation gets handed off to the LLM to manage prompts and responses, and Telegram acts as the interaction broker.
- Pass the URL in [square brackets] and mention how the bot should interpret it.
- Example: "What do you think of this article? [https://some_site/article]"
- This uses another ChatGPT model, preferrably GPT-4, to support more URL content by OpenAI tokens.
- After starting up, the bot can remember 50% of past conversations by a ChatGPT token limit.
- Conversations between the Telegram bot assistant and user will be stored in a folder
sessionlogs. - Users can also clear their conversation history for privacy.
- Conversations between the Telegram bot assistant and user will be stored in a folder
Why Telegram?
Using Telegram as the interface not only solves "exposing" the interface, but gives you boadloads of interactivity over a standard Command Line interface, or trying to create a website with input boxes and submit buttons to try to handle everything:
- Telegram already lets you paste in verbose, multiline messages.
- Telegram already lets you paste in pictures, videos, links, etc.
- Telegram already lets you react with emojis, stickers, etc.
API Keys
To operate TeLLMgramBot, three API keys are required:
- OpenAI - Drives the actual GPT AI.
- BotFather - Helps create a new Telegram bot and provide its API.
- VirusTotal - Performs safety checks on URLs.
There are two ways to populate each API key: environment variables or .key files.
Environment Variables
TeLLMgramBot uses the following environment variables that can be pre-loaded with the three API keys respectively:
TELLMGRAMBOT_OPENAI_API_KEYTELLMGRAMBOT_TELEGRAM_API_KEYTELLMGRAMBOT_VIRUSTOTAL_API_KEY
During spin-up time, a user can call out os.environ[env_var] to set those variables, like the following example:
my_keys = Some_Vault_Fetch_Function()
os.environ['TELLMGRAMBOT_OPENAI_API_KEY'] = my_keys['GPTKey']
os.environ['TELLMGRAMBOT_TELEGRAM_API_KEY'] = my_keys['BotFatherToken']
os.environ['TELLMGRAMBOT_VIRUSTOTAL_API_KEY'] = my_keys['VirusTotalToken']
This means the user can implement whatever key vault they want to fetch the keys at runtime, without needing files stored in the directory.
API Key Files
By default, three files are created for the user to input each API key:
openai.keytelegram.keyvirustotal.key
Setting each file also updates its respective environment variable as discussed before, if not defined.
Bot Setup
This library includes an example script test_local.py, which extracts values from sample files config.yaml and prompts/test_personality.prmpt for TeLLMgramBot to process.
- Ensure the previous sections are followed with the proper API keys and your Telegram bot set.
- Install this library via PIP (
pip install TeLLMgramBot) and then import into your project. - Instantiate the bot by passing in various configuration pieces needed below:
telegram_bot = TeLLMgramBot.TelegramBot( bot_username = <Bot username like 'friendly_bot'>, bot_owner = <Bot owner's Telegram username>, bot_name = <Bot name like 'Friendly Bot'>, bot_nickname = <Bot nickname like 'Botty'>, bot_initials = <Bot initials like 'FB'>, chat_model = <Conversation ChatGPT model like 'gpt-3.5-turbo'>, url_model = <URL contents ChatGPT model like 'gpt-4'>, token_limit = <Maximum token count set, by default chat_model max>, persona_temp = <LLM factual to creative value [0-2], by default 1.0>, persona_prompt = <System prompt summarizing bot personality> ) - Turn on TeLLMgramBot by calling:
Once you seetelegram_bot.start_polling()TeLLMgramBot polling..., the bot is online in Telegram. - Type
/commandsto show all available reported by theTelegramCommands.txtfile. - Only by the bot owner, type
/startto initiate user conversations.
Resources
- GitHub repository python-telegram-bot has guides to create a Telegram bot.
- For more information on ChatGPT models like
gpt-3.5-turboand tokens, see the following: - OpenAI Playground helps test a personality prompt more.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file TeLLMgramBot-1.3.2.tar.gz.
File metadata
- Download URL: TeLLMgramBot-1.3.2.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd71162d63a9c20dd413cab0f25026ef70f345ab76c647f096577f59deab148f
|
|
| MD5 |
201defacd05f1f8436ce8ac8e8e226d0
|
|
| BLAKE2b-256 |
d17ea8224ebea01e47c33fdd588b83f0b4f6ef666f2ed95331a65cd00f3a57b3
|
File details
Details for the file TeLLMgramBot-1.3.2-py3-none-any.whl.
File metadata
- Download URL: TeLLMgramBot-1.3.2-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce1f51d96d6f8312fd18fdbf492f1238f8964b1a5378c09b345c77ac29d9e35b
|
|
| MD5 |
616ff913f7b8adc7383d1c7cdc79bd04
|
|
| BLAKE2b-256 |
0ff2141d4228443d9b32f9c24a81a049c53a13a45820c259f3e3c7fe5db593a6
|