Git Product home page Git Product logo

ai-chatbots's Introduction

Overview

A simple demo ChatBot application that provides both an LLM and a RAG (Retrieval-Augmented Generation) based Chatbot to interact with a locally running LLM (Large Language Model).

Warning
Currently this is relatively unoptimized with certain inefficiencies regarding working with embeddings. This will be speeded up in future releases.

With relevant embeddings the RAG Chatbot will answer queries on Red Hat OpenShift AI and Red Hat Open Data Science (ODS) that the pure LLM-based Chatbot will struggle with.

rag bot screen 01

System setup

The local system needs to be prepared before running the ChatBot application.

Pre-requisites

Make sure your system is enabled with git and Podman (v5.0).

Clone repository

1) Create a new directory (e.g. ai-rag)

2) Clone the repository inside the new directory

 $ mkdir ai-rag
 $ cd ai-rag
 $ git clone https://github.com/rhpds/ai-chatbots.git

Run LLM Locally

1) Install the LLM runtime Ollama from here or follow the instructions in the installation guide.

2) Start Ollama running on your local machine either via the Ollama App you downloaded or via the command line ollama serve.

3) In a separate terminal window, launch the the mistral LLM

$ ollama run mistral
Note
The first time this will download the 'mistral' LLM and may take a few minutes. mistral is approximately 4GB in size.

Running the ChatBot application

There are two methods to run the ChatBot application:

  1. Run in a container (easier method)

  2. Run using Python

Note
Older or low-memory machines may have performance issues running the application. Ideally a relatively recent laptop, or machine, with at least 32GB of RAM locally.

Method 1: Running the Application using Podman (or Docker)

This is the recommended way to run the ChatBot application.

podman run --rm \
   --name ragbot \
   -e OLLAMA_BASE_URL="http://host.docker.internal:11434" \
   -p 7001:7001 \
   -p 7002:7002 \
   -p 7003:7003 \
   tonykay/ai-rag-chatbot:0.6.6
  1. Browse to your Chatbot of Choice - or both

Landing Page URL

LLM Chatbot (no RAG)

http://localhost:7001

RAG Chatbot

http://localhost:7002

Both Chatbots side-by-side

http://localhost:7003

Method 2: Running the Application locally via Python

This method requires Python 3.11 or higher and assumes you will use a virtual environment, or venv, called venv-chatbot to install the dependencies.

  1. Create a Python Virtual Environment (venv) venv for the Python dependencies

    python -m venv venv-chatbot
    Note
    This will create a new directory called venv-chatbot in your current working directory. git will ignore this directory by default as it is already added to your .gitignore.
  2. Activate your new venv:

    source venv-chatbot/bin/activate
    Note
    Your prompt should now show (venv-chatbot) to indicate the virtual environment is active. However, this may vary depending on your shell.
  3. Install the dependencies using the requirements file. First:

    python -m pip install -r requirements.txt
    Sample Output (Your output may differ and include a message about upgrading pip)
    <TRUNCATED>
    
    asn1-0.5.1 pyasn1-modules-0.3.0 pydantic-2.6.3 pydantic-core-2.16.3 pyjwt-2.8.0 pymupdf-1.23.26 pypika-0.48.9 pyproject_hooks-1.0.0 python-dateutil-2.9.0.post0 python-dotenv-1.0.1 python-engineio-4.9.0 python-graphql-client-0.4.3 python-multipart-0.0.6 python-socketio-5.11.1 regex-2023.12.25 requests-2.31.0 requests-oauthlib-1.3.1 rsa-4.9 safetensors-0.4.2 scikit-learn-1.4.1.post1 scipy-1.12.0 sentence_transformers-2.5.1 simple-websocket-1.0.0 six-1.16.0 sniffio-1.3.1 starlette-0.32.0.post1 sympy-1.12 syncer-2.0.3 tenacity-8.2.3 threadpoolctl-3.3.0 tiktoken-0.6.0 tokenizers-0.15.2 tomli-2.0.1 torch-2.2.1 tqdm-4.66.2 transformers-4.38.2 typer-0.9.0 typing-extensions-4.10.0 typing-inspect-0.9.0 uptrace-1.22.0 urllib3-2.2.1 uvicorn-0.25.0 uvloop-0.19.0 watchfiles-0.20.0 websocket-client-1.7.0 websockets-12.0 wrapt-1.16.0 wsproto-1.2.0 yarl-1.9.4 zipp-3.17.0
  4. Run the application:

    ./entrypoint.sh
    Sample Output
    <TRUNCATED>
    
    2024-03-25 06:48:52 - Use pytorch device_name: mps
    2024-03-25 06:48:54 - Anonymized telemetry enabled. See                     https://docs.trychroma.com/telemetry for more information.
    File path is /Users/tok/Dropbox/PARAL/Projects/redhat-rag-demo/ai-chatbots/chatbot-rag/rag-persist/record_manager_cache.sql
    Indexing stats: {'num_added': 334, 'num_updated': 0, 'num_skipped': 0, 'num_deleted': 0}
    2024-03-25 06:49:01 - Your app is available at http://localhost:7002
    huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...
    To disable this warning, you can either:
            - Avoid using `tokenizers` before the fork if possible
            - Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)
    ::1 - - [25/Mar/2024 06:49:51] "GET grv/ HTTP/1.1" 200 -
  5. Browse to http://localhost:7003 to access the application. The right hand iFrame will show the RAG Chatbot and the left hand iFrame will show the LLM Chatbot.

Note
The LLM Chatbot is available at http://localhost:7001 and the RAG Chatbot is available at http://localhost:7002 if you prefer to use them separately. And that RAG Chatbot can take a few moments to start.

Using the Application

The application is a simple web interface that allows you to ask questions about Red Hat OpenShift AI and Red Hat Open Data Science (ODS). The application will use the locally running LLM and RAG to answer your questions.

Note
The first time you ask a question it may take a few seconds to respond as the application will need to generate embeddings for the question and the documents in the database.

Sample Questions (examples)

  1. What is Red Hat ods

  2. What is rh ods?

Development

TBD

Architecture

  • chainlit

  • LangChain

  • chromadb - Chroma Database Vector Store to store and retrieve document chunks

  • Hugging Face sentance_transformers - embeddings * * *

Running with a bind mount (Work in Progress)

Podman and Docker differ,

Docker cmd:

Podman cmd:

Add --uidmap 1000:0:1 --uidmap 0:1:1000

podman run --uidmap 1000:0:1 --uidmap 0:1:1000 --rm --name ragnar -e OLLAMA_BASE_URL="http://host.docker.internal:11434" -v $(pwd):/home/user/app -p 7861:7860 tonykay/ai-rag-chatbot:0.1.0

*

ai-chatbots's People

Contributors

tonykay avatar ishuverma avatar rhjcd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.