How theopensi/cosmic works
Main Components
• User Interface & Entry Points:
• Frontend chatbot UI (powered by Open-WebUI, as noted in the README with assets like chatbot_ui.png)
• Demo script (demo.py) and local scripts for initiating the CoSMIC pipeline (local_run.sh, docker_run.sh)
• Query Analysis:
• The LLM-based query analyser (located under src/query_analyser/ with key files query_analyser.py and user_prompt.py)
• Core Services:
• Chess service: Handles chess-specific tasks (services/chess.py and modules/chess/* for puzzle analysis, FEN generation, and chain-of-thought prediction)
• Vector database & RAG: For document retrieval and context use (src/services/vector_database.py and src/services/rag.py)
• General QA: For answering questions using LLMs (src/services/qa.py)
• Code generation: Integrates with the PyCapsule service (modules/code_generation/code_generation.py)
• External Dependencies & Tools:
• Stockfish chess engine (in third_party/stockfish)
• Fen-To-Board-Image (third_party/Fen-To-Board-Image) for visual representations of chess boards
• Docker components and related scripts (Dockerfile, docker_compile.sh, docker_run.sh, and modules/docker/*)
Relationships and Interactions
• The user query enters the system via the chatbot front end or demo scripts.
• The query analyser (LLM-based) takes the user input and routes it to the appropriate service(s).
• Each service (chess, QA, vector database, code generation) processes queries, possibly interacting with external dependencies (e.g., Stockfish for chess moves, PyCapsule for code generation).
• The vector database service underpins both context retrieval and document-based queries.
• There is a clear separation between modules that handle different aspects (data handling, LLM interfacing, and specific service logic).
• The system configuration is controlled centrally via config.yaml (found in scripts/configs), reinforcing a modular but integrated design strategy.
Architectural Patterns and Design Principles
• Modular architecture: Each service (chess, vector database, RAG, code generation, QA) is separated into its own Python module with dedicated functionality.
• Service-orientation and pipeline design: The query analyser acts as a router to select the most relevant service for each query.
• Containerization: Deployment is designed around Docker containers for encapsulation and isolation, with scripts provided for building and running containers.
• Extensibility: The use of submodules and integration with external services (such as PyCapsule and Open-WebUI) implies a design that easily invites extension and integration.
• Separation of concerns: Distinguishing between core logic (in src/ and modules/) and supporting utilities (in utils/ and scripts/).
Technologies and Frameworks
• Programming Language: Python 3.8+
• Deployment: Docker (with build and run scripts)
• External Libraries: Stockfish for chess engine, Fen-To-Board-Image for board rendering, various LLM libraries (Hugging Face, OpenAI, Ollama)
• Web Framework (for user interface): Open-WebUI integration (backend chatbot container)
Elements
• Clear labels for each component:
• An “External Services” block for dependencies like Stockfish and Fen-To-Board-Image.
• Data flow back from the services to the UI.
• Special notation for containerization and deployment:
• Inter-container communication (if applicable) or note that some components are deployed as independent services.
• User Interaction Layer (UI, CLI via demo.py)
• Query Routing and Analysis (LLM-based dispatcher)
• Core Service Modules (chess analysis, QA, vector database, code generation)
• External and Supporting Services (Stockfish, Fen-To-Board-Image, Docker orchestration)
• Configuration and Deployment (config.yaml, Docker scripts)