Skip to content

Commit

Permalink
Add allowed_users feature
Browse files Browse the repository at this point in the history
thanks to @gianlucaalfa
  • Loading branch information
tpai committed Mar 9, 2024
1 parent 31d3135 commit 2c14308
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -13,14 +13,15 @@ An AI-powered text summarization Telegram bot that generates concise summaries o

## Usage

Launch a GPT-4 summary bot using OpenAI.
Launch a OpenAI GPT-4 summary bot that only can be used by your friend and you.

```sh
docker run -d \
-e LLM_MODEL=gpt-4 \
-e OPENAI_API_KEY=$OPENAI_API_KEY \
-e TELEGRAM_TOKEN=$YOUR_TG_TOKEN \
-e TS_LANG=$YOUR_LANGUAGE \
-e ALLOWED_USERS=<your_friends_id>,<your_id> \
tonypai/summary-gpt-bot:latest
```

Expand Down Expand Up @@ -54,3 +55,4 @@ Bot Variables
| LLM_MODEL | LLM Model to use for text summarization (default: gpt-3.5-turbo-16k) |
| TELEGRAM_TOKEN | Token for Telegram API (required) |
| TS_LANG | Language of the text to be summarized (default: Taiwanese Mandarin) |
| ALLOWED_USERS | You can get your own ID by asking to @myidbot (optional) |
12 changes: 9 additions & 3 deletions main.py
Expand Up @@ -14,7 +14,8 @@
telegram_token = os.environ.get("TELEGRAM_TOKEN", "xxx")
model = os.environ.get("LLM_MODEL", "gpt-3.5-turbo-16k")
lang = os.environ.get("TS_LANG", "Taiwanese Mandarin")
chunk_size= int(os.environ.get("CHUNK_SIZE", 10000))
chunk_size = int(os.environ.get("CHUNK_SIZE", 10000))
allowed_users = os.environ.get("ALLOWED_USERS", "")

def split_user_input(text):
# Split the input text into paragraphs
Expand Down Expand Up @@ -164,6 +165,13 @@ async def handle(command, update, context):
chat_id = update.effective_chat.id
print("chat_id=", chat_id)

if allowed_users:
user_ids = allowed_users.split(',')
if str(chat_id) not in user_ids:
print(chat_id, "is not allowed.")
await context.bot.send_message(chat_id=chat_id, text="You have no permission to use this bot.")
return

try:
if command == 'start':
await context.bot.send_message(chat_id=chat_id, text="I can summarize text, URLs, PDFs and YouTube video for you.")
Expand Down Expand Up @@ -196,8 +204,6 @@ async def handle(command, update, context):
text = page.extract_text()
text_array.append(text)

print(file_path)

await context.bot.send_chat_action(chat_id=chat_id, action="TYPING")
summary = summarize(text_array)
await context.bot.send_message(chat_id=chat_id, text=f"{summary}", reply_to_message_id=update.message.message_id, reply_markup=get_inline_keyboard_buttons())
Expand Down

0 comments on commit 2c14308

Please sign in to comment.