Skip to content

reginanka/Sum-AI-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ AI Article Summarizer Bot

A powerful Telegram bot designed to instantly summarize articles and answer questions about their content using advanced AI. Let artificial intelligence handle long reads for you!

✨ Features

  • πŸ“„ Article Summaries - Send a link to any article and receive a concise summary.
  • πŸ’¬ Post Analysis - Forward any Telegram post to generate a quick summary.
  • πŸ“ Text Processing - Send long texts (>500 characters) to be summarized instantly.
  • ❓ Q&A Mode - Ask questions about the read article and get accurate answers based on its context.
  • 🧠 Contextual Memory - The bot remembers previous questions and answers during the conversation.
  • 🌐 Multilingual Interface - Fully supports both English and Ukrainian languages.
  • πŸ’Ύ Persistent Storage - Securely stores user preferences and session data in a Supabase PostgreSQL database.

πŸš€ Tech Stack

  • FastAPI - High-performance web framework for webhook handling.
  • SQLAlchemy - Robust ORM for seamless database interactions.
  • Supabase (PostgreSQL) - Scalable cloud database solution.
  • Cerebras AI API - Ultra-fast LLM processing (powered by llama3.1-8b) for generating summaries and answers.
  • BeautifulSoup4 - Efficient HTML parsing and text extraction.
  • Telegram Bot API - Seamless integration with the Telegram ecosystem.

πŸ“‹ Requirements

fastapi>=0.104.0
sqlalchemy>=2.0.0
psycopg2-binary>=2.9.9
requests>=2.31.0
beautifulsoup4>=4.12.0

🌐 Deploying on Vercel

1. Project Preparation

Ensure the following files are present in the root directory:

  • api/index.py - Core bot logic (Vercel serverless function endpoint)
  • requirements.txt - Python dependencies
  • vercel.json - Vercel configuration file

2. Configure vercel.json

{
  "version": 2,
  "builds": [
    {
      "src": "api/index.py",
      "use": "@vercel/python"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "api/index.py"
    }
  ]
}

3. Vercel Deployment Steps

  1. Push your code to a GitHub repository.
  2. Log in to Vercel and click New Project.
  3. Import your GitHub repository.
  4. Go to Settings > Environment Variables and add the following keys:
    • TELEGRAM_TOKEN = your_telegram_bot_token
    • CEREBRAS_API_KEY = your_cerebras_api_key
    • DATABASE_URL = postgresql://user:password@host:port/database
    • ACCESS_CODE = your_secret_access_code
  5. Click Deploy.

4. Setup Telegram Webhook

Once deployed, run this in your terminal to connect the Telegram bot to Vercel:

curl -X POST "https://api.telegram.org/bot<YOUR_TELEGRAM_TOKEN>/setWebhook" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://your-project.vercel.app/webhook"}'

βš™οΈ Local Development

1. Clone the Repository

git clone <repository-url>
cd Sum_AIbot

2. Install Dependencies

pip install -r requirements.txt

3. Configure Environment Variables

Create a .env file in the root directory:

TELEGRAM_TOKEN=your_telegram_bot_token
CEREBRAS_API_KEY=your_cerebras_api_key
DATABASE_URL=postgresql://user:password@host:port/database
ACCESS_CODE=your_secret_access_code

4. Run Locally

uvicorn api.index:app --reload --port 8000

Note: For local Telegram webhooks, you can use ngrok to expose port 8000.

πŸ—„οΈ Supabase Setup

  1. Register on Supabase.
  2. Create a new project and copy the DATABASE_URL from the database settings.
  3. The server application will automatically create the required user_data table upon its first database connection:
CREATE TABLE user_data (
    user_id BIGINT PRIMARY KEY,
    language TEXT DEFAULT 'ua',
    article_text TEXT,
    conversation TEXT,
    article_url TEXT,
    has_unlimited BOOLEAN DEFAULT FALSE,
    code_verified BOOLEAN DEFAULT FALSE,
    articles_used INTEGER DEFAULT 0,
    last_reset TIMESTAMP
);

πŸ“± Bot Usage

Commands

  • /start - Start the bot and select a language.
  • /help - View instructions and available actions.

Workflow Example

  1. You share a link to a news article.
    • Bot: πŸ“„ Processing article...
    • Bot: πŸ“„ Summary: [concise summary generated by AI]
  2. You ask: "What are the main causes mentioned in the text?"
    • Bot: πŸ’‘ The main causes are...

🚫 Limitations

  • ❌ YouTube / Social Media Platforms: Meta (Facebook/Instagram), Notion, and YouTube links are currently blocked due to technical limitations regarding automated text parsing.
    • Workaround: Copy the text manually and paste it into the chat.
  • ⏱️ Vercel Timeout: Free tier Vercel functions time out after 10 seconds. Heavily loaded prompts or enormous articles might reach this limit.

πŸ”’ Security Practices

  • Keep your .env tokens completely private and never commit them to the repository.
  • Rely on environment variables through the Vercel dashboard.
  • The bot utilizes PostgreSQL connection pooling and handles HTML escaping thoroughly.

πŸ“„ License

This project is licensed under the MIT License - feel free to use and modify it!

πŸ‘€ Developer & Socials

Designed and developed by Gearberry β€” available for custom ecosystem architecture and high-performance web development. Feel free to connect with me:


⭐ Enjoying the project? Please consider starring the repository!

Rehina Nanaka profile views

About

⚑️ Ultra-fast Telegram bot for instant article summaries & contextual Q&A. Powered by Cerebras AI (Llama 3.1) & FastAPI. Stop reading, start knowing. πŸš€

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages