Skip to content

johndotpub/DiscordianAI

CI CodeQL codecov Security: pip-audit

Tests: py312 required Python 3.12+ required

Code style: black Ruff pre-commit

Discord.py OpenAI Perplexity License: Unlicense

GitHub release GitHub stars Docker GitHub issues

DiscordianAI

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.

What Makes It Different

  • 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.ini drives every runtime mode, and validators catch unsupported parameters early.

Operation Modes

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.

Quick Start

  1. Install Python 3.12 or newer and create a virtual environment.
  2. Clone & install: pip install -e .[dev]
  3. Copy config: cp config.ini.example config.ini
  4. Set tokens in config.ini (Discord, OpenAI, Perplexity as needed).
  5. Run the bot: python -m src.main --conf config.ini
  6. 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.

Running directly

python -m src.main --conf config.ini --folder /path/to/base/folder
  • --conf points at the config file.
  • --folder (optional) makes config/log paths relative to a base directory (useful for Docker or systemd units).

Configuration Essentials

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.

Minimal hybrid config

[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=60

Key Components

AI Orchestration

  • smart_orchestrator.py routes messages via semantic analysis, entity detection, and follow-up tracking.
  • message_processor.py normalizes Discord input, calls the orchestrator, and records AI metadata for future turns.
  • openai_processing.py and perplexity_processing.py build strictly supported API payloads (GPT-5 ignores temperature, Sonar-Pro sampling is managed server-side).

Discord User Experience

  • discord_embeds.py formats Perplexity citations into clean embeds with automatic suppression when multiple links exist.
  • message_splitter.py enforces Discord limits (2000 / 3840 / 4096 chars) with code-block and citation awareness.
  • message_router.py centralizes mention handling, DM routing, and rate-limit responses.

Reliability & Ops

  • connection_pool.py exposes tuned HTTP/2 clients (50/10 connections for OpenAI, 30/5 for Perplexity).
  • health_checks.py verifies API reachability and validates GPT-5/Sonar configurations at startup.
  • api_validation.py + api_utils.py guard against unsupported model strings and capture structured error metadata.

Documentation Map

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

Development Workflow

# 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.py

Use 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.

Security Checklist

  • Keep config.ini out of version control; copy from config.ini.example and set chmod 600 config.ini on 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_PER accordingly.

Support & License

About

An Opensource AI bot that uses GPT models to provide chat-based interactions with users in Discord channels and via DMs. Supports a hybrid mode with OpenAI and Perplexity API backends!

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors

Languages