How niyasahamedk/medical-chatbot works
Project type & purpose (from file tree + README)
This is a small Python application/package for a Medical Chatbot. The structure suggests:
• A runtime application entrypoint: app.py (likely launches a web UI or API server).
• A reusable Python package under src/ containing the chatbot’s core logic:
• src/prompt.py (prompt construction / prompt templates for medical domain behavior)
• src/helper.py (shared utilities: formatting, request wrappers, preprocessing/postprocessing, etc.)
• A templating layer: template.py (could be UI template, prompt template scaffolding, or response formatting template).
• Packaging & dependency management: setup.py, requirements.txt.
• R&D / experimentation: research/trials.ipynb.
Because the repository is small, being “very detailed” means: split modules and flows explicitly, and clearly label external calls (LLM/provider, any databases if present).
Runtime / execution components
• User (doctor/patient/tester)
• Chat UI / Client (whatever app.py exposes)
• If app.py uses Streamlit/Gradio: it’s a Web UI
• If app.py uses Flask/FastAPI: it’s an HTTP API
• If it’s CLI: it’s a terminal app
• Application Orchestrator (app.py)
• Routes user messages to the chatbot core
• Handles session state (if any)
• Handles request/response formatting
Core “business logic” components (in src/)
• Prompt Builder (src/prompt.py)
• Defines system prompt, medical constraints, safety notes, formatting rules
• May contain prompt templates, few-shot examples, roles/messages construction
• Helpers / Utilities (src/helper.py)
• Likely includes: text cleaning, logging, config loading, API wrappers, parsing model output, guardrails, etc.
• Package init (src/__init__.py)
• Exposes top-level functions/classes
Templates
• template.py
• It as a component responsible for:
• response formatting / UI formatting, OR
• prompt skeleton templating
> Again, confirm by reading its functions/classes.
Even though not visible in the tree, a medical chatbot almost certainly relies on one of:
• LLM Provider API (OpenAI / Anthropic / local model server)
• Optional (only include if present in code): Vector DB / Retrieval (FAISS/Pinecone/Chroma), Medical knowledge source, Database for conversations, Telemetry/Logging
• requirements.txt (e.g., openai, langchain, chromadb, pinecone, faiss, fastapi, streamlit, etc.)
• app.py imports and runtime code
app.py → Prompt Builder (src/prompt.py)
• “Build system + user message prompt”
app.py → Helpers (src/helper.py)
• “Preprocess input / validate / postprocess output”
app.py (or helper) → External LLM API
• “Send prompt/messages, receive completion”
If template.py formats output
• app.py → template.py → UI
If configs are used (env vars, keys)
• A small Config/Secrets node (e.g., environment variables) feeding app.py/helpers.
• “user message”
• “prompt/messages”
• “completion/response”
• “formatted response”
• “API key/config”
Architectural patterns to highlight (based on structure)
From the tree, the pattern is likely:
• Thin orchestrator (app.py) + modularized core in src/
• Prompt-as-code (prompt logic isolated in src/prompt.py)
• Utility layer (helpers provide shared cross-cutting behaviors)
• “Application Layer” (app.py)
• “Domain/Chatbot Logic” (prompt.py)
• “Shared Utilities” (helper.py)
• “External Dependency” (LLM API)
What
Include:
• User
• Browser/Client (or API client)
• Python App (app.py)
• External LLM API
• (Optional) Config/Secrets
Inside “Python App” boundary, include:
• Request handling / session management (in app.py)
• Prompt construction (src/prompt.py)
• Pre/post processing utilities (src/helper.py)
• Templating/formatting (template.py)
• LLM call wrapper (could be inside helper.py; label it explicitly if so)
Open requirements.txt and list frameworks
• streamlit/gradio/flask/fastapi?
• openai/langchain?
Open app.py
• entrypoint type (UI vs API vs CLI)
• where LLM call occurs (directly in app.py or via helper)
Open src/prompt.py
• prompt format (chat messages vs plain text)
Open src/helper.py and template.py
Only after those checks should you finalize labels like “Streamlit UI” vs “FastAPI Server”, “OpenAI API” vs “Local Ollama Server”, etc.