An open API service indexing awesome lists of open source software.

https://github.com/amine-akrout/parenting-assistant-rag

AI-Powered Parenting Assistant
https://github.com/amine-akrout/parenting-assistant-rag

docker docker-compose faiss fastapi huggingface langchain langfuse llm llm-guard llmops openai rag

Last synced: about 2 months ago
JSON representation

AI-Powered Parenting Assistant

Awesome Lists containing this project

README

          

# ๐Ÿค– AI-Powered Parenting Assistant

## ๐Ÿ“Œ Overview
The **AI-Powered Parenting Assistant** is an intelligent chatbot designed to provide safe, reliable, and empathetic responses to parenting-related questions. Built using **LangChain**, **LLM Guard**, and **FastAPI**, the system leverages **Retrieval-Augmented Generation (RAG)** to enhance its responses with relevant knowledge from curated sources.

The chatbot also integrates **advanced content filtering** to ensure the safety and appropriateness of responses, making it a powerful demonstration of AI engineering best practices.

---

## ๐Ÿš€ Features
### โœ… **Retrieval-Augmented Generation (RAG) System**
- Uses **FAISS vector search** combined with **BM25 retrieval** for accurate contextual knowledge retrieval.
- Implements **OpenVINO Reranker** for document ranking and relevance filtering.

### ๐Ÿ›ก **AI Safety with LLM Guard**
- **Input Filtering**: Blocks **toxic, political, religious, and self-harm topics** using `llm_guard`.
- **Output Validation**: Scans model responses for **language safety, sensitivity, and relevance**.
- **Routing Mechanism**: Ensures inappropriate queries are handled gracefully.

### โšก **High-Performance AI Pipeline**
- **LangChain Pipelines**: Modular **runnable chains** for seamless data flow.
- **Prompt Engineering**: Optimized **few-shot prompting** for structured AI outputs.
- **FastAPI Backend**: Fully asynchronous **REST API** for real-time chatbot interactions.
- **Langfuse Monitoring**: Enables **real-time LLM performance tracking**.

### ๐Ÿ”ฅ **Job-Worthy Tech Stack**
โœ… **AI & LLMs**: OpenAI GPT Models, LangChain, HuggingFace Embeddings
โœ… **Data Retrieval**: FAISS, BM25, OpenVINO Reranker
โœ… **Safety**: LLM Guard (Input & Output Filtering)
โœ… **Backend API**: FastAPI, Pydantic, Loguru
โœ… **Monitoring**: Langfuse Callbacks
โœ… **Dockerized Pipeline**: Multi-stage AI data processing stack

---

## ๐Ÿ“ Project Structure
```
๐Ÿ“‚ src/
โ”œโ”€โ”€ core/
โ”‚ โ”œโ”€โ”€ chatbot.py # Main AI chatbot pipeline (LLM + Retrieval + Guard)
โ”‚ โ”œโ”€โ”€ embedding.py # FAISS/BM25 index generation
โ”‚ โ”œโ”€โ”€ evaluation.py # AI performance and accuracy checks
โ”‚ โ”œโ”€โ”€ filters.py # LLM Guard configurations for input/output scanning
โ”‚โ”€โ”€ config.py # Application settings & environment variables
โ”‚
โ”œโ”€โ”€ api/
โ”‚ โ”œโ”€โ”€ routers/
โ”‚ โ”‚ โ””โ”€โ”€ chat.py # FastAPI routes for chatbot integration
โ”‚ โ”‚โ”€โ”€ __init__.py # API initializer
โ”‚ โ””โ”€โ”€ main.py # FastAPI app initialization
โ”‚
โ”œโ”€โ”€ data/
โ”‚ โ”œโ”€โ”€ clean_data.py # Data preprocessing scripts
โ”‚
โ”œโ”€โ”€ monitoring/
โ”‚ โ””โ”€โ”€ monitoring.py # Langfuse monitoring setup
โ”‚
โ”œโ”€โ”€ Dockerfile # Containerization setup
โ”œโ”€โ”€ docker-compose.yml # Multi-container deployment setup
โ”œโ”€โ”€ requirements.txt # Python dependencies
โ”œโ”€โ”€ README.md # Project documentation (this file)
```

---

## ๐Ÿ— Setup & Installation
### 1๏ธโƒฃ **Clone the Repository**
```bash
git clone https://github.com/amine-akrout/parenting_assistant_rag.git
cd parenting_assistant_rag
```

### 2๏ธโƒฃ **Create Virtual Environment & Install Dependencies**
```bash
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt
```

### 3๏ธโƒฃ **Set Up Environment Variables**
Create a `.env` file in the root directory:
```ini
POSTGRES_USER=your_db_user
POSTGRES_PASSWORD=your_db_password
POSTGRES_DB=your_db_name
OPENAI_API_KEY=your-openai-key
LANGFUSE_PUBLIC_KEY=your-langfuse-public-key
LANGFUSE_SECRET_KEY=your-langfuse-secret-key
```

### 4๏ธโƒฃ **Run the API Server**
```bash
uvicorn src.api.main:app --host 0.0.0.0 --port 8000
```

### 5๏ธโƒฃ **Test the API**
Open **Swagger UI** to test endpoints:
๐Ÿ“Œ `http://localhost:8000/docs`

---

## ๐Ÿณ Dockerized Workflow
This project includes a **Dockerized data pipeline** that prepares, indexes, and serves the chatbot API.

### 1๏ธโƒฃ **Start All Services**
```bash
docker-compose up --build
```
### 2๏ธโƒฃ **Stop All Services**
```bash
docker-compose down
```

### **Docker Services Overview**
- **`langfuse-server`** โ†’ Logs chatbot requests/responses for monitoring
- **`db`** โ†’ PostgreSQL database for logging and indexing
- **`clean-data`** โ†’ Prepares and cleans datasets before indexing
- **`preprocess`** โ†’ Creates FAISS/BM25 indexes for fast retrieval
- **`chatbot-api`** โ†’ Runs the **FastAPI** chatbot backend

---

## ๐Ÿ“ˆ Performance Monitoring (Langfuse)
Enable **Langfuse** for real-time monitoring:

๐Ÿ“Œ `http://localhost:3000`

View logs on **Langfuse Dashboard**.

---

## ๐Ÿงช Testing

Run unit tests using **pytest**:

```bash
pytest tests/
```

---

## ๐ŸŽฏ Future Enhancements
โœ… Add **multi-turn conversations** (memory support)
โœ… Implement **whisper model for speech-to-text**
โœ… Add **more retrieval sources (vector & hybrid search)**
โœ… Integrate **more LLM Guard features** (e.g., sentiment analysis)

---

## ๐Ÿค Contributing
Feel free to **open an issue** or **submit a pull request**.

---