How 202416852-anhpv/4h2n works
Điện Máy Xanh is a Vietnamese AI shopping-advice chatbot. A shopper enters a need in the chat UI; the frontend sends conversation history to FastAPI, whose LLM tool loop searches real catalog data, then selects up to three grounded product cards or asks for clarification. Store-policy questions use a separate retrieval-and-answer branch. The README documents both semantic retrieval and keyword fallback, plus hallucination guardrails. Edges reflect shown calls and explicit README behavior; unsampled UI and tool-loop details are not expanded beyond that evidence.
Main entry points: llm.py Tool conversation loop · main.py Chat endpoint · catalog.py Catalog search · policies.py Policy search
Components 23
Chat experience
- Chat application
frontend/src/App.tsx - Chat input
frontend/src/components/ChatInput.tsx - Message view
frontend/src/components/MessageBubble.tsx - Markdown renderer
frontend/src/components/Markdown.tsx - Product cards
frontend/src/components/ProductCardView.tsx - Chat API client
frontend/src/api.ts
Conversation orchestration
- Chat endpoint
backend/app/main.py - Chat schemas
backend/app/schemas.py - Tool conversation loop
backend/app/llm.py - Clarification response
backend/app/llm.py - Product recommendation
backend/app/llm.py
Product retrieval
- Catalog search
backend/app/catalog.py - Product catalog
backend/app/data/products_detail.json - Product vectors
backend/app/data/product_embeddings.npz
Policy retrieval
- Policy search
backend/app/policies.py - Policy documents
backend/app/data - Policy vectors
backend/app/data/policy_embeddings.npz - Policy answer
backend/app/llm.py
Shared services
- Embedding client
backend/app/embeddings.py - Runtime settings
backend/app/config.py
Other components
- Shopper
- FPT AI Factory
- FPT embeddings API
Connections 28
- Shopper → Chat input: enters request
- Chat input → Chat application: submits text
frontend/src/App.tsx - Chat application → Chat API client: sends history
frontend/src/App.tsx - Chat API client → Chat endpoint: POST chat
README.md - Chat endpoint → Chat schemas: validates payload
backend/app/main.py - Chat endpoint → Tool conversation loop: runs chat
backend/app/main.py - Tool conversation loop → FPT AI Factory: requests tool calls
README.md - Tool conversation loop → Catalog search: searches products
backend/app/llm.py - Catalog search → Product catalog: loads records
backend/app/catalog.py - Catalog search → Product vectors: ranks candidates
backend/app/catalog.py - Catalog search → Embedding client: embeds query
backend/app/catalog.py - Tool conversation loop → Product recommendation: finalizes choices
backend/app/llm.py - Product recommendation → Catalog search: gets product details
backend/app/llm.py - Tool conversation loop → Clarification response: asks follow-up
backend/app/llm.py - Tool conversation loop → Policy search: searches policies
backend/app/llm.py - Policy search → Policy documents: chunks and searches
backend/app/policies.py - Policy search → Policy vectors: ranks chunks
backend/app/policies.py - Policy search → Embedding client: embeds query
backend/app/policies.py - Tool conversation loop → Policy answer: finalizes answer
README.md - Policy answer → Policy search: grounds response
README.md - Embedding client → FPT embeddings API: requests vectors
backend/app/embeddings.py - Embedding client → Runtime settings: reads credentials
backend/app/embeddings.py - Chat endpoint → Runtime settings: checks configuration
backend/app/main.py - Chat endpoint → Chat application: returns reply and cards
backend/app/main.py - Chat application → Message view: renders turns
frontend/src/App.tsx - Message view → Markdown renderer: renders text
frontend/src/components/MessageBubble.tsx - Message view → Product cards: renders products
frontend/src/components/MessageBubble.tsx - Product cards → Chat application: requests details
frontend/src/App.tsx