A Temporal-orchestrated backend service for cryptocurrency news analysis using ChatGPT and Perplexity AI.
This service receives cryptocurrency ticker symbols (BTC/ETH/APT), generates analytical questions via ChatGPT, searches for answers using Perplexity AI, formats the results, and delivers them via multiple channels (webhook, email, Slack).
- Workflow Orchestration: Temporal.io (Python SDK)
- AI APIs: OpenAI GPT-4, Perplexity AI
- Database: PostgreSQL (persistence), Redis (caching)
- Containerization: Docker + docker-compose
- Monitoring: Temporal Web UI, structured logging, health checks
- LLM Workflow Service: Main orchestrator handling the analysis workflow
- Activities: Validation, ChatGPT Q-gen, Perplexity search, Formatting, Delivery
- API Service: REST API for API Gateway integration
- Validation: Validate ticker symbol (BTC/ETH/APT)
- Question Generation: Generate 3 analytical questions using ChatGPT
- Answer Search: Get answers for each question via Perplexity AI (parallel)
- Formatting: Format results for different delivery channels
- Delivery: Deliver via webhook/email/Slack with retry logic
- Docker and docker-compose
- OpenAI API key
- Perplexity API key
- Clone the repository and navigate to the crypto-llm-backend directory
- Copy environment configuration:
cp .env.example .env
- Edit
.envwith your API keys and configuration - Start all services:
docker compose up -d
- Temporal Web UI: http://localhost:8080
- API Service: http://localhost:8000
- PostgreSQL: localhost:5432
- Redis: localhost:6379
POST /workflows/start
Content-Type: application/json
{
"ticker": "BTC",
"delivery_type": "webhook",
"delivery_destination": "https://your-api.com/crypto-webhook",
"execution_type": "adhoc",
"metadata": {"priority": "high"}
}GET /workflows/{workflow_id}/statusGET /workflows/{workflow_id}/resultGET /workflows?ticker=BTC&status=completed&limit=10GET /healthGET /metricsTEMPORAL_HOST: Temporal server host (default: localhost:7233)TEMPORAL_NAMESPACE: Temporal namespace (default: default)TEMPORAL_TASK_QUEUE: Task queue name (default: crypto-news-analysis)
OPENAI_API_KEY: Your OpenAI API key (required)PERPLEXITY_API_KEY: Your Perplexity API key (required)
POSTGRES_HOST: PostgreSQL host (default: localhost)POSTGRES_PORT: PostgreSQL port (default: 5432)POSTGRES_DB: Database name (default: crypto_news)POSTGRES_USER: Database user (default: postgres)POSTGRES_PASSWORD: Database password (required)
REDIS_HOST: Redis host (default: localhost)REDIS_PORT: Redis port (default: 6379)REDIS_DB: Redis database number (default: 0)
WEBHOOK_TIMEOUT: Webhook timeout in seconds (default: 30)SLACK_BOT_TOKEN: Slack bot token (optional)SMTP_HOST: SMTP server host (default: smtp.gmail.com)SMTP_PORT: SMTP server port (default: 587)SMTP_USERNAME: SMTP username (optional)SMTP_PASSWORD: SMTP password (optional)
LOG_LEVEL: Logging level (default: INFO)MAX_CONCURRENT_WORKFLOWS: Max concurrent workflows (default: 10)WORKFLOW_TIMEOUT: Workflow timeout in seconds (default: 120)CACHE_TTL_CHATGPT: ChatGPT cache TTL in seconds (default: 86400)CACHE_TTL_PERPLEXITY: Perplexity cache TTL in seconds (default: 3600)
{
"ticker": "BTC",
"delivery_type": "webhook",
"delivery_destination": "https://your-api.com/webhook"
}{
"ticker": "BTC",
"delivery_type": "email",
"delivery_destination": "[email protected]"
}{
"ticker": "BTC",
"delivery_type": "slack",
"delivery_destination": "#crypto-analysis"
}Or via webhook URL:
{
"ticker": "BTC",
"delivery_type": "slack",
"delivery_destination": "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
}- Database connectivity
- Redis cache functionality
- Temporal server connection
- Overall system health
- Workflows started/completed/failed
- Average workflow duration
- Activity execution counts
- Cache hit/miss ratios
- Structured JSON logging
- Workflow and activity tracing
- Error tracking with context
- Workflow Duration: <2 minutes full run
- Concurrent Workflows: 10+ workflows simultaneously
- Success Rate: 99% under normal conditions
- Error Handling: Robust retry policies and circuit breakers
- ChatGPT Questions: 24-hour TTL (questions don't change frequently)
- Perplexity Answers: 1-hour TTL (news updates frequently)
- Rate Limiting: Per-service rate limiting via Redis
-
Start infrastructure:
docker-compose up postgresql redis temporal temporal-ui -d
-
Install dependencies:
pip install -r requirements.txt
-
Run database migrations:
python -c "from core.database import create_tables; create_tables()" -
Start worker:
python worker.py
-
Start API service:
python api_service.py
pytest tests/ -vThe service is designed for container deployment with docker-compose. For production:
- Use environment-specific
.envfiles - Configure proper secrets management
- Set up log aggregation
- Configure monitoring and alerting
- Scale worker instances based on load
- API keys stored in environment variables only
- No secrets logged or committed to repository
- Database credentials secured via environment
- HTTPS required for production deployments
- Input validation on all API endpoints
For issues and questions:
- Check service health at
/healthendpoint - Review logs in the
./logsdirectory - Monitor Temporal Web UI at http://localhost:8080
- Check system metrics at
/metricsendpoint