https://github.com/brucewind/knowledgebase-chat
RAG + openai to chat with a knowledgebase.
https://github.com/brucewind/knowledgebase-chat
ai ai-support customer-support customer-support-ai openai product-recommendation-with-ai rag
Last synced: 7 months ago
JSON representation
RAG + openai to chat with a knowledgebase.
- Host: GitHub
- URL: https://github.com/brucewind/knowledgebase-chat
- Owner: BruceWind
- License: gpl-3.0
- Created: 2024-09-04T04:20:31.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-05T12:18:34.000Z (about 1 year ago)
- Last Synced: 2025-01-26T18:47:02.494Z (9 months ago)
- Topics: ai, ai-support, customer-support, customer-support-ai, openai, product-recommendation-with-ai, rag
- Language: Python
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RAG-Powered Chat Application
This project implements a Retrieval-Augmented Generation (RAG) system with OpenAI integration, featuring document upload capabilities and a streaming chat API.
## Features
- Document upload and processing for RAG
- Streaming chat API with OpenAI integration
- FastAPI-based web server## Installation
1. Install **tesseract-ocr** and Clone the repository.
- For macOS, use Homebrew: `brew install tesseract`
- For ubuntu: `sudo apt-get update && sudo apt-get install tesseract-ocr`2. Create a virtual environment and activate it:
```
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install --no-build-isolation faiss-cpu==1.7.2
```Click to expend: If you suffer an error: `Failed to build faiss-cpu` from this step:
The error is related to building the faiss-cpu package, which requires SWIG. Here's a quick guide to resolve this issue:
1. Install SWIG:- For macOS, use Homebrew: `brew install swig`
- For ubuntu: `sudo apt-get update && sudo apt-get install build-essential swig libopenblas-dev`2. or, SWIG does not work
- you can try using Anaconda/Miniconda. However, I dont want to put much tutorial here.
2. After installing SWIG, try installing the requirements again:
```
pip install -r requirements.txt
```3. If issues persist with faiss-cpu, try using a pre-built wheel:
- In requirements.txt, replace `faiss-cpu==1.7.2` with `faiss-cpu==1.7.2 --only-binary :all:`4. Alternatively, use faiss-cpu from conda:
- Install Miniconda or Anaconda
- Create a new conda environment: `conda create -n your_env_name python=3.8`
- Install faiss-cpu: `conda install -c conda-forge faiss-cpu`
- Install other requirements: `pip install -r requirements.txt`3. Start the server:
> Create a .env file:
Create a file named `.env` in the root directory of the project and add the following content:
```
OPENAI_API_BASE=https://XXXXX/v1
OPENAI_API_KEY=your_api_key_here
```Following that, run this command:
```
python -m venv venv
source venv/bin/activate
uvicorn app:app --host 0.0.0.0 --port 8000
```The server will run on `http://localhost:8000`
## API Endpoints:
- POST `/upload`: Upload a document for processing
- Parameters:
- `file`: The document file to upload
- `doc_type`: (Optional) The type of the document
- Returns:
- `lib_id`: A unique identifier for the uploaded document's RAG instance
- POST `/chat`: Send a chat message and receive a streaming response
- Parameters:
- `message`: The chat message to process
- `lib_id`: The unique identifier of the RAG instance to use for this chat## Usage Example:
1. Upload a document:
```
curl -X POST -F "file=@your_document.pdf" -F "doc_type=pdf" http://localhost:8000/upload
```
This will return a `lib_id` in the response.2. Chat using the uploaded document:
```
curl -X POST -F "message=Your question here" -F "lib_id=the_lib_id_from_upload" http://localhost:8000/chat
```
Replace `the_lib_id_from_upload` with the actual `lib_id` received from the upload response.## Acknowledgements
- [FastAPI](https://fastapi.tiangolo.com/)
- [OpenAI](https://openai.com/)
- [Uvicorn](https://www.uvicorn.org/)
- [RAG (Retrieval-Augmented Generation)](https://arxiv.org/abs/2005.11401)