Kryten LLM integration service - provides AI chat responses and interactions
Project description
Kryten LLM
AI-powered chat bot service for CyTube, part of the Kryten ecosystem.
Features
- Trigger-Based Responses: Configurable trigger words with probabilities
- Direct Mentions: Responds when mentioned by name
- LLM Integration: Multiple LLM provider support (OpenAI, OpenRouter, local)
- Rate Limiting: Per-user, per-trigger, and global rate limits
- Spam Detection: Automatic spam detection with exponential backoff penalties
- Context Awareness: Tracks chat history and video context
- Hot-Reload: Reload configuration without restart (SIGHUP)
- Service Discovery: Publishes heartbeats and responds to discovery polls
- Dry-Run Mode: Test responses without sending to chat
Requirements
- Python 3.10+
- Poetry
- NATS server
- kryten-py library
Installation
Using Poetry
# Install dependencies
poetry install
# Copy example configuration
cp config.example.json config.json
# Edit configuration with your settings
# See config.example.json for all options
Using pip
pip install kryten-llm
Configuration
Configuration is stored in a JSON file. See config.example.json for a complete example.
Key Sections
| Section | Description |
|---|---|
nats |
NATS connection settings |
channels |
CyTube channel connections |
personality |
Bot character and behavior |
llm_providers |
LLM API configurations |
triggers |
Trigger words with patterns and probabilities |
rate_limits |
Rate limiting rules |
spam_detection |
Spam detection settings |
testing |
Dry-run and logging options |
Environment Variables
Override configuration with environment variables:
export OPENROUTER_API_KEY="your-api-key"
export KRYTEN_LLM_DRY_RUN="true"
Usage
Running the Service
# Using Poetry
poetry run kryten-llm --config config.json
# Direct Python execution
python -m kryten_llm --config config.json
Command Line Options
| Option | Description |
|---|---|
--config PATH |
Path to configuration file (default: config.json) |
--log-level LEVEL |
Logging level: DEBUG, INFO, WARNING, ERROR |
--dry-run |
Generate responses but don't send to chat |
--validate-config |
Validate configuration and exit |
Validation Mode
Validate your configuration without starting the service:
poetry run kryten-llm --config config.json --validate-config
Dry-Run Mode
Test responses without sending to chat:
poetry run kryten-llm --config config.json --dry-run
Hot-Reload (POSIX)
Reload configuration without restarting the service:
# Send SIGHUP to reload configuration
kill -HUP $(pgrep -f kryten_llm)
Safe changes that can be hot-reloaded:
- Triggers (patterns, probabilities, enabled status)
- Rate limits
- Spam detection settings
- Personality configuration
- LLM provider settings
Unsafe changes (require restart):
- NATS connection settings
- Channel configuration
- Service name
Production Deployment
Systemd Service
Install the systemd service file:
# Copy service file
sudo cp kryten-llm.service /etc/systemd/system/
# Create config directory
sudo mkdir -p /etc/kryten-llm
sudo cp config.json /etc/kryten-llm/
# Create log directory
sudo mkdir -p /var/log/kryten-llm
sudo chown kryten:kryten /var/log/kryten-llm
# Enable and start service
sudo systemctl daemon-reload
sudo systemctl enable kryten-llm
sudo systemctl start kryten-llm
Service Management
# Check status
sudo systemctl status kryten-llm
# View logs
sudo journalctl -u kryten-llm -f
# Reload configuration
sudo systemctl reload kryten-llm
# Restart service
sudo systemctl restart kryten-llm
Development
Running Tests
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov=kryten_llm
# Run specific test file
poetry run pytest tests/test_trigger_engine.py -v
Code Quality
# Linting
poetry run ruff check .
# Formatting
poetry run black .
# Type checking
poetry run mypy kryten_llm
Architecture
The service processes messages through a pipeline:
Chat Message
↓
MessageListener (parse/filter)
↓
TriggerEngine (detect triggers/mentions)
↓
RateLimiter (check rate limits)
↓
SpamDetector (check spam)
↓
ContextManager (gather context)
↓
PromptBuilder (build LLM prompt)
↓
LLMManager (call LLM API)
↓
ResponseValidator (validate response)
↓
ResponseFormatter (format for chat)
↓
Send to Chat
Service Discovery
The service publishes:
- Startup event: When service starts
- Heartbeat: Every 30s with health status
- Shutdown event: When service stops gracefully
Subscribe to service events:
kryten.lifecycle.llm.startupkryten.heartbeat.llmkryten.lifecycle.llm.shutdown
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kryten_llm-0.2.4.tar.gz.
File metadata
- Download URL: kryten_llm-0.2.4.tar.gz
- Upload date:
- Size: 44.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.11 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad383ede3aa4af7dfc5dc8f0b10cc7eb3a7edfc0e631567081644fb0f92bb2b2
|
|
| MD5 |
e84679c5c8ab8a06796071bfa9638e73
|
|
| BLAKE2b-256 |
0efbb6a7280292f66bc11286ec5c8a7b6040e9fd593c9df037693801d6465ea5
|
File details
Details for the file kryten_llm-0.2.4-py3-none-any.whl.
File metadata
- Download URL: kryten_llm-0.2.4-py3-none-any.whl
- Upload date:
- Size: 53.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.11 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bf5919622d9857d6b4042186ad7667f15f5c30e730f21229764bc6eb7a7d961
|
|
| MD5 |
510b91a454c890ed844ad6d2cc640bc2
|
|
| BLAKE2b-256 |
31f22a682b1beb6a19013b65a42631ee4192d8f540a0a9203c3c04e990218445
|