Skip to content

trieu/leo-bot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 LeoBot — AI Chat Assistant for Businesses & Users

LeoBot Screenshot

LeoBot is a FastAPI-based AI chatbot platform for intelligent, real-time conversations across multiple channels — including websites, Facebook Messenger, and Zalo Official Accounts. It integrates seamlessly with LEO CDP (Customer Data Platform) to serve both admins and end-users, delivering contextual, personalized answers powered by RAG (Retrieval-Augmented Generation) and advanced AI models like Google Gemini.


🌐 Live Chatbot Demo

Try the chatbot in action: 👉 https://leobot.leocdp.com

LeoBot uses the Google Gemini API for natural, context-aware responses.


🚀 Features

  • Multi-channel support: Works with Facebook Messenger and Zalo OA.
  • Gemini-powered intelligence: Uses Google Gemini API for high-quality understanding and generation.
  • RAG-based reasoning: Combines knowledge retrieval with semantic memory.
  • FastAPI backend: Lightweight, async, and production-ready.
  • Redis rate limiting: Prevents spam and message floods.
  • Custom personas: Supports user profiles, roles, and chat touchpoints.
  • Prebuilt frontend demos: Jinja2 templates for quick UI testing and embedding.

🧠 Architecture Overview

(Coming soon — overview diagram and explanation of key modules.)


🧩 Key Components

RAGAgent

Handles message understanding, context retrieval, and Gemini-based response generation.

Webhooks

  • /fb-webhook — Facebook Messenger
  • /zalo-webhook — Zalo Official Account

Redis Rate Limiting

Uses a sorted-set time window to prevent excessive messaging per user.


🛠️ Setup and Installation

1. Clone the Repository

git clone https://github.com/trieu/leo-bot
cd leo-bot

2. Start PostgreSQL + pgvector (via Docker)

Make sure Docker CLI is installed:

docker --version

Then start the database:

./start_pgsql_pgvector.sh

This script:

  • Launches a PostgreSQL 16 container (pgsql16_vector)
  • Mounts a persistent volume (pgdata_vector)
  • Enables pgvector and postgis extensions
  • Creates the customer360 database and schema
  • Handles collation version fixes automatically

To reset the database, run:

./start_pgsql_pgvector.sh --reset-db

You can connect manually:

psql -h localhost -U postgres -d customer360

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment

Create a .env file or edit main_config.py:

LEOBOT_DEV_MODE=false
HOSTNAME=leobot.example.com
POSTGRES_URL=postgresql://postgres:password@localhost:5432/customer360

GOOGLE_APPLICATION_CREDENTIALS=your_credentials.json
GEMINI_API_KEY=your_gemini_api_key

REDIS_USER_SESSION_HOST=127.0.0.1
REDIS_USER_SESSION_PORT=6480

FB_VERIFY_TOKEN=
FB_PAGE_ACCESS_TOKEN=your_facebook_access_token
ZALO_OA_ACCESS_TOKEN=your_zalo_access_token

Gemini API setup:


5. Python Environment (Ubuntu Example)

sudo apt install python-is-python3 python3.10-venv
python -m venv env
source env/bin/activate
pip install -r requirements.txt

After installation, refresh your shell.


6. Run LeoBot

Production mode:

./start_app.sh

Development mode:

./start_dev.sh

LeoBot will run at 0.0.0.0:8888. Open your browser and visit your configured HOSTNAME to test.


🌐 API Endpoints

Endpoint Method Description
/ask POST Main chatbot endpoint
/is-ready GET/POST Gemini API readiness check
/fb-webhook GET/POST Facebook Messenger webhook
/zalo-webhook POST Zalo OA webhook
/ping GET Basic health check
/get-visitor-info GET Retrieve visitor info from Redis

🧰 Developer Notes

  • Built on FastAPI with full async I/O.
  • Message context stored in Redis.
  • Embeddings via SentenceTransformer or Gemini Embeddings.
  • Compatible with pgvector and other vector databases.

To extend LeoBot:

  • Add webhook routes for new channels (Telegram, LINE, etc.)
  • Create custom response modules in rag_agent
  • Integrate new LLM APIs or plugins

🧪 Testing

Run automated tests:

pytest

Or test manually:

curl -X POST http://localhost:8000/ask \
  -H "Content-Type: application/json" \
  -d '{"visitor_id": "demo", "question": "Hello!", "persona_id": "test"}'

🧭 Author & Resources

Author: Trieu Nguyen YouTube: @bigdatavn Demo: https://leobot.leocdp.com


🌱 Future Roadmap

  • Support Telegram, LINE, and WhatsApp
  • Add knowledge-graph search (PostgreSQL + pgvector)
  • Streaming chat via SSE/WebSocket
  • AI analytics dashboard for admins
  • Plugin SDK for external integrations

📜 License

MIT License — free to use, modify, and share. Attribution is appreciated but not required.


💡 Vision

LeoBot embodies the union of Dataism and AI pragmatism — an assistant that connects people and data through natural conversation. It’s not just automation; it’s augmentation — amplifying human understanding through intelligent dialogue.

About

LEO BOT: the AI for Chatbot, Marketing Automation and Personalization Engine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 68.2%
  • HTML 11.5%
  • JavaScript 7.3%
  • PLpgSQL 6.2%
  • Shell 5.8%
  • CSS 1.0%