Chatbot with Chainlit#
This example demonstrates a simple chatbot using Quivr and Chainlit, where users can upload a .txt
file and ask questions based on its content.
Prerequisites#
- Python: Version 3.8 or higher.
- OpenAI API Key: Ensure you have a valid OpenAI API key.
Installation#
-
Clone the repository and navigate to the appropriate directory:
git clone https://github.com/QuivrHQ/quivr cd examples/chatbot
-
Set the OpenAI API key as an environment variable:
export OPENAI_API_KEY='<your-key-here>'
-
Install the required dependencies:
pip install -r requirements.lock
Running the Chatbot#
-
Start the Chainlit server:
chainlit run main.py
-
Open your web browser and navigate to the URL displayed in the terminal (default:
http://localhost:8000
).
Using the Chatbot#
File Upload#
- On the chatbot interface, upload a
.txt
file when prompted. - Ensure the file size is under 20MB.
- After uploading, the file is processed, and you will be notified when the chatbot is ready.
Asking Questions#
- Type your questions into the chat input and press Enter.
- The chatbot will respond based on the content of the uploaded file.
- Relevant file sources for the answers are displayed in the chat.
How It Works#
-
File Upload:
- Users upload a
.txt
file, which is temporarily saved. - The chatbot processes the file using Quivr to create a "brain."
- Users upload a
-
Session Handling:
- Chainlit manages the session to retain the file path and brain context.
-
Question Answering:
- The chatbot uses the
ask_streaming
method from Quivr to process user queries. - Responses are streamed incrementally for faster feedback.
- Relevant file excerpts (sources) are extracted and displayed.
- The chatbot uses the
-
Retrieval Configuration:
- A YAML file (
basic_rag_workflow.yaml
) defines retrieval parameters for Quivr.
- A YAML file (
Workflow#
Chat Start#
- Waits for the user to upload a
.txt
file. - Processes the file and creates a "brain."
- Notifies the user when the system is ready for questions.
On User Message#
- Retrieves the "brain" from the session.
- Processes the user's question with Quivr.
- Streams the response and displays it in the chat.
- Extracts and shows relevant sources from the file.
Features#
- File Processing: Creates a context-aware "brain" from the uploaded file.
- Streaming Responses: Delivers answers incrementally for better user experience.
- Source Highlighting: Displays file excerpts relevant to the answers.
Enjoy interacting with your text files in a seamless Q&A format!