This project is an information retrieval chatbot built using FastAPI and LangChain. It utilizes the OpenAI API for answering user queries based on a set of documents (PDF files). The chatbot can return context-aware answers, extract specific information from documents, and engage in friendly, human-like conversations with users.
- Document-based Q&A: The chatbot retrieves relevant information from uploaded documents (PDF format) and answers user queries.
- Social Interaction: The chatbot is able to respond to common social greetings like "Hi", "Hello", "How are you?", and more in a human-like and friendly manner.
- FastAPI-powered API: The project exposes an API endpoint for querying, which is built using FastAPI, a fast and modern web framework for Python.
- Customizable Instructions: The system allows setting an initial prompt for context that helps the AI assistant answer more effectively and in a natural tone.
- Python: 3.8 or higher
- Dependencies:
- FastAPI
- Uvicorn
- LangChain
- LangChain-OpenAI
- FAISS (for efficient vector-based search)
- python-dotenv
-
Clone this repository to your local machine:
git clone https://github.com/levietkhanh189/timo-info-bot-prototype cd timo-info-bot-prototype
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # For Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY="your_openai_api_key" # On Windows use `set` instead of `export`
-
Ensure that your PDF documents are placed in a
data
folder inside the project directory. -
Start the FastAPI server:
uvicorn main:app --reload
-
The API will be available at
http://127.0.0.1:8000
. You can check the health status of the API athttp://127.0.0.1:8000/healthcheck
.
-
POST
/ask
: Submit a query to the chatbot.- Request body:
{ "query": "Your question here" }
- Response:
{ "question": "Your question here", "answer": "Chatbot's answer", "source_documents": [List of documents referenced] }
- Request body:
-
GET
/healthcheck
: Check the health status of the server.- Response:
{ "status": "ok" }
- Response:
Example request:
curl -X POST "http://127.0.0.1:8000/ask" -H "Content-Type: application/json" -d '{"query": "What is the name of the author in the document?"}'
- This project is designed to retrieve information from PDF files placed in the
data
folder. You can easily extend it by adding more PDF documents or adapting the document loader. - The chatbot uses OpenAI’s language model to process the queries and provide natural-sounding responses.
- Make sure to keep your OpenAI API key secure, and do not expose it in public repositories.