Skip to content
silvaxxx1Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

36 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

β˜• Fero Cafe β€” AI-Powered Coffee Shop Chatbot

Open source. A full-stack conversational commerce app built to explore multi-agent LLM pipelines in a real-world setting. A customer types naturally β€” "I want a latte and a croissant" β€” and a pipeline of specialized agents handles intent classification, menu validation, personalized recommendations, and order state across the conversation. The result is a cross-platform mobile app backed by a fully async Python API with SSE streaming, SQLite session persistence, 120 passing tests, LLM evals, and a live observability dashboard.

Python 3.12 FastAPI React Native Groq Tests License Open Source


πŸ“Ή Demo

Fero Cafe Demo

End-to-end walkthrough: multi-item ordering, guard agent, RAG-powered Q&A, and cart auto-population from chat


πŸ“Š Observability Dashboard

Observability Dashboard

Live dashboard at http://localhost:8000/dashboard β€” request latency, token usage, agent distribution, and guard block rate. Auto-refreshes every 5s.


✨ Features

Feature What it does
🧠 Multi-agent pipeline Guard β†’ Classification β†’ Details / Order / Recommendation
πŸ” RAG (Retrieval-Augmented Generation) Answers menu & shop questions via ChromaDB (local, no API key)
πŸ“ Smart ordering Multi-turn conversation with menu validation and persistent state
🎯 Personalized recommendations Apriori market basket analysis + popularity rankings
πŸ“± React Native app Browse menu, chat, review cart β€” one unified flow
⚑ SSE streaming Responses stream token-by-token via POST /chat/stream; first token at ~1s
πŸ’Ύ Session persistence SQLite-backed sessions; conversation restores on reload; "New chat" to reset
πŸ”„ Provider-agnostic LLM Swap Groq, RunPod, or OpenAI with a single .env change
βœ… 160 passing tests 126 backend (pytest) + 34 frontend (Jest) β€” no API key needed for unit tests
πŸ” Live search Filter menu by name in real time, combined with category chips
πŸ“ Size selection S / M / L adjusts price live on the detail screen; size-adjusted totals in cart
πŸ–ΌοΈ Products in chat Image cards appear below recommendation and order-confirmation bubbles
πŸ›’ Smart cart merge Chat orders merge with browse-screen adds β€” no more cart-wipe on agent response
πŸ“Š Observability dashboard Live /dashboard β€” latency, tokens, routing, guard block rate
πŸ§ͺ LLM evals Guard, classification, recommendation accuracy tested against real LLM
πŸ–ΌοΈ Bundled product images Served from local assets β€” no Firebase Storage required

πŸ—οΈ Architecture

React Native App (Expo)
        β”‚
        β”‚  POST /chat/stream  { messages, session_id }  (SSE)
        β–Ό
   FastAPI Server  (local_server.py)  ← fully async
        β”‚
        β–Ό
   AgentController
        β”‚
        β”œβ”€β”€ GuardAgent           β†’ blocks off-topic / harmful queries
        β”‚
        β”œβ”€β”€ ClassificationAgent  β†’ routes intent
        β”‚
        └── DetailsAgent         β†’ RAG: sentence-transformers β†’ ChromaDB (local) β†’ LLM
            OrderTakingAgent     β†’ multi-turn order + auto-upsell
            RecommendationAgent  β†’ Apriori / popularity rankings
                β”‚
                β–Ό
           Groq API  (llama-3.3-70b-versatile)

πŸ’‘ Design note: Every agent uses AsyncOpenAI with a configurable base_url β€” no vendor lock-in. Invalid routing returns a graceful error rather than crashing the pipeline.


πŸ› οΈ Tech Stack

Layer Technology Why
LLM Groq API (llama-3.3-70b) Free tier, fast inference
Embeddings sentence-transformers (all-MiniLM-L6-v2) Runs locally, no API cost
Vector DB ChromaDB Local persistent index β€” no API key, no account
Backend Python 3.12 + FastAPI Async, type-safe
Frontend React Native + Expo Router Cross-platform, hot reload
Styling NativeWind (Tailwind) Utility-first, rapid UI
Recommendations scikit-learn (Apriori) Market basket analysis
Testing pytest + jest-expo 126 backend + 34 frontend, no API key needed for unit tests
Observability structlog + Chart.js dashboard Structured logs + live /dashboard
Product catalog Firebase Realtime DB Live product data
Product images Bundled local assets No Firebase Storage required

