How preethicoder/kitchenremedykid_chatbot works
Project Type and Purpose
• HomeCure-Kids is a full-stack web application:
• Frontend: React SPA providing a conversational UI.
• Backend: FastAPI service orchestrating AI retrieval, response generation, PDF creation, image generation, and email delivery.
• Purpose: Offer interactive, kitchen-based home remedy suggestions for kids using OpenAI/GPT, LangChain, FAISS, web-scraped sources, and downloadable/exportable assets (PDFs, visuals).
File Structure Highlights
• Top-level (Backend)
• main.py – FastAPI app and endpoint definitions.
• home_cure_kids.py – Core chat logic invoking LangChain, OpenAI, retrieval.
• retrieverFAISS.py – Builds/queries FAISS vector index.
• relevance_score.py – Scores the relevance of generated remedies.
• pdf_utils.py – Formats and exports remedy content to PDF.
• email_utils.py – Sends remedy PDFs via SMTP.
• visual.py – Generates step-by-step illustrations (DALL·E).
• faiss_index/ – Persisted FAISS index files.
• Frontend (homecure-frontend/)
• React source under src/: App.js, index.js, UI components.
• Public assets and manifest for PWA.
• Config & Tests
• see test_kitchen_remedy_chatbot.py for end-to-end tests.
• seen_urls.txt logs scraping history.
Key Architectural Components
a. Client (Browser/React SPA)
b. API Layer (FastAPI)
c. Retrieval Engine (LangChain + FAISS)
d. AI Services (OpenAI GPT for text, DALL·E for visuals)
e. Data & Storage
• Local FAISS index on disk
• Temporary/Generated PDFs
• Scraped content cache (seen_urls.txt)
f. Utility Services
• PDF export service (pdf_utils)
• Email service (email_utils)
• Relevance scorer (relevance_score)
Interactions & Data Flow
1) User sends symptom query via React UI.
2) Frontend issues HTTP POST → FastAPI endpoint (/chat).
3) FastAPI → retrieverFAISS: perform vector similarity search on FAISS index.
4) Retrieved docs + chat history fed into LangChain prompt → OpenAI GPT call.
5) GPT returns remedy text → FastAPI passes to relevance_score for quality check.
6) Optionally:
• visual.py requests DALL·E to generate step visuals.
• pdf_utils assembles text + visuals into PDF.
• email_utils sends PDF to user’s email.
7) Response (text + image URLs + PDF link) returned to React UI.
Architectural Patterns & Principles
• Layered Architecture: Clear separation of UI, API, business logic, and infrastructure.
• Modular Python services: Each utility (PDF, email, retrieval) encapsulated in its own module.
• Single-page Application (SPA) for responsive UX.
• Vector search + LLM chain for context-aware retrieval.
• Asynchronous I/O in FastAPI for non-blocking calls to OpenAI and email services.