A powerful Retrieval-Augmented Generation (RAG) chatbot service built with FastAPI and LangChain.
- Document ingestion and processing
- Vector-based semantic search
- Conversational memory
- RESTful API endpoints
- Document upload support
- Health check endpoint
- Python 3.12 or higher
- OpenAI API key
- Clone the repository:
git clone <repository-url>
cd chatbot-v2- Create a virtual environment and activate it:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -e .- Create a
.envfile in the root directory with the following content:
OPENAI_API_KEY=your_openai_api_key_here
MODEL_NAME=gpt-3.5-turbo
EMBEDDING_MODEL=text-embedding-3-small
CHROMA_PERSIST_DIRECTORY=./data/chroma
Start the FastAPI server:
uvicorn app.main:app --reloadThe API will be available at http://localhost:8000
-
POST /chat: Send a message to the chatbot{ "message": "Your question here" } -
POST /upload: Upload a document for processing- Use multipart/form-data with a file field named "file"
-
GET /health: Check the API health status
Once the server is running, you can access the interactive API documentation at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
chatbot-v2/
├── app/
│ ├── __init__.py
│ ├── main.py
│ ├── config.py
│ ├── rag_chain.py
│ └── vector_store.py
├── data/
│ └── chroma/
├── uploads/
├── .env
├── pyproject.toml
└── README.md
Feel free to submit issues and enhancement requests!
The following code block was added to the main.py file:
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
def serve_ui(request: Request):
return templates.TemplateResponse("index.html", {"request": request})