An AI-powered conversational assistant and economic event analyzer. This system combines real-time data scraping pipelines (covering forex, cryptocurrencies, metals, and energy) with state-of-the-art Large Language Models (LLMs) to deliver structured, action-oriented financial analysis directly to traders and investors.
- Intelligent Intent Parsing (NLU): Leverages LLM function calling (or raw structured output) to determine if a query requires economic calendar data. Routes automatically between conversational chat and targeted data scraping.
- Decoupled Scraping Client: Fully integrated with the decoupled
ForexFactoryScrapperbundle API supporting multi-source querying (forex,crypto,metal,energy). - Pydantic Structured Outputs: Guarantees JSON schema compliance for LLM analysis, eliminating raw text hallucination risks and securing downstream parsing.
- Flexible LLM Provider Engine: Fully abstract provider layer allows seamless switching between:
- Local Inference: Self-hosted Ollama (e.g.
Qwen,Llama,Mistral). - Cloud Inference: Groq API (superfast inference) or OpenAI API (
GPT-4).
- Local Inference: Self-hosted Ollama (e.g.
- Calibrated Volatility Analytics: Provides traders with market sentiment (
bullish,bearish,neutral), trading implications, confidence levels, key event priorities, and macroeconomic summaries. - Robust Date Range Validation: Validates natural dates (e.g., "today", "yesterday", "last week Wednesday") and clamps query limits to a maximum of 7 days to prevent rate limits and performance bottlenecks.
- Aesthetic Swagger UI & Interactive Chat: Provides beautiful built-in Swagger specification endpoints (
/swagger) and a premium web-based glassmorphism chat UI (/).
The system adheres strictly to decoupled, clean-code architecture principles:
βββ main.py # Application launcher
βββ requirements.txt # Package dependencies
βββ src/
β βββ app.py # Flask server setup, CORS & Blueprints
β βββ openapi_spec.py # OpenAPI specification schemas
β βββ middleware.py # Lifecycle handlers (correlation ID propagation)
β βββ client/
β β βββ schemas.py # Scrapper API models (Pydantic)
β β βββ scrapper_api_client.py # HTTPX client for the scraping engine
β βββ ai/
β β βββ ai_constants.py # AI system limits, supported languages, fallback configs
β β βββ ai_utils.py # System prompt rendering & structured output parsers
β β βββ exceptions.py # Domain-specific NLU exceptions
β β βββ intent_parser.py# NLU orchestrator facade
β β βββ analyzer.py # Analysis engine orchestrator facade
β β βββ prompts/ # Jinja2-templated prompts
β β βββ intent/ # Rule-based fallback parser & function specifications
β β βββ providers/ # LLM provider implementations (Ollama, Groq, OpenAI)
β βββ routes/
β β βββ ai_routes.py # AI analyze & NLU chat controllers
β β βββ swagger_routes.py # Swagger UI endpoint & specification delivery
β β βββ root_routes.py # Interactive Chat UI view
β βββ templates/
β βββ chat.html # Premium glassmorphic chat front-end
βββ tests/ # Robust Pytest suite
Copy the example environment file and customize it for your setup:
cp .env.example .envMake sure Ollama is running locally, then pull a fast multilingual model:
ollama pull qwen:7bConfigure your .env:
LLM_PROVIDER=ollama
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=qwen:7bObtain an API key from the Groq Console:
LLM_PROVIDER=groq
GROQ_API_KEY=gsk_your_groq_api_key
GROQ_MODEL=mixtral-8x7b-32768Obtain an API key from the OpenAI Platform:
LLM_PROVIDER=openai
OPENAI_API_KEY=sk-proj-your_openai_api_key
OPENAI_MODEL=gpt-4-turbo-previewThis application acts as a decoupled NLU intelligence layer and requires the backend scraper engine to be running as a separate service.
You must set up and run the following repository: π ForexFactoryScrapper Engine
- Clone and install the scraper repository on your local system or server.
- Run the scraper engine on its designated port (typically
http://127.0.0.1:5000or customized). - Provide the scraper API base URL in this project's
.envconfiguration file via theFF_SCRAPPER_API_BASE_URLparameter:FF_SCRAPPER_API_BASE_URL=http://127.0.0.1:5000
Create and activate a python virtual environment, then install dependencies:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtRun the Flask server:
python main.pyThe server will boot by default on http://127.0.0.1:8080.
- Interactive Web Chat UI: Navigate to
http://127.0.0.1:8080/ - Swagger API Docs: Navigate to
http://127.0.0.1:8080/swagger - Raw OpenAPI Spec: Navigate to
http://127.0.0.1:8080/openapi.json
- Path:
POST /api/ai/analyze - Description: Sends raw events to the LLM to get structured volatility summaries.
- Request Body:
{ "events": [ { "ID": "123", "Time": "2026-05-21 14:30:00", "Currency": "USD", "Event": "Non-Farm Payrolls", "Forecast": "150k", "Actual": "145k", "Previous": "140k", "Impact": "high" } ], "language": "tr", "focus": "trading", "example_count": 0, "response_style": "detailed" } - Response Wrapper (200 OK):
{ "reply": "Institutional high-level macro summary of the events...", "analysis": { "summary": "High-level summary for investors...", "analyses": [ { "event_name": "Non-Farm Payrolls", "currency": "USD", "time": "2026-05-21 14:30:00", "expectation_vs_previous": "Missed forecast...", "actual_vs_expectation": "Negative implication...", "market_implication": "USD under pressure...", "sentiment": "bearish", "confidence": "high" } ], "overall_sentiment": "bearish", "key_events": ["Non-Farm Payrolls"], "risk_level": "medium" }, "provider": "GroqProvider", "analysis_request": { ... } }
- Path:
POST /api/ai/chat - Description: Analyzes natural query text, fetches relevant market data if needed, and replies.
- Request Body:
{ "message": "GeΓ§en hafta ΓarΕamba gΓΌnΓΌ Forex'te ne oldu?", "focus": "macro", "response_style": "concise" }
We maintain a high-coverage unit and integration test suite targeting utilities, schema validation, LLM providers, and controllers.
To execute tests with proper path resolution, run:
PYTHONPATH=. .venv/bin/pytest -vTo launch the app with a companion containerized local Ollama server, use docker-compose:
docker-compose up --buildThis starts both the Flask application and the Ollama instance in the same virtual network, allowing secure, fast local inference.
This project is licensed under the MIT License. See the LICENSE file for details.
