How nguyen-tho/simple-chatbot works
Main Components
• Chatbot Core Logic: The core functionality is likely encapsulated in files like common.py and perhaps parts of common.csv (which might hold reference data).
• Offline Mode Integration: This is supported by (likely) open_ai_api.py and possibly index_cpp.py which may interface with the Llama_cpp library and the Mistral 7B Open Orca model.
• Online Mode Integration: Handled by google_api.py, with the API key details stored in key.txt or api_key.json.
• Terminal Interface: Shown in terminal_app.py, which serves as the command-line entry point for running the chatbot.
• Web API: Implemented in app.py, which is designed to run with FastAPI on localhost (127.0.0.1:80).
• Web UI: Static assets (HTML, CSS, JS) in the static folder and possibly UI.py to support a browser-based user interface.
Interactions and Connections
• The Terminal App and the Web API both connect to the core chatbot logic.
• In offline mode, the chatbot core interacts with Llama_cpp (via open_ai_api.py/index_cpp.py) to process data using the Mistral model.
• In online mode, the system calls out to Google Gemini through google_api.py and uses the provided API key (from key.txt or api_key.json) to authenticate.
• The web UI (in static) consumes the API endpoints exposed by app.py.
Architectural Patterns and Design Principles
• Separation of Concerns: Distinct modules for handling offline and online processing.
• Modularity: Clear division of functionalities where each script handles dedicated tasks (e.g., UI.py for the user interface, terminal_app.py for command-line usage, and app.py for the API).
• Extensibility: The design supports both terminal and web interactions with potential future expansions (e.g., additional API endpoints or integrations).
Incorporate Technologies and Frameworks
• Python Environment: Using a virtual environment with dependencies specified in requirements.txt.
• FastAPI: Used in app.py to create a RESTful API service.
• Llama_cpp & Mistral 7B Open Orca Model: For processing offline chat operations.
• Google Gemini API: For the online mode of the chatbot.
• Basic web technologies (HTML, CSS, JS) to form the simple UI.
• If applicable, integration with libraries referenced in UI.py.