πŸš€ Quick Start

Prerequisites

# Required
Python 3.12+
Node.js 18+

# Recommended
uv  # fast Python package manager

# Free accounts needed
Groq API key  β†’  https://console.groq.com

1. Backend Setup

# Clone and enter repo
git clone https://github.com/silvaxxx1/Cafe.AI.git
cd Cafe.AI

# Create virtual environment
uv venv .venv --python 3.12
source .venv/bin/activate        # Windows: .venv\Scripts\activate

# Install dependencies
cd python_code/api
uv pip install -r requirements.txt

# Pin httpx β€” newer versions break the openai async client
uv pip install "httpx==0.27.2"

# Configure environment
cp .env_example .env

Edit .env with your credentials:

# Note: these variable names reflect RunPod origins β€” they work equally for Groq
RUNPOD_TOKEN=your-groq-api-key-here
RUNPOD_CHATBOT_URL=https://api.groq.com/openai/v1
MODEL_NAME=llama-3.3-70b-versatile

Start the server:

python local_server.py
# βœ… Agents ready.
# πŸš€ Uvicorn running on http://0.0.0.0:8000

2. Frontend Setup

# Open a new terminal
cd coffee_shop_app

# Copy config and fill in Firebase + backend URL
cp .env_example.txt .env

# Install and run
npm install
npm run web    # Opens at http://localhost:8081

3. Verify the Integration

# Streaming endpoint (what the app uses)
curl -N -X POST http://localhost:8000/chat/stream \
  -H "Content-Type: application/json" \
  -d '{"input": {"messages": [{"role": "user", "content": "I want a latte and a croissant"}]}}'

Expected: SSE token stream ending with {"type":"done","memory":{"order":[...]}} β€” both items captured with correct prices. 🎯


πŸ§ͺ Testing

# Backend unit tests (no API key needed)
make test          # 126 pytest tests

# Frontend unit tests
make test-frontend # 34 Jest tests (CartContext, MessageItem, SizesSection, productService)

# Both suites in sequence
make test-all

# LLM evals (requires valid Groq key in .env)
make evals

126 backend tests cover all agents, the server (streaming and session endpoints), and eval runner logic. All LLM calls are mocked with AsyncMock β€” no API key needed.

34 frontend tests cover CartContext (13), MessageItem (12), SizesSection (8), and productService (4).

Evals hit the real LLM and report per-case PASS/FAIL with a pass rate. Exit 1 if below 80%.


πŸ’¬ Example Prompts

You say… Agent handles it
"Who won the World Cup?" πŸ›‘οΈ Guard blocks
"What are your opening hours?" πŸ“š Details (RAG)
"Tell me about Fero Cafe" πŸ“š Details (RAG)
"What do you recommend?" 🎯 Recommendation
"What pastry should I get?" 🎯 Recommendation (category-filtered)
"I want a latte and a croissant" πŸ“ Order β€” 2 items captured
"Also add an espresso" πŸ“ Order β€” context remembered
"No thanks, that's all" πŸ“ Order β€” finalised with total

πŸ”§ Advanced Setup

ChromaDB (RAG Q&A)

No account or API key needed β€” the index lives on disk.

# 1. Build the index (runs locally, ~30 seconds)
cd coffee_shop_customer_service_chatbot/python_code
python build_index.py
# β†’ Writes index to api/chroma_db/

# 2. Restart the backend
# β†’ [DetailsAgent] RAG enabled β€” local embeddings + ChromaDB.

Uses sentence-transformers/all-MiniLM-L6-v2 for embeddings locally. Without the index, DetailsAgent is gracefully disabled and the rest of the app functions normally.

Firebase (live product catalog)

Firebase is pre-configured for the fero-ai project. To use your own:

