Skip to content

A RAG based Diary Bot assistant with 2 interface options: web UI and CLI.

Notifications You must be signed in to change notification settings

JoeCardoso13/diary_bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Diary Bot RAG Assistant

This application creates a Retrieval-Augmented Generation (RAG) system that allows users to ask questions about their custom-made diary. For demonstration, the system uses an arbitrarily created diary, with AI generated entries stored in a .csv file. The script for injecting this data appropriately into a PostgreSQL database with vector embeddings is provided, it enables context-aware responses to user queries.

πŸ–₯️ Gradio Web Interface

Gradio UI Demonstration Gradio UI Demonstration



⌨️ Command Line Interface

CLI Demonstration

Prerequisites

  • Python 3.8+
  • PostgreSQL 12+ with pgvector extension
  • OpenAI API key

Installation

  1. Clone this repository and change directory to its root folder:
git clone https://github.com/JoeCardoso13/diary_bot.git && cd diary_bot
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up PostgreSQL:

    • Install PostgreSQL if you haven't already
    • Install the pgvector extension:
      CREATE EXTENSION vector;
    • Create a database named diary_bot
  2. Add your OpenAI API key into your environment, e.g. an .env file with the following:

OPENAI_API_KEY=your_api_key_here
DB_NAME=diary_bot
DB_USER=your_psql_user_name
DB_HOST=/var/run/postgresql_or_localhost
DB_PORT=5432

Data Processing

Before using the system, you need to process the diary entries by running the pre_processing.py script:

python src/pre_processing.py

This will:

  • Read the CSV file
  • Generate embeddings for each entry
  • Store the data in the PostgreSQL database

Running the Application

Option 1: Web Interface

Run the Gradio interface for a user-friendly web experience:

python src/main_gradio_interface.py

This will:

  • Start a local web server
  • Open the interface in your default browser
  • Allow you to:
    • Ask questions about my hike
    • Get random question suggestions
    • See responses with source attribution

Option 2: Command Line Interface

Run the CLI version for a simpler interface:

python src/main_command_line.py

This provides:

  • A text-based interface
  • Same functionality as the web version
  • Responses in the terminal

Project Structure

diary_bot/
β”œβ”€β”€ data/
β”‚   └── diary.csv    # Blog entries data
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ pre_processing.py    # Data processing and embedding generation
β”‚   β”œβ”€β”€ rag_tools.py        # Shared RAG functionality
β”‚   β”œβ”€β”€ main_command_line.py # CLI interface
β”‚   └── main_gradio_interface.py # Web interface
β”œβ”€β”€ requirements.txt        # Python dependencies
└── README.md

Database Schema

The diary table contains:

  • id: Unique identifier
  • date: Date of diary entry
  • entry: Content of diary entry
  • embedding: Vector embedding of the entry text

About

A RAG based Diary Bot assistant with 2 interface options: web UI and CLI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages