Skip to main content

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.

Python License: Apache 2.0 Code style: black Imports: isort Tests codecov

๐Ÿ“ฆ Installation

Prerequisites

Install with Poetry

  1. Clone the repository:

    git clone https://github.com/dialogchain/python.git
    cd python
    
  2. Install dependencies:

    poetry install
    
  3. Activate the virtual environment:

    poetry shell
    

Development Setup

  1. Install development and test dependencies:

    poetry install --with dev,test
    
  2. Set up pre-commit hooks:

    pre-commit install
    
  3. 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

  1. 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
    
  2. 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:

  • Black for code formatting
  • isort for import sorting
  • Flake8 for linting
  • mypy for static type checking

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

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Make changes and add tests
  4. Run checks: make dev-workflow
  5. Commit changes: git commit -m 'Add amazing feature'
  6. Push to branch: git push origin feature/amazing-feature
  7. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dialogchain-0.1.3.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dialogchain-0.1.3-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

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

Hashes for dialogchain-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4edfb4cf206c6dad7cd53e70b723164778f619521a2198ca263d0470b5fb93ab
MD5 4772472f1a5a80c70477cb2d85b64b8e
BLAKE2b-256 1089203676fc38e00ae51fdfa7f5ebc8060dd5c105f73bc3103f82c8e9eb9799

See more details on using hashes here.

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

Hashes for dialogchain-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9c80232f2e7ee5e788d45b40605de75caafebcc3da2f2649724820c689e5e055
MD5 06b4ee82bdfc06cb090e572d33dd78a3
BLAKE2b-256 0a112ffec350d585f2bb6e1407b9d22a55d123c00c211a01777d71cbabeb7b98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page