Chatbot access on HuggingFace: Link to Space
Develop a generative Q&A chatbot that provides factual answers to user queries by referring to a knowledge base created from the PDF files of financial reports from major public companies. The chatbot should use proper grounding techniques to minimize hallucinations and ensure the accuracy of the information.
- Develop a generative Q&A chatbot capable of answering questions related to financial reports of large public companies.
- The chatbot should utilize a knowledge base derived from the provided PDF files of financial reports.
- Ensure the chatbot is grounded in the knowledge base to minimize hallucinations and provide accurate responses.
Use PDF files containing financial reports from major public companies:
For more information about the experiments, please refer to the Experiment Report.
- Query Rewriting
- Query Expansion
- Recursive Text Splitter
- Chunking and Processing data with UNSTRCUCTRED.io
- Splitting documents via SemanticChunker
- Reranking
- prompt compression and rank relevant docs
- Nemo Gaurdrailings
- RAGAS Evaluation
- Backend: HTTP Server for serving the backend API.
- Frontend: Gradio for an interactive user interface.
- Cloud Services: Amazon Web Services (AWS) for deployment.
- CI/CD: GitHub Actions for Continuous Integration, Continuous Delivery, and Continuous Deployment.
- RAG Model Evaluation: RAGAS Library for model evaluation.
- Model Monitoring: LangchainSmith for model monitoring.
- Language Models: GPT-3.5-Turbo, LLaMA3-70B-8192, and Mixtral-8x7B-32768.
- Data Version Control: DVC for storing documents and vector databases in an AWS S3 bucket.
- Containerization: Docker for containerizing applications.
- Container Orchestration: Docker Compose for defining and running multi-container Docker applications.
- Guardrails: Nemo GuardRails for implementing safety and compliance measures in AI models.
You can directly test the Chatbot here
https://huggingface.co/spaces/sxandie/RAGFinanceChatbot
-
Clone the project:
https://github.com/xandie985/RAGFinanceChatBot.git
-
Create a
.env
file in thefrontend/src/.env
folder with the following content:HF_TOKEN= OPENAI_API_KEY= GROQ_API_KEY= LANGCHAIN_API_KEY= PINECONE_API_KEY=
-
Open Docker Desktop application.
-
Build the Docker container:
docker-compose build
-
Run the Docker container:
docker-compose up
-
Open your preferred browser and navigate to http://localhost:8000/ & http://localhost:7860/to start using the application.
-
frontend/: Contains files related to the Gradio-based frontend application, including the main script (
app.py
), configuration files, data, and Dockerfile. -
backend/: Includes the backend server for handling API requests, with the main script (
serve.py
), configuration files, requirements, and Dockerfile. -
notebooks/: Contains Jupyter notebooks for experimentation, including initial assumptions, data processing, and testing.
-
pytest/: Directory for pytest with example test files.
-
docker-compose.yaml: Configuration file for defining and running multi-container Docker applications.
-
.dvc/: Contains DVC configuration files for data version control, including
.gitignore
andconfig
.
π¦
ββ .dvc
β ββ .gitignore
β ββ config
ββ .dvcignore
ββ .github
β ββ workflows
β ββ main.yml
ββ .gitignore
ββ HELPER.md
ββ README.md
ββ backend
β ββ Dockerfile
β ββ configs
β β ββ app_config.yml
β ββ requirements.txt
β ββ serve.py
ββ docker-compose.yaml
ββ frontend
β ββ Dockerfile
β ββ app.py
β ββ configs
β β ββ app_config.yml
β ββ data
β β ββ docs
β β β ββ alphabet-2023.pdf
β β β ββ microsoft-2023.pdf
β β ββ vectordb
β β ββ processed
β β ββ chroma
β β ββ chroma.sqlite3
β β ββ f926420f-492c-48a8-a50b-448a3a18a87a
β β ββ data_level0.bin
β β ββ header.bin
β β ββ index_metadata.pickle
β β ββ length.bin
β β ββ link_lists.bin
β ββ images
β β ββ chatbot.png
β β ββ user.png
β ββ requirements.txt
β ββ src
β ββ __init__.py
β ββ finbot.py
β ββ load_config.py
β ββ prepare_bgesmall_vectordb.py
β ββ prepare_openAIEmbeddings_vectordb.py
β ββ ui_settings.py
β ββ upload_data_manually.py
β ββ upload_file.py
ββ log.txt
ββ notebooks
β ββ config
β β ββ config.yml
β ββ langsmith_groq_openaiembed.ipynb
β ββ processed_data
β β ββ chroma.sqlite3
β β ββ f01ca3c9-e477-42c2-a127-6c44abc22708
β β ββ data_level0.bin
β β ββ header.bin
β β ββ index_metadata.pickle
β β ββ length.bin
β β ββ link_lists.bin
β ββ test.ipynb
ββ pytest
ββ dummy_test.py
The below steps followed to do perform deployment. Note: I used my AWS account for deployment but have since removed all resources to avoid incurring charges.
#with specific access
1. EC2 access : It is virtual machine
2. ECR: Elastic Container registry to save your docker image in aws
#Description: About the deployment
1. Build docker image of the source code
2. Push your docker image to ECR
3. Launch Your EC2
4. Pull Your image from ECR in EC2
5. Lauch your docker image in EC2
#Policy:
1. AmazonEC2ContainerRegistryFullAccess
2. AmazonEC2FullAccess
- Save the URI:
#optinal
sudo apt-get update -y
sudo apt-get upgrade
#required
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker ubuntu
newgrp docker
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION = us-east-1
AWS_ECR_LOGIN_URI =
BACKEND_ECR_REPOSITORY_NAME=
FRONTEND_ECR_REPOSITORY_NAME=
These tests ensure that the code handles different scenarios correctly:
- Producing valid results for correct input ranges. Run the tests:
pytest
The dataset & Vector database has been added to the AWS S3 bucket. Managing Data Versions with DVC
To manage the data versions with DVC using the below commands:
- Add a remote storage:
dvc remote add -d myremote s3://mybucket
- Set your AWS credentials:
export AWS_ACCESS_KEY_ID='myid' export AWS_SECRET_ACCESS_KEY='mysecret'
- Push your data to the remote storage:
dvc push
- Searching for Best Practices in Retrieval-Augmented Generation
- Python LangChain Documentation
- LangChain LangSmith
- RAGAS Evaluation
- NeMo-Guardrails
The project was developed by Sandeep Kumar Kushwaha. Connect with me on LinkedIn.