This project aims to create a business context-aware customer assistant using Generative AI and Retrieval-Augmented Generation (RAG) techniques for Desi Bazar Agro. The assistant is built using Python, Flask, LangChain, ChromaDB, and OpenAI API.
- Python installed
Command to clone the repository:
git clone https://github.com/RyhanSunny/GenAI-RAG-Business-Context-Aware-Customer-Assistant-for-Desi-Bazar-Agro.git
- In the root directory run:
python -m venv venv
- Activate the virtual environment:
source venv/bin/activate
- For Windows:
venv\Scripts\activate
- Install the required dependencies:
pip install -r requirements.txt
To run the application, make sure the virtual environment is active and run the following command:
python run.py
The easiest way to run the application is by using Docker:
docker-compose up
- Python: Main programming language
- Flask: Web framework for API
- LangChain: Framework for LLM applications
- RetrievalQA: Implements RAG pattern
- PromptTemplate: Structures prompts
- ChromaDB: Vector database for embeddings; embedded instance of DuckDB
- OpenAI API:
- ChatGPT model: Generates responses
- Embeddings: Creates vector representations
- python-dotenv: Manages environment variables
- JSON: For configuration and API responses
- Text to embeddings (OpenAI)
- Store in ChromaDB
- Retrieve similar docs for query
- LangChain combines docs + query
- ChatGPT generates response
- Flask serves response
- HTML, CSS, and JavaScript: (
index.html
,style.css
,chat.js
)
- Python with Flask: (
backend_api.py
,app.py
,website.py
,run.py
) - Configuration: (
config.json
,requirements.txt
) - Docker setup: (
Dockerfile
,docker-compose.yml
) - Additional utilities: (
highlight.min.js
,highlightjs-copy.min.js
,icons.js
)
- backend_api.py: Loads environment variables and configuration, initializes the RAG chatbot, and sets up Flask routes.
- rag_chatbot.py: Initializes the ChromaDB client, sets up LangChain components, and provides methods for adding documents and querying.
- populate_db.py: Populates ChromaDB with initial data about Desi Bazar Agro.
- Install dependencies:
pip install -r requirements.txt
- Populate the database:
python populate_db.py
- Run the backend API:
python backend_api.py
- Build and run the Docker containers:
docker-compose up
Check the health of the application:
http://192.168.0.245:1338/health
- To clear and repopulate the database:
python populate_db.py --clear
- To add/update without clearing:
python populate_db.py
view_documents.py
is a diagnostic tool to verify the contents of the database.
- Context Awareness: Improve recognition of new conversation starters.
- Response Templates: Ensure the chatbot uses the exact response templates specified in the system prompt.
- Product Information: Ensure access to specific product information.
- Limited Context: Improve the context being used for responses.
- Create a system prompt that includes:
- Language guidelines
- Customer interaction guidelines
- Instructions for handling common inquiries (location, delivery fee, price list, general delivery)
- Invoice creation process
- Implement language detection and response formatting in the chatbot's code.
- Store the following in your vector database:
- Product information and pricing
- Delivery charges and areas
- Business overview and contact information
- Create functions or logic in your chatbot to handle:
- Formatting and sending invoices
- Sharing the WhatsApp catalog link
- Detecting and appropriately responding to "hm" as "how much"
Feel free to contribute to this project by forking the repository and creating pull requests. Your contributions are welcome!
MIT License