Chatbot trained to answer specific requests about a document using PyTorch and RAG (Retrieval Augmented Generation) technique.
Prerequisites:
- Install Ollama: You need to install Ollama previously from their official website: https://ollama.com/
- Download a Local Model: Download the LLM model you want to run locally using Ollama.
Setup:
pip install -r requirements.txt
Usage:
upload.py: This script takes a PDF or JSON file, cleans it, and transforms it into avault.txtfile. This file is used to feed information to the LLM for the RAG process.server.py: This is the main application file. It uses the OpenAI API, runs the selected LLM model locally (via Ollama) and create a Flask server to make requests from an application.
-
Modify the system message to align with your specific use case. This helps guide the LLM's overall behavior and persona.
-
Redefine the prompt within the
rewrite_queryfunction. -
Adjust the
top-kparameter inget_relevant_contextfunction
- Higher
top-kvalues: Your model will incorporate more contextual information. This can lead to more accurate and comprehensive answers, but it will generally increase the response time. - Lower
top-kvalues: Your model will prioritize speed by limiting the context it considers. This is ideal for applications where real-time responses are critical, though it might occasionally result in less detailed answers.