DialogChain - A flexible and extensible dialog processing framework
Project description
DialogChain - Flexible Dialog Processing Framework
๐ DialogChain is a flexible and extensible framework for building, managing, and deploying dialog systems and conversational AI applications. It supports multiple programming languages and integrates with various NLP and ML models.
๐ฆ Installation
Prerequisites
- Python 3.8+
- Poetry
Install with Poetry
-
Clone the repository:
git clone https://github.com/dialogchain/python.git cd python
-
Install dependencies:
poetry install -
Activate the virtual environment:
poetry shell
Development Setup
-
Install development and test dependencies:
poetry install --with dev,test
-
Set up pre-commit hooks:
pre-commit install -
Run tests:
make test
Or with coverage report:
make coverage
๐๏ธ Project Structure
dialogchain/
โโโ src/
โ โโโ dialogchain/ # Main package
โ โโโ __init__.py
โ โโโ cli.py # Command-line interface
โ โโโ config.py # Configuration handling
โ โโโ connectors/ # Connector implementations
โ โโโ engine.py # Core engine
โ โโโ exceptions.py # Custom exceptions
โ โโโ processors/ # Processor implementations
โ โโโ utils.py # Utility functions
โโโ tests/ # Test files
โ โโโ unit/ # Unit tests
โ โ โโโ core/ # Core functionality tests
โ โ โโโ connectors/ # Connector tests
โ โ โโโ ...
โ โโโ integration/ # Integration tests
โโโ .github/ # GitHub workflows
โโโ docs/ # Documentation
โโโ .gitignore
โโโ .pre-commit-config.yaml
โโโ Makefile # Common development commands
โโโ pyproject.toml # Project metadata and dependencies
โโโ README.md
๐งช Testing
Run the full test suite:
make test
Run specific test categories:
# Unit tests
make test-unit
# Integration tests
make test-integration
# With coverage report
make coverage
๐งน Code Quality
Format and check code style:
make format # Auto-format code
make lint # Run linters
make typecheck # Run type checking
make check-all # Run all checks
๐ Quick Start
-
Create a configuration file
config.yaml:version: 1.0 pipelines: - name: basic_dialog steps: - type: input name: user_input source: console - type: processor name: nlp_processor module: dialogchain.processors.nlp function: process_text - type: output name: response target: console
-
Run the dialog chain:
poetry run dialogchain -c config.yaml
โจ Features
- ๐ฌ Dialog Management: Stateful conversation handling and context management
- ๐ค Multi-Language Support: Python, Go, Rust, C++, Node.js processors
- ๐ Flexible Connectors: REST APIs, WebSockets, gRPC, MQTT, and more
- ๐ง ML/NLP Integration: Built-in support for popular NLP libraries and models
- โ๏ธ Simple Configuration: YAML/JSON configuration with environment variables
- ๐ณ Cloud Native: Docker, Kubernetes, and serverless deployment ready
- ๐ Production Ready: Monitoring, logging, and error handling
- ๐งช Comprehensive Testing: Unit, integration, and end-to-end tests
- ๐ Code Quality: Type hints, linting, and code formatting
- ๐ Scalable: Horizontal scaling for high-throughput applications
๐ ๏ธ Development
Code Style
This project uses:
Development Commands
# Run tests with coverage
poetry run pytest --cov=dialogchain --cov-report=term-missing
# Format code
poetry run black .
poetry run isort .
# Lint code
poetry run flake8
# Type checking
poetry run mypy dialogchain
๐๏ธ Architecture
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Inputs โ โ Processors โ โ Outputs โ
โโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโค
โ HTTP API โโโโโบโ NLP Processing โโโโโบโ REST API โ
โ WebSocket โ โ Intent Detection โ โ WebSocket โ
โ gRPC โ โ Entity Extractionโ โ gRPC โ
โ CLI โ โ Dialog Managementโ โ Message Bus โ
โ Message Bus โ โ Response Gen โ โ Logging โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
๐ Quick Start
1. Installation
# Clone repository
git clone https://github.com/taskinity/dialogchain
cd dialogchain
# Install dependencies
poetry install
# Run the application
poetry run dialogchain --help
2. Configuration
Create your .env file:
# Copy template and edit
cp .env.example .env
Example .env:
CAMERA_USER=admin
CAMERA_PASS=your_password
CAMERA_IP=192.168.1.100
SMTP_USER=alerts@company.com
SMTP_PASS=app_password
SECURITY_EMAIL=security@company.com
3. Create Routes
Generate a configuration template:
camel-router init --template camera --output my_routes.yaml
Example route (simplified YAML):
routes:
- name: "smart_security_camera"
from: "rtsp://{{CAMERA_USER}}:{{CAMERA_PASS}}@{{CAMERA_IP}}/stream1"
processors:
# Python: Object detection
- type: "external"
command: "python scripts/detect_objects.py"
config:
confidence_threshold: 0.6
target_objects: ["person", "car"]
# Go: Risk analysis
- type: "external"
command: "go run scripts/image_processor.go"
config:
threat_threshold: 0.7
# Filter high-risk only
- type: "filter"
condition: "{{threat_level}} == 'high'"
to:
- "email://{{SMTP_SERVER}}:{{SMTP_PORT}}?user={{SMTP_USER}}&password={{SMTP_PASS}}&to={{SECURITY_EMAIL}}"
- "http://webhook.company.com/security-alert"
4. Run
# Run all routes
camel-router run -c my_routes.yaml
# Run specific route
camel-router run -c my_routes.yaml --route smart_security_camera
# Dry run to see what would execute
camel-router run -c my_routes.yaml --dry-run
๐ Detailed Usage
Sources (Input)
| Source | Example URL | Description |
|---|---|---|
| RTSP Camera | rtsp://user:pass@ip/stream1 |
Live video streams |
| Timer | timer://5m |
Scheduled execution |
| File | file:///path/to/watch |
File monitoring |
| gRPC | grpc://localhost:50051/Service/Method |
gRPC endpoints |
| MQTT | mqtt://broker:1883/topic |
MQTT messages |
Processors (Transform)
External Processors
Delegate to any programming language:
processors:
# Python ML inference
- type: "external"
command: "python scripts/detect_objects.py"
input_format: "json"
output_format: "json"
config:
model: "yolov8n.pt"
confidence_threshold: 0.6
# Go image processing
- type: "external"
command: "go run scripts/image_processor.go"
config:
thread_count: 4
optimization: "speed"
# Rust performance-critical tasks
- type: "external"
command: "cargo run --bin data_processor"
config:
batch_size: 32
simd_enabled: true
# C++ optimized algorithms
- type: "external"
command: "./bin/cpp_postprocessor"
config:
algorithm: "fast_nms"
threshold: 0.85
# Node.js business logic
- type: "external"
command: "node scripts/business_rules.js"
config:
rules_file: "security_rules.json"
Built-in Processors
processors:
# Filter messages
- type: "filter"
condition: "{{confidence}} > 0.7"
# Transform output
- type: "transform"
template: "Alert: {{object_type}} detected at {{position}}"
# Aggregate over time
- type: "aggregate"
strategy: "collect"
timeout: "5m"
max_size: 100
Destinations (Output)
| Destination | Example URL | Description |
|---|---|---|
email://smtp.gmail.com:587?user={{USER}}&password={{PASS}}&to={{EMAILS}} |
SMTP alerts | |
| HTTP | http://api.company.com/webhook |
REST API calls |
| MQTT | mqtt://broker:1883/alerts/camera |
MQTT publishing |
| File | file:///logs/alerts.log |
File logging |
| gRPC | grpc://service:50051/AlertService/Send |
gRPC calls |
๐ ๏ธ Development
Project Structure
camel-router/
โโโ camel_router/ # Python package
โ โโโ cli.py # Command line interface
โ โโโ engine.py # Main routing engine
โ โโโ processors.py # Processing components
โ โโโ connectors.py # Input/output connectors
โโโ scripts/ # External processors
โ โโโ detect_objects.py # Python: YOLO detection
โ โโโ image_processor.go # Go: Risk analysis
โ โโโ health_check.go # Go: Health monitoring
โ โโโ business_rules.js # Node.js: Business logic
โโโ examples/ # Configuration examples
โ โโโ simple_routes.yaml # Sample routes
โโโ k8s/ # Kubernetes deployment
โ โโโ deployment.yaml # K8s manifests
โโโ Dockerfile # Container definition
โโโ Makefile # Build automation
โโโ README.md # This file
Building External Processors
# Build all processors
make build-all
# Build specific language
make build-go
make build-rust
make build-cpp
# Install dependencies
make install-deps
Development Workflow
# Development environment
make dev
# Run tests
make test
# Lint code
make lint
# Build distribution
make build
๐ณ Docker Deployment
Build and Run
# Build image
make docker
# Run with Docker
docker run -it --rm \
-v $(PWD)/examples:/app/examples \
-v $(PWD)/.env:/app/.env \
camel-router:latest
# Or use Make
make docker-run
Docker Compose (with dependencies)
version: "3.8"
services:
camel-router:
build: .
environment:
- CAMERA_IP=192.168.1.100
- MQTT_BROKER=mqtt
volumes:
- ./examples:/app/examples
- ./logs:/app/logs
depends_on:
- mqtt
- redis
mqtt:
image: eclipse-mosquitto:2
ports:
- "1883:1883"
redis:
image: redis:7-alpine
ports:
- "6379:6379"
โธ๏ธ Kubernetes Deployment
# Deploy to Kubernetes
make deploy-k8s
# Or manually
kubectl apply -f k8s/
# Check status
kubectl get pods -n camel-router
# View logs
kubectl logs -f deployment/camel-router -n camel-router
Features in Kubernetes:
- Horizontal Pod Autoscaling: Auto-scale based on CPU/memory/custom metrics
- Resource Management: CPU/memory limits and requests
- Health Checks: Liveness and readiness probes
- Persistent Storage: Shared volumes for model files and logs
- Service Discovery: Internal service communication
- Monitoring: Prometheus metrics integration
๐ Monitoring and Observability
Built-in Metrics
# Health check endpoint
curl http://localhost:8080/health
# Metrics endpoint (Prometheus format)
curl http://localhost:8080/metrics
# Runtime statistics
curl http://localhost:8080/stats
Logging
# View real-time logs
make logs
# Start monitoring dashboard
make monitor
Performance Benchmarking
# Run benchmarks
make benchmark
๐ง Configuration Reference
Environment Variables
# Camera settings
CAMERA_USER=admin
CAMERA_PASS=password
CAMERA_IP=192.168.1.100
CAMERA_NAME=front_door
# Email settings
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=alerts@company.com
SMTP_PASS=app_password
SECURITY_EMAIL=security@company.com
# Service URLs
WEBHOOK_URL=https://hooks.company.com
ML_GRPC_SERVER=localhost:50051
DASHBOARD_URL=https://dashboard.company.com
# MQTT settings
MQTT_BROKER=localhost
MQTT_PORT=1883
MQTT_USER=camel_router
MQTT_PASS=secret
# Advanced settings
MAX_CONCURRENT_ROUTES=10
DEFAULT_TIMEOUT=30
LOG_LEVEL=info
METRICS_ENABLED=true
Route Configuration Schema
routes:
- name: "route_name" # Required: Route identifier
from: "source_uri" # Required: Input source
processors: # Optional: Processing pipeline
- type: "processor_type"
config: {}
to: ["destination_uri"] # Required: Output destinations
# Global settings
settings:
max_concurrent_routes: 10
default_timeout: 30
log_level: "info"
metrics_enabled: true
health_check_port: 8080
# Required environment variables
env_vars:
- CAMERA_USER
- SMTP_PASS
๐ฏ Use Cases
1. Smart Security System
- Input: RTSP cameras, motion sensors
- Processing: Python (YOLO), Go (risk analysis), Node.js (rules)
- Output: Email alerts, mobile push, dashboard
2. Industrial Quality Control
- Input: Factory cameras, sensor data
- Processing: Python (defect detection), C++ (performance), Rust (safety)
- Output: MQTT control, database, operator alerts
3. IoT Data Pipeline
- Input: MQTT sensors, HTTP APIs
- Processing: Go (aggregation), Python (analytics), Node.js (business logic)
- Output: Time-series DB, real-time dashboard, alerts
4. Media Processing Pipeline
- Input: File uploads, streaming video
- Processing: Python (ML inference), C++ (codec), Rust (optimization)
- Output: CDN upload, metadata database, webhooks
๐ Troubleshooting
Common Issues
Camera Connection Failed
# Test RTSP connection
ffmpeg -i rtsp://user:pass@ip/stream1 -frames:v 1 test.jpg
# Check network connectivity
ping camera_ip
telnet camera_ip 554
External Processor Errors
# Test processor manually
echo '{"test": "data"}' | python scripts/detect_objects.py --input /dev/stdin
# Check dependencies
which go python node cargo
# View processor logs
camel-router run -c config.yaml --verbose
Performance Issues
# Monitor resource usage
htop
# Check route performance
make benchmark
# Optimize configuration
# - Reduce frame processing rate
# - Increase batch sizes
# - Use async processors
Debug Mode
# Enable verbose logging
camel-router run -c config.yaml --verbose
# Dry run to test configuration
camel-router run -c config.yaml --dry-run
# Validate configuration
camel-router validate -c config.yaml
๐ค Contributing
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Make changes and add tests
- Run checks:
make dev-workflow - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
Development Setup
# Clone and setup
git clone https://github.com/taskinity/camel-router
cd camel-router
make dev
# Run tests
make test
For questions or support, please open an issue in the [issue tracker](https://github.com/taskinity/dialogchain/issues).
## ๐ Related Projects
- **[Apache Camel](https://camel.apache.org/)**: Original enterprise integration framework
- **[GStreamer](https://gstreamer.freedesktop.org/)**: Multimedia framework
- **[Apache NiFi](https://nifi.apache.org/)**: Data flow automation
- **[Kubeflow](https://kubeflow.org/)**: ML workflows on Kubernetes
- **[TensorFlow Serving](https://tensorflow.org/tfx/serving)**: ML model serving
## ๐ก Roadmap
- [ ] **Web UI**: Visual route designer and monitoring dashboard
- [ ] **More Connectors**: Database, cloud storage, message queues
- [ ] **Model Registry**: Integration with MLflow, DVC
- [ ] **Stream Processing**: Apache Kafka, Apache Pulsar support
- [ ] **Auto-scaling**: Dynamic processor scaling based on load
- [ ] **Security**: End-to-end encryption, authentication, authorization
- [ ] **Templates**: Pre-built templates for common use cases
---
**Built with โค๏ธ for the ML and multimedia processing community**
[โญ Star us on GitHub](https://github.com/taskinity/camel-router) | [๐ Documentation](https://docs.camel-router.org) | [๐ฌ Community](https://discord.gg/camel-router)
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 dialogchain-0.1.3.tar.gz.
File metadata
- Download URL: dialogchain-0.1.3.tar.gz
- Upload date:
- Size: 32.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.14.6-300.fc42.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4edfb4cf206c6dad7cd53e70b723164778f619521a2198ca263d0470b5fb93ab
|
|
| MD5 |
4772472f1a5a80c70477cb2d85b64b8e
|
|
| BLAKE2b-256 |
1089203676fc38e00ae51fdfa7f5ebc8060dd5c105f73bc3103f82c8e9eb9799
|
File details
Details for the file dialogchain-0.1.3-py3-none-any.whl.
File metadata
- Download URL: dialogchain-0.1.3-py3-none-any.whl
- Upload date:
- Size: 33.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.14.6-300.fc42.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c80232f2e7ee5e788d45b40605de75caafebcc3da2f2649724820c689e5e055
|
|
| MD5 |
06b4ee82bdfc06cb090e572d33dd78a3
|
|
| BLAKE2b-256 |
0a112ffec350d585f2bb6e1407b9d22a55d123c00c211a01777d71cbabeb7b98
|