DiscordianAI is a production-ready Discord bot that blends OpenAI GPT-5 frontier models with Perplexity Sonar-Pro web search. It focuses on conversation consistency, deterministic routing, and Discord-native formatting so answers stay contextual, accurate, and easy to read.
- Hybrid intelligence: GPT-5 handles reasoning/creative prompts while Sonar-Pro covers current events with structured citations.
- Conversation consistency: Follow-up detector keeps a thread on the same AI service, preventing jarring context shifts.
- Discord-first UX: Citation-aware embeds, smart message splitting, and automatic embed suppression keep chats readable.
- Operations minded: HTTP/2 connection pooling, circuit breakers, and health checks keep long-running bots stable.
- Single-source configuration:
config.inidrives every runtime mode, and validators catch unsupported parameters early.
| Mode | Description |
|---|---|
| π§ Smart Hybrid | Analyze each message, then route to GPT-5 or Sonar-Pro with follow-up consistency. |
| π€ OpenAI Only | Force GPT-5 for every response; great for creative and coding-focused servers. |
| π Perplexity Only | Force Sonar-Pro for every response; ideal for research or news-heavy servers. |
- Install Python 3.12 or newer and create a virtual environment.
- Clone & install:
pip install -e .[dev] - Copy config:
cp config.ini.example config.ini - Set tokens in
config.ini(Discord, OpenAI, Perplexity as needed). - Run the bot:
python -m src.main --conf config.ini - Run tests before shipping:
pytest(coverage gate: 84% via tox/Codecov)
Need the full Discord bot creation walkthrough and environment prep? See docs/Setup.md.
python -m src.main --conf config.ini --folder /path/to/base/folder--confpoints at the config file.--folder(optional) makes config/log paths relative to a base directory (useful for Docker or systemd units).
| Key | Purpose |
|---|---|
DISCORD_TOKEN |
Bot authentication token from the Discord Developer Portal. |
GPT_MODEL |
GPT-5 series model (gpt-5-mini, gpt-5, gpt-5-nano, gpt-5-chat). |
PERPLEXITY_MODEL |
Perplexity Sonar model (sonar-pro default, sonar fallback). |
INPUT_TOKENS / OUTPUT_TOKENS |
Caps for prompt and completion tokens (GPT-5 uses max_completion_tokens). |
LOOKBACK_MESSAGES_FOR_CONSISTENCY |
How many prior turns to inspect when enforcing AI service consistency. |
OPENAI_MAX_CONNECTIONS / PERPLEXITY_MAX_CONNECTIONS |
HTTP/2 pooling limits for each API client. |
[Discord]
DISCORD_TOKEN=your_discord_bot_token
[Default]
OPENAI_API_KEY=sk-your-openai-key
OPENAI_API_URL=https://api.openai.com/v1/
GPT_MODEL=gpt-5-mini
PERPLEXITY_API_KEY=pplx-your-perplexity-key
PERPLEXITY_MODEL=sonar-pro
INPUT_TOKENS=120000
OUTPUT_TOKENS=8000
SYSTEM_MESSAGE=You are a helpful assistant with access to current web information.
[Limits]
RATE_LIMIT=10
RATE_LIMIT_PER=60smart_orchestrator.pyroutes messages via semantic analysis, entity detection, and follow-up tracking.message_processor.pynormalizes Discord input, calls the orchestrator, and records AI metadata for future turns.openai_processing.pyandperplexity_processing.pybuild strictly supported API payloads (GPT-5 ignores temperature, Sonar-Pro sampling is managed server-side).
discord_embeds.pyformats Perplexity citations into clean embeds with automatic suppression when multiple links exist.message_splitter.pyenforces Discord limits (2000 / 3840 / 4096 chars) with code-block and citation awareness.message_router.pycentralizes mention handling, DM routing, and rate-limit responses.
connection_pool.pyexposes tuned HTTP/2 clients (50/10 connections for OpenAI, 30/5 for Perplexity).health_checks.pyverifies API reachability and validates GPT-5/Sonar configurations at startup.api_validation.py+api_utils.pyguard against unsupported model strings and capture structured error metadata.
| Topic | Reference |
|---|---|
| Setup & onboarding | docs/Setup.md |
| Architecture & flow | docs/Architecture.md |
| Smart routing internals | docs/HybridMode.md |
| Configuration deep dive | docs/Configuration.md |
| OpenAI usage | docs/OpenAI.md |
| Perplexity usage & citations | docs/Perplexity.md |
| Message splitting & embeds | docs/MessageSplitting.md, docs/EmbedLimits.md |
| Web scraping pipeline | docs/WebScraping.md |
| Connection pooling & HTTP/2 | docs/ConnectionPooling.md |
| Docker & daemonization | docs/Docker.md, docs/Daemon.md |
| Security & rate limiting | docs/Security.md |
| Development workflow | docs/Development.md |
| API parameter validation | docs/API_Validation.md |
# Install dev extras
pip install -e .[dev]
# Lint & format
ruff check --fix .
black .
# Run the targeted suites
pytest -q
pytest tests/test_smart_orchestrator_coverage.pyUse tox for the CI matrix (tox, tox -e py312, tox --parallel auto, tox -e audit). CI runs Ruff, Black, pytest with coverage, and pip-audit; locally run tox -e audit to scan runtime + dev deps.
- Keep
config.iniout of version control; copy fromconfig.ini.exampleand setchmod 600 config.inion servers. - Prefer environment variables in production (
export DISCORD_TOKEN=...). - Rotate OpenAI (
sk-...) and Perplexity (pplx-...) keys regularly; validators will reject malformed prefixes. - Limit Discord bot permissions to the channels where it operates.
- Monitor logs for rate-limit bursts or scraping failures and adjust
RATE_LIMIT/RATE_LIMIT_PERaccordingly.
- Questions or feedback: [email protected]
- Issues and feature requests: open a GitHub issue.
- Licensed under the Unlicense.