This repository contains a FastAPI-based chatbot application that can handle user questions, provide responses based on a knowledge base, and maintain a conversation history. The application also includes an option to reset the conversation history.
- POST /ask: Handles user questions, interacts with a chatbot system, and provides appropriate responses.
- GET /: Returns a welcome message when accessing the root endpoint.
app/
├── chatbot/
│ ├── chatbot.py # Core chatbot logic, including the setup of RAG system with history
│ ├── __init__.py # Initialization file for the chatbot module
├── database_prep/
│ ├── database_preparation.py # This file is responsible for formatting scraped data and creating collated_text.txt
│ ├── Extraction.py # Scrapes data from the links provided and creates txt file for each link
│ ├── __init__.py # Initialization file for the database preparation module
├── data/
│ ├── collated_text.txt # Data file with extracted and formatted information
│ ├── summary.txt # Summary data in collated_text.txt used for the chatbot
├── text/ # Scraped tex data
├── .dockerignore # Specifies files and directories to be ignored by Docker
├── .gitignore # Specifies files and directories to be ignored by Git
├── api.py # Main FastAPI application with API endpoints
├── Dockerfile # Dockerfile for building the Docker image
├── entrypoint.sh # Entrypoint script for Docker container
├── heroku.yml # Heroku configuration file for deployment
├── README.md # Documentation for the repository
├── requirements.txt # Python dependencies
Handles the POST request to the /ask endpoint.
This function processes the user's question, interacts with the chatbot system, and returns a response. If the user inputs 'reset', it clears the chat history.
question: A string representing the user's question.
- 200 OK: Returns a response with the chatbot's answer to the user's question or a reset confirmation.
{
"question": "Who are you?"
}{
"response": "I am an intelligent assistant designed to guide users through tasks and provide information."
}- If the user enters
"reset"as the question, the chatbot's conversation history is cleared, and the response indicates that the history has been reset.
- HTTPException (500): If an error occurs while processing the request.
Handles the GET request to the root (/) endpoint.
This function returns a welcome message when the root endpoint is accessed.
- 200 OK: Returns a dictionary containing a welcome message and a health check status.
{
"message": "Welcome to the ChatBot with History API!",
"health_check": "OK"
}To build and run the application locally using Docker:
-
Build the Docker Image:
docker build -t chatbot . -
Run the Docker Container Locally:
docker run -p 8080:8080 chatbot
To deploy the application on Heroku, ensure you have the heroku.yml and Dockerfile set up properly, and push your code to Heroku using the git push heroku main command.
- Python 3.9
- FastAPI
- Uvicorn
- Docker
- LangChain
- Heroku CLI (for Heroku deployment)
-
Clone the repository:
git clone https://github.com/rohithsiddhartha/Chatbot.git
-
Navigate to the project directory:
cd CustomChatBot -
Install dependencies:
pip install -r requirements.txt
-
Setup OPENAI_API_KEY:
export OPENAI_API_KEY="your_openai_api_key"
-
Run the FastAPI server:
uvicorn api:app --reload
-
To setup OPENAI_API_KEY in Heroku
heroku config:set OPENAI_API_KEY="your_openai_api_key"
This project is licensed under the MIT License - see the LICENSE file for details.