This project implements a Retrieval-Augmented Generation (RAG) chatbot using LangChain and Hugging Face models. It fetches data from a Wikipedia article, creates a vector store using ChromaDB, and generates responses with a CodeLlama model.
- RAG Implementation: Uses LangChain to create a RAG pipeline.
- Wikipedia Data: Fetches data from a specified Wikipedia article.
- Chroma Vector Store: Stores document embeddings for efficient retrieval.
- Hugging Face Models: Uses Hugging Face embeddings and a CodeLlama language model.
- Gradio Interface: Provides a user-friendly chat interface.
- Customizable Parameters: Allows adjusting max output tokens and creativeness.
- Python 3.1x
- Pip
- A Hugging Face API key (set as the
HUGGINGFACE_API_KEYenvironment variable)
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
(Replace
<repository_url>and<repository_directory>with your repository's URL and directory.) -
Install dependencies:
pip install gradio langchain langchain-huggingface langchain-chroma python-dotenv requests sentence-transformers
-
Set the Hugging Face API key:
-
Create a
.envfile in the project's root directory. -
Add your Hugging Face API key to the
.envfile:HUGGINGFACE_API_KEY=your_huggingface_api_key(Replace
your_huggingface_api_keywith your actual API key.)
-
-
Run the application:
python app.py
- Run the
app.pyscript. - The Gradio interface will launch in your web browser.
- Enter your question in the chat input.
- The chatbot will generate a response based on the fetched Wikipedia data.
- Use the sliders to adjust the
Max output tokensandCreativenessof the responses
- Data Loading: The script loads data from a Wikipedia article using
WebBaseLoader. - Text Splitting: The loaded data is split into chunks using
RecursiveCharacterTextSplitter. - Vector Store: ChromaDB is used to create a vector store from the document chunks, using
HuggingFaceEmbeddings. - Language Model: A CodeLlama model from Hugging Face is used to generate responses.
- RAG Chain: LangChain's
RunnablePassthrough,PromptTemplate, andStrOutputParserare used to create the RAG pipeline. - Gradio Interface: Gradio's
ChatInterfaceis used to create the user interface.
- Remember to set your Hugging Face API key as an environment variable or in a
.envfile. - The Chroma database is persisted to the
./chroma_langchain_dbdirectory. - You can change the Wikipedia URL to use a different source.
- The
all-MiniLM-L6-v2andBAAI/bge-small-zh-v1.5models are used for embeddings. - The
codellama/CodeLlama-34b-Instruct-hfmodel is used for text generation.
Make sure to add the following to your .gitignore file to prevent unnecessary files from being committed: