File size: 10,366 Bytes
a4b8078 cf6d08c 102dd4f edb038d 9278db7 cb6dd54 9278db7 cf6d08c 9278db7 cf6d08c 9278db7 cf6d08c edb038d 9278db7 edb038d cf6d08c 9278db7 cf6d08c 9278db7 cf6d08c 9278db7 102dd4f 9278db7 102dd4f 9278db7 cf6d08c 9278db7 102dd4f 9278db7 102dd4f 9278db7 102dd4f 9278db7 cf6d08c 9278db7 102dd4f 9278db7 cb9a5de 9278db7 cf6d08c 9278db7 cf6d08c 9278db7 cf6d08c 9278db7 cf6d08c 9278db7 cf6d08c 9278db7 102dd4f 9278db7 102dd4f 9278db7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | ---
title: FALZH
sdk: docker
emoji: "\U0001F680"
colorFrom: blue
colorTo: blue
pinned: true
---
# FALZH
> **AI-powered travel service β on WhatsApp.**
> **π§ Work in progress β not yet published. Coming soon.**
<p align="center">
<img src="assets/Falzh.png" alt="FALZH logo" width="100%">
</p>
FALZH lets passengers search trips and connect with drivers, and lets drivers publish, update, and manage their trips β all through a natural conversation on WhatsApp. No app to install, no complex UI to learn. Just type what you want.
---
## Problem
Travel booking platforms in my country are poorly adopted. Not because people don't *want* a better way β but because:
- Users don't want to learn yet another app with a steep learning curve.
- People prefer something that works *inside* the tools they already use daily.
- Asking users to download a new app is a barrier. WhatsApp is already on their phone.
- Existing UIs are complicated and unintuitive.
## Solution
FALZH removes all of that. The entire interface is a single chat conversation. **You say where you're going and when β FALZH handles the rest.**
- **Passengers** describe their trip in natural language; FALZH searches available trips, shows options, and connects them with drivers.
- **Drivers** publish trips, manage schedules, and receive trip interest notifications β all by chatting.
- No app install, no account creation flow, no confusing dashboard.
---
## Features
- **Natural-language trip search** β "I want to go from Sana'a to Taiz tomorrow morning"
- **WhatsApp-native interaction** β interactive lists, text replies, no extra UI
- **Driver tools** β publish trips, add cars, modify/delete trips, receive trip interest notifications
- **Passenger tools** β search trips, select trips, get driver contact, get FALZH information
- **AI-powered orchestration** β tool-calling LLM (Groq primary, Hugging Face fallback) routes intent to the right action
- **RAG knowledge base** β company info, pricing, policies embedded via Jina AI and retrieved on demand
- **Trip vector search** β semantic search over driver trips for flexible departure matching
- **Multi-mode personas** β new-user onboarding, passenger mode, driver mode
---
## Why Vector Search?
Users describe trips in natural language: *"I want to go to Taiz tomorrow afternoon"*. Traditional SQL can't handle that. It would need exact dates, predefined routes, rigid filters.
**Semantic search** solves this. Trip departures ("tomorrow afternoon", "Friday morning") and routes are embedded into vectors using Jina AI. When a user says something, the query gets embedded the same way β and pgvector finds the closest matching trips by meaning, not by keyword.
This means:
- Users can phrase trips however they want β the system understands intent.
- Spelling mistakes or missing letters don't break the search β semantic similarity handles typos and partial input gracefully.
- No rigid dropdowns, no calendar pickers, no predefined route lists.
- The same vector index powers both trip search and RAG knowledge retrieval.
- It lives inside Postgres (pgvector) β no separate vector database to manage.
---
## Tech Stack
| Layer | Choice | Why |
|-------|--------|-----|
| **Language** | Python 3.12+ | Core comfort zone; best fit for the backend services, AI orchestration, and data work |
| **Framework** | FastAPI (async) | High performance, native async, great DX with Pydantic validation |
| **Primary LLM** | Groq (via OpenAI-compatible API) | Fast inference, generous free tier, tool-calling support |
| **Fallback LLM** | Hugging Face (OpenAI-compatible) | Backup provider for resilience when Groq is unavailable |
| **Embeddings** | Jina AI (`jina-embeddings-v5`) | Multilingual-capable, 1024-dim vectors, simple REST API |
| **Database** | Supabase (PostgreSQL + pgvector) | Managed Postgres with built-in vector search, real-time, and REST API |
| **WhatsApp** | Meta WhatsApp Cloud API | Official business API for reliable message delivery; webhook-based |
| **WhatsApp Bridge** | Baileys (Node.js) | Temporary bridge for WhatsApp Web protocol until Cloud API is fully onboarded; the system is designed to interact with Baileys identically to how it interacts with Cloud API, making the switch seamless |
| **Containerization** | Docker / Compose | Consistent dev environment, easy deployment |
| **Testing** | pytest + pytest-asyncio | Async-native testing with fully mocked external services |
| **Linting** | ruff | Fast, modern Python linter |
---
## Architecture
```
WhatsApp User
β
βΌ (message)
Baileys Bridge βββΊ FALZH API βββΊ AI Orchestrator βββΊ Tools
(Node.js, (FastAPI) (Groq / HF) β
separate repo) β β
βΌ βΌ
Supabase (pgvector) WhatsApp Cloud API
(trips, customers, (outbound replies)
messages, embeddings)
```
The system is designed so the WhatsApp integration layer is swappable. The Baileys bridge (Node.js) handles the Web protocol; the FALZH Python backend talks to it the same way it talks to the Cloud API. When Cloud API onboarding is complete, swapping the bridge requires zero changes to the core logic.
---
## Quick Start
### Prerequisites
- Python 3.12+
- A Supabase project (with pgvector enabled)
- API keys: Groq, Jina AI, Hugging Face, Meta WhatsApp Cloud
### Setup
```bash
# 1. Clone and enter the repo
git clone <repo-url> && cd falzh
# 2. Configure environment
cp .env.example .env
# Fill in your credentials (Supabase, Groq, Jina, WhatsApp, etc.)
# 3. Install dependencies
pip install -r requirements.txt
# 4. Apply database migrations
# Run the SQL files in supabase/migrations/ in order via Supabase SQL editor or psql
# 5. Start the server
uvicorn main:app --reload
```
The API is now running at `http://localhost:8000`.
### Seed Knowledge Base
```bash
./scripts/setup_and_seed.sh
```
This embeds the FALZH info document (`prompts/falzh_info.md`) and all active trips into Supabase pgvector for RAG retrieval.
### Run Tests
```bash
pytest
ruff check .
```
> Note: I'm still learning testing best practices through this project. Tests exist and pass, but coverage and structure will improve over time.
---
## Docker
```bash
docker compose up
```
Mounts the current directory with hot-reload enabled.
---
## Hugging Face Spaces
This repository is prepared to run as a Hugging Face Space using the top-level `app.py` entrypoint.
### What to do in Hugging Face
1. Create a new Space with the Python template.
2. Connect this repository to the Space.
3. Configure the required secrets in the Space settings if you want the full backend features enabled.
4. Deploy.
The Space will expose the FastAPI app on port `7860` and the app will respond at:
- `/` β simple service overview
- `/healthz` β health check
- `/docs` β interactive API documentation
If the external services are not configured yet, the app still starts in a lightweight demo mode and serves the health endpoint.
---
## WhatsApp Baileys Bridge
FALZH uses the official Meta Cloud API for production messages. During early stages β while waiting for commercial approval β a **Baileys-based bridge** acts as the WhatsApp gateway.
The bridge is a separate Node.js project:
#### [https://github.com/codeBOKER/wh_baileys](https://github.com/codeBOKER/wh_baileys)
It connects to WhatsApp via the Web protocol, relays inbound messages to the FALZH API, and forwards responses back to the user. The FALZH API treats the bridge identically to the Cloud API, so switching later requires no backend changes.
---
## API Endpoints
| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/healthz` | Health check |
| `GET` | `/webhooks/whatsapp` | Webhook verification (challenge) |
| `POST` | `/webhooks/whatsapp` | Receive WhatsApp messages |
| `POST` | `/admin/seed-info` | Seed FALZH RAG info |
| `POST` | `/admin/sync-trips` | Sync trip embeddings |
| `POST` | `/admin/jina-embed` | Test embedding |
| `POST` | `/admin/llm-tool-call` | Debug tool calling |
---
## Project Structure
```
falzh/
βββ app/
β βββ ai/ # LLM orchestration, providers, tool schemas
β βββ api/ # FastAPI routes, dependency injection
β βββ database/ # Supabase repository (CRUD + vector search)
β βββ models/ # Pydantic request/response & domain models
β βββ services/ # Business logic (conversation, admin, embeddings)
β βββ tools/ # Tool handler implementations + registry
β βββ utils/ # Logging, time helpers, departure parsing
β βββ whatsapp/ # WhatsApp client, parser, security, trip UI
βββ prompts/ # AI system prompts + RAG seed data
βββ scripts/ # Admin CLI scripts (seed, sync, test)
βββ supabase/migrations/ # SQL schema migrations (apply in order)
βββ tests/ # pytest suite with mocked externals
βββ docker-compose.yml
βββ Dockerfile
βββ pyproject.toml
βββ requirements.txt
βββ .env.example
```
---
## FAQ
**How do you find trips in the early stage with few users and drivers?**
We scrape public trip listings from WhatsApp groups and seed them into the database. This bootstraps the system with real trip data so passengers get results from day one. As adoption grows, drivers publish trips directly through the assistant.
**Why not use JavaScript across the entire project?**
Baileys (Node.js) is used only as a temporary WhatsApp bridge. My strongest area is Python β the core backend, AI orchestration, and data pipeline all benefit from Python's ecosystem, so the main service is built in Python. The bridge is minimal and swappable.
**How does the Baileys bridge differ from the Cloud API?**
It doesn't β that's the point. The FALZH backend speaks the same protocol to both. The Baileys bridge simply translates the WhatsApp Web protocol into the same format the Cloud API uses. When Cloud API approval comes through, we swap the bridge with zero backend changes.
---
## License
MIT
|