π DialogChain is a powerful 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.
pip install dialogchain
git clone https://github.com/dialogchain/python
cd python
poetry install
config.yaml:version: "1.0"
pipeline:
- name: greeting
type: python
module: dialogchain.processors.basic
class: GreetingProcessor
config:
default_name: "User"
dialogchain serve config.yaml
curl -X POST http://localhost:8000/process -H "Content-Type: application/json" -d '{"text": "Hello!"}'
For detailed documentation, please visit our documentation site.
DialogChain includes a robust logging system with the following features:
from dialogchain.utils.logger import setup_logger, get_logs
# Get a logger instance
logger = setup_logger(__name__, log_level='DEBUG')
# Log messages with different levels
logger.debug('Debug message')
logger.info('Information message')
logger.warning('Warning message')
logger.error('Error message', extra={'error_code': 500})
# Get recent logs from database
recent_logs = get_logs(limit=10)
DialogChain provides several make commands for log management:
# View recent logs (default: 50 lines)
make logs
# View specific number of log lines
make logs LINES=100
# Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
make log-level LEVEL=DEBUG
# View database logs
make log-db LIMIT=50
# Follow log file in real-time
make log-tail
# Clear log files
make log-clear
Logging can be configured via environment variables:
# Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
LOG_LEVEL=DEBUG
# Log file path
LOG_FILE=logs/dialogchain.log
# Database log file path
DB_LOG_FILE=logs/dialogchain.db
Log files are automatically rotated when they reach 10MB, keeping up to 5 backup files.
dialogchain/
βββ src/
β βββ dialogchain/
β βββ __init__.py
β βββ engine.py # Core processing engine
β βββ processors/ # Built-in processors
β βββ connectors/ # I/O connectors
β βββ utils/ # Utility functions
βββ tests/ # Test suite
βββ examples/ # Example configurations
βββ docs/ # Documentation
Run the complete test suite:
make test
Run specific test types:
# Unit tests
make test-unit
# Integration tests
make test-integration
# End-to-end tests
make test-e2e
Generate test coverage report:
make coverage
We welcome contributions! Please see our Contributing Guidelines for details.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
For support, please open an issue in the GitHub repository.
DialogChain includes a comprehensive test suite to ensure code quality and functionality. Hereβs how to run the tests and view logs:
Run the complete test suite:
make test
Or run specific test types:
# Unit tests
make test-unit
# Integration tests
make test-integration
# End-to-end tests
make test-e2e
Generate a coverage report to see which parts of your code are being tested:
make coverage
This will generate an HTML report in the htmlcov directory.
View the most recent logs from your application:
# Show last 50 lines from all log files
make logs
# Show a different number of lines
make logs LINES=100
# Specify a custom log directory
make logs LOG_DIR=/path/to/logs
Ensure your code follows the projectβs style guidelines:
# Run linters
make lint
# Automatically format your code
make format
# Check types
make typecheck
You can also run tests in a Docker container:
# Build the Docker image
docker build -t dialogchain .
# Run tests in the container
docker run --rm dialogchain make test
DialogChain includes powerful network scanning capabilities to discover devices like cameras and printers on your local network.
Scan your local network for various devices and services:
make scan-network
Find RTSP cameras on your network:
make scan-cameras
List all available printers on your system:
make scan-printers
Send a test page to your default printer:
make print-test
You can also use the network scanner directly in your Python code:
from dialogchain.scanner import NetworkScanner
import asyncio
async def scan_network():
scanner = NetworkScanner()
# Scan for all services
services = await scanner.scan_network()
# Or scan for specific service types
cameras = await scanner.scan_network(service_types=['rtsp'])
for service in services:
print(f"{service.ip}:{service.port} - {service.service} ({service.banner})")
# Run the scan
asyncio.run(scan_network())
DialogChain includes basic printing capabilities using the CUPS (Common Unix Printing System) interface.
import cups
def print_text(text, printer_name=None):
conn = cups.Connection()
printers = conn.getPrinters()
if not printers:
print("No printers available")
return
printer = printer_name or list(printers.keys())[0]
job_id = conn.printFile(printer, "/dev/stdin", "DialogChain Print", {"raw": "True"}, text)
print(f"Sent print job {job_id} to {printer}")
# Example usage
print_text("Hello from DialogChain!")
def print_file(file_path, printer_name=None):
conn = cups.Connection()
printers = conn.getPrinters()
if not printers:
print("No printers available")
return
printer = printer_name or list(printers.keys())[0]
job_id = conn.printFile(printer, file_path, "Document Print", {})
print(f"Sent print job {job_id} to {printer}")
# Example usage
print_file("document.pdf")
git clone https://github.com/dialogchain/python.git
cd python
poetry install
poetry shell
poetry install --with dev,test
pre-commit install
make test
Or with coverage report:
make coverage
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
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
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
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
poetry run dialogchain -c config.yaml
This project uses:
# 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
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββ
β 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 β
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββ
# Clone repository
git clone https://github.com/dialogchain/python
cd python
# Install dependencies
poetry install
# Run the application
poetry run dialogchain --help
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
Generate a configuration template:
dialogchain init --template camera --output my_config.yaml
Example route (simplified YAML):
routes:
- name: "smart_security_camera"
from: "rtsp://:@/stream1"
processors:
# Python: Object detection
- type: "external"
command: "python scripts/detect_objects.py"
config:
confidence_threshold: 0.6
target_objects: ["person", "car"]
# Filter high-risk only
- type: "filter"
condition: " == 'high'"
to:
- "smtp://:?user=&password=&to="
- "http://webhook.company.com/security-alert"
Run all routes
dialogchain run -c my_config.yaml
Run specific route
dialogchain run -c my_config.yaml --route smart_dialog_flow
Dry run to see what would execute
dialogchain run -c my_config.yaml --dry-run
dialogchain run -c my_config.yaml --dry-run
π DRY RUN - Configuration Analysis:
==================================================
π Route: front_door_camera
From: rtsp://:@/stream1
Processors:
1. external
Command: python -m ultralytics_processor
2. filter
3. transform
To:
β’ smtp://:?user=&password=&to=
| 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 |
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"
processors:
# Filter messages
- type: "filter"
condition: " > 0.7"
# Transform output
- type: "transform"
template: "Alert: detected at "
# Aggregate over time
- type: "aggregate"
strategy: "collect"
timeout: "5m"
max_size: 100
| Destination | Example URL | Description |
|---|---|---|
smtp://smtp.gmail.com:587?user=&password=&to= |
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 |
dialogchain/
βββ dialogchain/ # 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
β βββ 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
# Build all processors
make build-all
# Build specific language
make build-go
make build-rust
make build-cpp
# Install dependencies
make install-deps
# Development environment
make dev
# Run tests
make test
# Lint code
make lint
# Build distribution
make build
# Build image
make docker
# Run with Docker
docker run -it --rm \
-v $(PWD)/examples:/app/examples \
-v $(PWD)/.env:/app/.env \
dialogchain:latest
# Or use Make
make docker-run
version: "3.8"
services:
dialogchain:
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"
# Deploy to Kubernetes
make deploy-k8s
# Or manually
kubectl apply -f k8s/
# Check status
kubectl get pods -n dialogchain
# View logs
kubectl logs -f deployment/dialogchain -n dialogchain
Features in Kubernetes:
# Health check endpoint
curl http://localhost:8080/health
# Metrics endpoint (Prometheus format)
curl http://localhost:8080/metrics
# Runtime statistics
curl http://localhost:8080/stats
# View real-time logs
make logs
# Start monitoring dashboard
make monitor
# Run benchmarks
make benchmark
# 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=dialogchain
MQTT_PASS=secret
# Advanced settings
MAX_CONCURRENT_ROUTES=10
DEFAULT_TIMEOUT=30
LOG_LEVEL=info
METRICS_ENABLED=true
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
# 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
# Test processor manually
echo '{"test": "data"}' | python scripts/detect_objects.py --input /dev/stdin
# Check dependencies
which go python node cargo
# View processor logs
dialogchain run -c config.yaml --verbose
# Monitor resource usage
htop
# Check route performance
make benchmark
# Optimize configuration
# - Reduce frame processing rate
# - Increase batch sizes
# - Use async processors
# Enable verbose logging
dialogchain run -c config.yaml --verbose
# Dry run to test configuration
dialogchain run -c config.yaml --dry-run
# Validate configuration
dialogchain validate -c config.yaml
git checkout -b feature/amazing-featuremake dev-workflowgit commit -m 'Add amazing feature'git push origin feature/amazing-feature```bash
git clone https://github.com/dialogchain/python cd python make dev
make test
For questions or support, please open an issue in the issue tracker.
Built with β€οΈ for the ML and multimedia processing community
| β Star us on GitHub | π Documentation | π¬ Community |