# 1. Create a project at console.firebase.google.com
# 2. Enable Realtime Database (Spark / free plan β€” Storage NOT required)
# 3. Download service account JSON from Project Settings β†’ Service Accounts
# 4. Fill python_code/.env with service account fields
# 5. Seed products (images are local, no upload needed):
cd python_code
jupyter notebook firebase_uploader.ipynb

# 6. Add Firebase web config to coffee_shop_app/.env

Product images are bundled in coffee_shop_app/assets/images/products/ and mapped by filename in constants/productImages.ts. Firebase stores only the filename (e.g. cappuccino.jpg), not a remote URL.

Without Firebase, the home tab shows an empty menu β€” but the chat tab works fully. The agent validates orders against menu.json, which is always loaded server-side.

Running on a Physical Device

  1. Install Expo Go on your phone
  2. Ensure your phone and computer are on the same Wi-Fi network
  3. Update coffee_shop_app/.env:
    EXPO_PUBLIC_RUNPOD_API_URL='http://192.168.x.x:8000/chat'  # your local IP
  4. Run and scan the QR code:
    npm start

🚒 Production Deployment (RunPod)

cd python_code/api
docker build -t your-dockerhub/fero-cafe:latest .
docker push your-dockerhub/fero-cafe:latest
  1. Create a RunPod serverless endpoint with the image
  2. Set env vars from .env_example
  3. Update EXPO_PUBLIC_RUNPOD_API_URL in the frontend to your RunPod endpoint

πŸ“ Project Structure

Cafe.AI/
β”œβ”€β”€ πŸ“± coffee_shop_app/              # React Native (Expo)
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ _layout.tsx            # Root layout: providers + web frame
β”‚   β”‚   β”œβ”€β”€ index.tsx              # Splash / landing screen
β”‚   β”‚   β”œβ”€β”€ details.tsx            # Product detail
β”‚   β”‚   β”œβ”€β”€ thankyou.tsx           # Order confirmation
β”‚   β”‚   └── (tabs)/
β”‚   β”‚       β”œβ”€β”€ _layout.tsx        # Tab bar with cart badge
β”‚   β”‚       β”œβ”€β”€ home.tsx           # Menu browse + category filter
β”‚   β”‚       β”œβ”€β”€ chatRoom.tsx       # AI chat β†’ auto-fills cart
β”‚   β”‚       └── order.tsx          # Cart review + checkout
β”‚   β”œβ”€β”€ components/                # CartContext, MessageList, UI components
β”‚   β”œβ”€β”€ constants/
β”‚   β”‚   β”œβ”€β”€ theme.ts               # Light/dark token system + useTheme()
β”‚   β”‚   β”œβ”€β”€ responsive.ts          # useGridColumns(), webPointer utils
β”‚   β”‚   └── productImages.ts       # filename β†’ require() map
β”‚   β”œβ”€β”€ services/                  # chatBot.ts, productService.ts (cached)
β”‚   β”œβ”€β”€ assets/images/products/    # Bundled product images (18 items)
β”‚   β”œβ”€β”€ polyfills.ts               # setImmediate shim for web
β”‚   └── config/                    # Firebase config
β”‚
└── 🐍 python_code/
    β”œβ”€β”€ api/
    β”‚   β”œβ”€β”€ agents/
    β”‚   β”‚   β”œβ”€β”€ guard_agent.py
    β”‚   β”‚   β”œβ”€β”€ classification_agent.py
    β”‚   β”‚   β”œβ”€β”€ details_agent.py
    β”‚   β”‚   β”œβ”€β”€ order_taking_agent.py
    β”‚   β”‚   β”œβ”€β”€ recommendation_agent.py
    β”‚   β”‚   β”œβ”€β”€ agent_protocol.py     # async Protocol
    β”‚   β”‚   └── utils.py
    β”‚   β”œβ”€β”€ tests/                 # 126 tests βœ… (unit + eval runners)
    β”‚   β”œβ”€β”€ recommendation_objects/
    β”‚   β”œβ”€β”€ local_server.py        # Dev server (async FastAPI)
    β”‚   β”œβ”€β”€ main.py                # RunPod entry point
    β”‚   β”œβ”€β”€ agent_controller.py    # Pipeline orchestration
    β”‚   β”œβ”€β”€ session.py             # SQLite session store
    β”‚   └── menu.json              # Single source of truth for product names
    β”œβ”€β”€ products/
    β”‚   β”œβ”€β”€ products.jsonl         # Full product data (seeded to Firebase)
    β”‚   └── images/                # Source images
    β”œβ”€β”€ firebase_uploader.ipynb    # Seeds Firebase (no Storage needed)
    β”œβ”€β”€ build_vector_database.ipynb
    └── recommendation_engine_training.ipynb

