A Discord bot that generates Traditional Chinese summaries of arXiv papers with PDF reports and provides monthly curated lists of influential research papers.
- π Paper Summarization: Extract arXiv papers and generate structured Traditional Chinese summaries
- π€ Multi-Stage LLM Pipeline: Pre-sanitizer β Main Summarizer β Validator for quality assurance
- π PDF Reports: Automatically generate professional PDF reports
- πΎ Smart Caching: Redis-based caching for metadata, summaries, and PDFs (7-30 day TTLs)
- β±οΈ Rate Limiting: Multi-tier rate limiting (default, trusted, admin)
- π Cost Tracking: Token usage and cost estimation per request and daily aggregates
- π Streaming Updates: Real-time progress updates in Discord
Discord β Bot Service ββ¬β LLM Service (OpenAI/vLLM)
ββ Retriever (arXiv/Semantic Scholar)
ββ PDF Exporter
ββ Redis Cache
ββ Scheduler (Monthly Push)
- Stage A (Pre-Sanitizer): Small model cleans and validates metadata
- Stage B (Main Summarizer): Primary model generates ηΉι«δΈζ structured summary
- Stage C (Validator): Low-temperature validation of JSON schema and language compliance
- Docker & Docker Compose
- Discord Bot Token (Create one here)
- OpenAI API Key (or self-hosted vLLM)
-
Clone the repository
git clone <repository-url> cd discord-arxiv
-
Configure environment
cp .env.example .env # Edit .env with your credentials -
Required environment variables
DISCORD_TOKEN=your_discord_bot_token OPENAI_API_KEY=your_openai_api_key OPENAI_BASE_URL=https://api.openai.com/v1 # or vLLM endpoint -
Start services with Docker Compose
docker-compose up -d
-
Check logs
docker-compose logs -f bot
-
Install dependencies
pip install -r requirements.txt
-
Start Redis
docker run -d -p 6379:6379 redis:7-alpine
-
Run the bot
python -m src.bot.main
Generate a Traditional Chinese summary of an arXiv paper.
Examples:
/summarize 2401.01234
/summarize https://arxiv.org/abs/2401.01234
/summarize https://arxiv.org/pdf/2401.01234.pdf
Output:
- Structured embed with 4 sections (η°‘δ»/θζ―/ζΉζ³/η΅θ«)
- Bullet points highlighting key contributions
- PDF report attachment
Processing time: Typically 10-30 seconds
Get top cited papers from arXiv and conferences (coming soon).
Examples:
/top-papers
/top-papers 2024-11
/top-papers 2024-11 LLM
See .env.example for all available options. Key settings:
| Variable | Description | Default |
|---|---|---|
OPENAI_MODEL |
Main summarization model | gpt-4o-mini |
OPENAI_MODEL_PRE |
Pre-processing model | gpt-4o-mini |
OPENAI_MODEL_VAL |
Validation model | gpt-4o-mini |
LLM_TEMPERATURE |
Generation temperature | 0.2 |
REDIS_URL |
Redis connection URL | redis://localhost:6379/0 |
S2_API_KEY |
Semantic Scholar API key | (optional) |
Configured per user tier:
- Default: 3 requests/min, 20/day
- Trusted: 6 requests/min, 100/day
- Admin: Unlimited (tracked)
Adjust in .env:
RATE_LIMIT_DEFAULT_PER_MIN=3
RATE_LIMIT_DEFAULT_PER_DAY=20Uncomment the vllm service in docker-compose.yml and set:
OPENAI_BASE_URL=http://vllm:8000/v1
OPENAI_API_KEY=dummy # vLLM doesn't require real keysrc/
βββ bot/ # Discord bot & commands
β βββ commands/ # Slash commands (/summarize, /top-papers)
β βββ main.py # Bot entry point
βββ llm/ # LLM pipeline
β βββ client.py # OpenAI-compatible client
β βββ pipeline.py # Multi-stage pipeline (A/B/C)
β βββ prompts/ # Prompt templates
β βββ validators/ # Output validators
βββ retriever/ # Data retrievers
β βββ arxiv.py # arXiv API client
β βββ semantic_scholar.py # Citation data
βββ exporter/ # PDF generation
β βββ pdf.py # ReportLab PDF exporter
βββ config/ # Configuration
β βββ settings.py # Pydantic settings
β βββ logging.py # Structured logging
β βββ cache.py # Redis cache layer
βββ telemetry/ # Observability (future)
Redis key namespace: dra:*
| Key Pattern | TTL | Description |
|---|---|---|
dra:paper:{id}:meta |
7d | arXiv metadata |
dra:paper:{id}:summary:{model}:v1 |
30d | Generated summaries |
dra:pdf:{id}:{model}:v1 |
30d | PDF info |
dra:citations:{month} |
7d | Monthly citation data |
dra:cost:daily:{date} |
90d | Daily cost tracking |
dra:rate:discord:{user_id}:* |
60s-24h | Rate limiting |
The bot tracks token usage and estimated costs:
- Per-request tracking:
tokens_in,tokens_out,cost_estimated,duration_ms - Daily aggregates stored in Redis
- Simplified pricing estimates (configurable in
llm/client.py)
View daily costs (requires admin access):
from src.config.cache import RedisCache
cache = RedisCache("redis://localhost:6379/0")
await cache.connect()
costs = await cache.get_daily_cost("2024-11-22")
print(costs) # {'tokens_in': 12500, 'tokens_out': 3200, 'cost_estimated': 0.025}pytest tests/- See
CLAUDE.mdfor architecture guidelines - See
TDS.mdfor complete technical design specification - See
AGENDA.mdfor development phases and milestones
- Check bot is online:
docker-compose logs bot - Verify
SYNC_COMMANDS=truein.env - For guild commands, set
COMMAND_SCOPE=guildandCOMMAND_GUILD_IDS - Manually sync: Bot will sync on startup if configured
# Check Redis is running
docker-compose ps redis
# Check logs
docker-compose logs redisChinese characters require proper font support. The PDF exporter uses reportlab's default Unicode support. For custom fonts, add TTF files and register in src/exporter/pdf.py.
- Check
OPENAI_BASE_URLandOPENAI_API_KEY - Verify API quota and rate limits
- Check logs:
docker-compose logs bot | grep llm_error
See AGENDA.md for detailed phases:
- β Phase 1: Foundations (Bot, Retriever, LLM Pipeline)
- β Phase 2: Feature Completion (/summarize command, PDF export)
- π§ Phase 3: Hardening (Tests, error handling, load testing)
- π Phase 4: Launch (Monthly scheduler, /top-papers, observability)
This project follows the Technical Design Spec in TDS.md. Key principles:
- Multi-stage LLM pipeline for quality
- Aggressive caching for cost control
- Structured logging for observability
- Traditional Chinese (ηΉι«δΈζ) output
- Docker-first deployment
[Add your license here]
For issues and questions:
- Check
CLAUDE.mdfor development guidelines - Review
TDS.mdfor technical specifications - See structured logs:
docker-compose logs bot | jq