Skip to content

Source code for a RAG chatbot that can operate on a headless site

Notifications You must be signed in to change notification settings

koppieesq/koppiebot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koppiebot

A headless, retrieval augmented generation chatbot. Meant to operate alongside a headless blog, and provide context for the blog posts.

Installation

git pull origin main
pip install -r requirements.txt

Environment Variables

You will need to set the following environment variables:

  • OPENAI_API_KEY: Your OpenAI API key. Get one here
  • CERT_FILE_PATH: The path to your SSL certificate file. For example: cert.pem
  • KEY_FILE_PATH: The path to your SSL key file. For example: key.pem
  • ALLOW_ORIGINS: A comma-separated list of origins that are allowed to access the API. For example:
ALLOW_ORIGINS=http://localhost:3000,http://127.0.0.1:3000

If you experience CORS issues, add the following environment variables:

NODE_TLS_REJECT_UNAUTHORIZED=0
DANGEROUSLY_DISABLE_HOST_CHECK=true
REACT_APP_IGNORE_SSL=true

SSL Certificates

You will need to generate SSL certificates for your koppiebot instance. You can do this using Let's Encrypt or Certbot.

Using Certbot

sudo certbot certonly --standalone -d yourdomain.com

Local Development

If you are running koppiebot locally, you will need to generate SSL certificates for your local machine. You can do this using openSSL:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem

Running as a Linux Service

To run koppiebot as a systemd service on Linux:

  1. Create a systemd service file, e.g. /etc/systemd/system/koppiebot.service:
[Unit]
Description=Koppiebot Service
After=network.target

[Service]
Type=simple
User=YOUR_USERNAME
WorkingDirectory=/path/to/koppiebot
ExecStart=/usr/bin/python3 /path/to/koppiebot/main.py
Restart=on-failure

[Install]
WantedBy=multi-user.target
  1. Reload systemd and enable the service:
sudo systemctl daemon-reload
sudo systemctl enable koppiebot
sudo systemctl start koppiebot

Replace /path/to/koppiebot and YOUR_USERNAME as appropriate for your setup.

Updating

Koppiebot is not automatically updated; it relies on manual updates, thanks to the embed.py script. This script will do a fresh import from the blog, and then process all blog posts into a vector database, which is stored in embeddings.csv.

The script takes one argument, which is the URL of the CSV file to import. If no argument is provided, the default URL is used.

python3 embed.py --url https://d10.koplowiczandsons.com/export --primary body
systemctl restart koppiebot

Notes:

  • The embedding script takes about a minute to run (on an M4 processor)
  • koppiebot won't "know" the new information until the service is restarted

About

Source code for a RAG chatbot that can operate on a headless site

Topics

Resources

Stars

Watchers

Forks

Languages