How owais-kamdar/mistral-chat works
Project Type and Purpose
• This is a full-stack, local Q&A chatbot system with two “frontends”:
a) A command-line chat interface (main.py)
b) A Streamlit-based dashboard (dashboard.py)
• It orchestrates local inference against a self-hosted Mistral 7B model, performs document processing, captures metrics, persists logs, and visualizes them.
Core Components
a. User Interfaces (Frontends)
• CLI Chat (main.py): Read/write loop, upload PDF/TXT, commands (exit, clear, stats)
• Dashboard (dashboard.py): Streamlit app showing plots (Plotly+Pandas) of logged metrics
b. Backend Services
• Pipeline (pipeline.py): Orchestrates end-to-end flow: document enrichment, LLM calls, fallback/error handling
• Document Processor (document_processor.py): PDF/TXT parsing (PyPDF2), text chunking, embedding (sentence-transformers), semantic retrieval
• LLM Interface (llm.py): HTTP client to local Mistral model server (requests)
• System Monitor (system_monitor.py): psutil-based decorators for response time, memory, char counts, errors, session stats
• Logger (logger.py): File-based logging via loguru, writes to logs/app.log, metrics_*.jsonl, summary_*.json
• Utils (utils.py): Retry with exponential backoff
• Config (config.py): Centralized parameters (paths, LLM settings, doc-chunk sizes, retry policy)
c. Data Stores
• uploads/: Raw user documents (PDF/TXT)
• logs/:
• app.log (general events)
• metrics_*.jsonl (per-session granular records)
• summary_*.json (session summaries)
d. External Service
Interactions and Data Flows
1) User ➔ CLI Chat
• Uploads file ➔ stored in uploads/
• Enters query ➔ main.py
2) main.py ➔ Pipeline
• Passes user input + history
3) Pipeline ➔ Document Processor
• If document query, returns context chunks + embeddings
4) Pipeline ➔ LLM Interface
• Builds prompt with context + user query
• Requests generation via HTTP POST
5) System Monitor (decorators) wrap Pipeline & LLM calls
• Emits metrics (response time, memory, counts, errors)
6) Logger
• Receives events & metrics ➔ writes to logs/
7) Session continues or terminates
8) Dashboard reads logs/
• Builds Pandas DataFrame, uses Plotly to render time series, histograms
• Provides filtering by session timestamp
Architectural Patterns & Principles
• Modular single-responsibility components (each .py has one domain)
• Orchestration layer (pipeline.py) separates control flow from implementation
• Decorator-based instrumentation (system_monitor) for non-intrusive metrics
• Configuration centralization (config.py) for easy parameter tuning
• File‐based persistence for simplicity (no external DB)
• Retry/exponential backoff (utils.py) for resilience