πŸ” Environment Variables

Backend (python_code/api/.env)

Variable Required Description
RUNPOD_TOKEN βœ… Yes Your Groq API key (legacy name β€” works for any provider)
RUNPOD_CHATBOT_URL βœ… Yes https://api.groq.com/openai/v1
MODEL_NAME βœ… Yes llama-3.3-70b-versatile
CHROMA_DB_PATH ❌ Optional Path to ChromaDB index (default: api/chroma_db/). Run build_index.py once to create it.

Firebase Seeding (python_code/.env)

Variable Description
FIREBASE_* Service account fields from Firebase console
FIREBASE_DATABASE_URL Realtime Database URL

Frontend (coffee_shop_app/.env)

Variable Required Description
EXPO_PUBLIC_RUNPOD_API_URL βœ… Yes Backend URL (e.g. http://localhost:8000/chat)
EXPO_PUBLIC_FIREBASE_API_KEY βœ… Yes Firebase web API key
EXPO_PUBLIC_FIREBASE_DATABASE_URL βœ… Yes Realtime Database URL
EXPO_PUBLIC_FIREBASE_* βœ… Yes Remaining Firebase web config fields

πŸ—ΊοΈ Roadmap

V1 β€” Complete βœ…

  • Multi-agent pipeline β€” Guard β†’ Classification β†’ Details / Order / Recommendation
  • Fully async FastAPI + all agents
  • SSE streaming β€” POST /chat/stream; first token at ~1s
  • SQLite session persistence β€” restores conversation on reload
  • Dynamic menu β€” menu.json single source of truth, injected at startup
  • Observability β€” structlog structured logging + live /dashboard
  • LLM evals β€” guard, classification, recommendation runners (80% threshold)
  • 120 passing tests β€” unit + eval runners, no API key needed for unit tests
  • Production hardening β€” rate limiting, CORS, startup validation, typed input
  • CI/CD β€” GitHub Actions on every push

V2 β€” Complete βœ…

  • Live search β€” filters menu by name in real time, combined with category chips
  • Size selection β€” S/M/L adjusts price live; size-adjusted totals flow through cart
  • Product images in chat β€” cards below recommendation and final-order bubbles, tappable to detail
  • Fix cart-wipe bug β€” syncCartFromOrder merges LLM orders without wiping browse-screen adds
  • RecommendationAgent turn memory β€” last_recommendations stored; repeats avoided next turn
  • Wider context window β€” CONTEXT_WINDOW=6 across guard, classification, recommendation
  • Response variation β€” temperature=0.7 on recommendation language calls
  • Full TypeScript types β€” AgentMemory union replacing memory?: any everywhere
  • Frontend tests β€” CartContext (13), MessageItem (12), SizesSection (8), productService (4)
  • make test-all β€” runs backend + frontend suites in sequence
  • RAG β€” ChromaDB local index (no API key); build_index.py populates api/chroma_db/ in ~30s

V3 β€” Possible Next Steps

  • Cart β†’ agent context β€” agent awareness of items added via browse screen
  • Product images on menu/details agent responses
  • Multi-tenant deployment β€” one backend serving multiple cafΓ© clients

See V2_PLAN.md for the full breakdown with file references and implementation details.


πŸ“„ License

MIT β€” free for personal and commercial use.


πŸ™ Acknowledgments

  • Groq for free, fast LLM inference
  • ChromaDB for local vector storage
  • Expo for React Native tooling
  • Firebase for real-time product catalog

Built with β˜• and πŸ€– by SilvaLAB

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages