added RAG, Multiuser, TG bot
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from aiogram import Bot
|
||||
|
||||
TG_MAX_LEN = 4096
|
||||
|
||||
|
||||
def split_telegram_message(text: str, limit: int = TG_MAX_LEN) -> list[str]:
|
||||
if len(text) <= limit:
|
||||
return [text]
|
||||
chunks: list[str] = []
|
||||
remaining = text
|
||||
while remaining:
|
||||
if len(remaining) <= limit:
|
||||
chunks.append(remaining)
|
||||
break
|
||||
split_at = remaining.rfind("\n", 0, limit)
|
||||
if split_at <= 0:
|
||||
split_at = limit
|
||||
chunks.append(remaining[:split_at])
|
||||
remaining = remaining[split_at:].lstrip("\n")
|
||||
return chunks
|
||||
|
||||
|
||||
async def send_text(bot: Bot, chat_id: int, text: str) -> None:
|
||||
for chunk in split_telegram_message(text):
|
||||
await bot.send_message(chat_id, chunk)
|
||||
Reference in New Issue
Block a user