Scrape a website for web content and pdfs and build a conversational ai chatbot from that knowledgebase.
This chatbot has conversational memory and can hold follow up conversations within the same session.
This code was tested on a WordPress Blog and as such has some logic that may not directly
work on other websites. However, that can be easily fixed by making some tweaks and you will
need to make some additional tweaks to suit your specific use cases.
Also, while this code can technically run on a computer without a GPU, running it on a GPU is recommended
since the RAG process can be very slow otherwise.
You will also need to change how you install llama-cpp-python
package depending on your OS and whether
you are planning on using a GPU or not.
- Install llama-cpp-python
- Install langchain
- Install streamlit
- Install beautifulsoup
- Install PyMuPDF
- Install sentence-transformers
- Install docarray
- Install pydantic 1.10.8
- Download Mistral from HuggingFace from TheBloke's repo: mistral-7b-instruct-v0.1.Q5_0.gguf
- Place model file in the
models
subfolder - Run streamlit
The setup assumes you have python
already installed and venv
module available.
- Download the code or clone the repository.
- Inside the root folder of the repository, initialize a python virtual environment:
python -m venv venv
- Activate the python envitonment:
source venv/bin/activate
- Install required modules (
langchain
,llama.cpp
, andstreamlit
along withbeautifulsoup4
,pymypdf
,sentence-transformers
,docarray
, andpydantic 1.10.8
):
pip install -r requirements.txt
- Create a subdirectory to place the models in:
mkdir -p models
- Download the
Mistral7b
quantized model fromhuggingface
from the following link: mistral-7b-instruct-v0.1.Q5_0.gguf - Start
streamlit
:
streamlit run main.py