How d-artisan/ai-chatbot works
Main Components
• User Interfaces:
• Terminal UI (TerminalChat.py) for command-line interaction.
• Web UI (UIChat.py) powered by Streamlit, featuring avatars, personality settings, and voice toggles.
• Chatbot Engine:
• Core logic that processes inputs, maintains chat context, and generates responses using LangChain.
• Integration with local LLM models (e.g., mistral:7b) run via Ollama.
• Document Processing:
• Components/module(s) for handling document Q&A, including file loaders (PyPDFLoader, TextLoader) and FAISS-based document retrieval.
• Voice Support:
• Modules or subcomponents leveraging SpeechRecognition (speech-to-text) and pyttsx3 (text-to-speech) to handle voice input and output.
• Persistence Layer:
• Mechanisms to save and reload chat history from disk.
• External Dependencies & Configurations:
• The requirements.txt file to manage all the third-party libraries and dependencies.
Out the Relationships and Interactions
• The UI components (TerminalChat.py and UIChat.py) serve as entry-points where user inputs are captured.
• These inputs are sent to the Chatbot Engine, which then:
• Interacts with the local language model through LangChain/Ollama.
• If a document-based query is detected, the engine routes the request to the Document Processing component.
• The Document Processing component uses FAISS for quick retrieval and leverages file loaders (PyPDFLoader/TextLoader) to parse and understand the document content.
• For voice interactions, the engine temporarily passes audio input through the SpeechRecognition module, converts it to text, and then processes it through the same chatbot engine. The response may be converted back into speech using pyttsx3.
• Chat sessions and histories are maintained on disk, so there should be persistence hooks within the engine.
Architectural Patterns and Design Principles
• Separation of Concerns:
• Different files handle different interfaces (terminal vs. Streamlit-based web UI).
• Core logic, document handling, voice processing, and persistence are functionally separated.
• Modular Design:
• Clear Input/Output Flow:
Technologies and Frameworks
• Python with dependencies (LangChain, Ollama, FAISS, PyPDFLoader, TextLoader, SpeechRecognition, pyttsx3) serve as the backbone.
• Streamlit for the web interface.
• Local LLM models (e.g., mistral:7b) via Ollama.
• FAISS for vector-based retrieval in the Document Q&A feature.