How alrashid-alkiswane/chatbot-for-dental-clinic works
Main Components
• Entry Point & Environment Configuration:
• main.py: Acts as the application launcher.
• .env.example: Environment variables handling.
• API Layer & Frontend:
• src/api: Contains RESTful endpoints that serve both API interactions and the Web UI.
○ chatbot_api.py: Provides routes for handling chat requests.
○ templates (chat.html) and static (styles.css): Serve the web frontend.
• Chatbot Pipeline:
• src/pipeline_chatbot/chatbot_pipeline.py: Orchestrates the conversation flow and overall pipeline.
• Retrieval Augmented Generation (RAG) Module:
• src/RetrievalAugmentedGeneration: Implements document retrieval and generative responses.
○ generative.py: Handles language model–based response generation.
○ retrieve_relevant_documents.py: Manages the logic for fetching relevant documentation.
• Models:
• src/models: Houses different language models and embedding models.
○ embedding_model.py: Feature extraction from text.
○ llm_huggingface.py & openai_model.py: Interfaces for different LLM implementations.
• Data Operations & Database Integration:
• src/data_operation: Functions for ingesting data to and retrieving data from a database.
○ ingest_database.py, pull_from_database.py: Manage CRUD operations.
○ combine_dataframe_with_text.py, unzip_file.py: Pre-processing and data handling.
• Auxiliary & Support Components:
• src/cash: Likely provides caching support.
• src/configs: Configuration modules.
• src/save_pydantic: Implements history or logging functions using Pydantic models.
• src/utils: Utility modules for generic operations (like get_size and monitoring functions).
• Additional Resources:
• assets: Stores images (e.g., for documentation) and potential other static resources (like the dental clinic image).
Relationships and Interactions
● The User Interface (UI)/Client sends chat requests via the API (src/api) to main.py.
● The API endpoints (chatbot_api.py) relay these requests to the Chatbot Pipeline, which is orchestrated by src/pipeline_chatbot/chatbot_pipeline.py.
● The chatbot pipeline leverages two key subcomponents:
– The Retrieval Augmented Generation module (src/RetrievalAugmentedGeneration) which retrieves documents and uses language models to generate responses.
– The Models module (src/models) provides the underlying LLM and embedding functionalities (using either Hugging Face or OpenAI based implementations).
● Data Operations (ingest_database.py, pull_from_database.py in src/data_operation) support the pipeline by managing patient information and historical interactions.
● Caching (src/cash) and Logging/History (src/save_pydantic/history_chat.py) enhance performance and allow tracking/logging of conversations.
● Utility functions (src/utils) support monitoring and other general system checks.
● Config modules (config/pipeline_config.yaml and src/configs) centrally manage settings, parameters, and secrets (with .env providing environment variable overrides).
Architectural Patterns & Design Principles
• Layered Architecture: Clearly separated layers for presentation (frontend/API), business logic (pipeline, generative modules), and data handling (database operations).
• Modularization: Each major functionality is isolated into its own subdirectory (RAG, models, data_operation, etc.), allowing independent evolution and testing.
• Dependency Injection & Configuration Management: Use of config files and environment settings to manage dependencies and runtime parameters.
• Extensibility: The design supports plugging in different machine learning models (e.g., Huggingface, OpenAI) and easily modifying data ingestion or retrieval strategies.