https://github.com/Omar-Karimov/BankLLM
BankLLM is an AI-driven recommendation engine designed for banking applications. The project analyzes customer data from a mobile banking application to generate personalized product recommendations using OpenAI's advanced models. The system integrates various modern tools and practices to ensure a robust, scalable, and user-friendly experience, following an LLMOps approach to manage the lifecycle of large language models.
BankLLM leverages artificial intelligence to provide personalized banking product recommendations based on both customer financial data and available banking products stored in a MySQL database. The project uses OpenAI's models through LangChain and LangServe to create a sophisticated recommendation engine that analyzes customer data and suggests relevant banking products, enhancing the overall customer experience.
The system is built with FastAPI for the backend, Streamlit for the frontend, and integrates monitoring tools like LangSmith to track performance and optimize the recommendation process. This project follows an LLMOps methodology, which focuses on the operationalization and lifecycle management of large language models in production.
The architecture of BankLLM is designed to be modular, scalable, and easy to manage. It consists of the following components:
MySQL Database:
Data Retrieval:
FAISS Vector Store:
Backend API (FastAPI + LangServe):
Frontend Interface (Streamlit):
LangChain Sequential Chain:
Monitoring & Analytics (LangSmith):
+--------------------------+ | MySQL Database | # Stores Customer & Product Data | (Customer & Product Data)| +--------------------------+ | | v +----------------------------+ | Fetch Data from MySQL | # Automatically on App Start | (Customer & Product Data) | +----------------------------+ | | v +-----------------------+ | Customer Data Embedding| | & Storage in FAISS | | Vector DB | +-----------------------+ | | v +----------------------+ | Backend API (FastAPI) | # API Interface for Client-Server Communication | + LangServe | # Handles LangChain Processing +----------------------+ | | v +----------------------+ | GET Request: | # Retrieve Customer IDs for Selectbox | Retrieve Customer IDs| (Streamlit) +----------------------+ | | v +-------------------------+ | Frontend Interface | # Streamlit Interface | (Streamlit) | # Customer Selection and Recommendation Display +-------------------------+ | | v +-----------------------+ | POST Request: | # Generate Recommendation using LangChain Sequential Chain | Generate Recommendation| - Data Analyst Chain +-----------------------+ - Recommendation Specialist Chain | | v +------------------------+ | Display Final | # Display Final Recommendation in Streamlit | Recommendation | +------------------------+ | | v +------------------------+ | Monitoring & Analytics | # LangSmith Monitoring for Performance | (LangSmith) | +------------------------+
The BankLLM project uses detailed customer and product data from a mobile banking application to generate recommendations. Below is the schema and description of each key field:
BankLLM utilizes LangChain and LangServe to power its recommendation engine. The recommendation process is managed through two primary chains:
Data Analyst Chain: This chain is responsible for analyzing the customer’s financial data, identifying key metrics, patterns, and potential needs based on the customer’s transaction history and financial profile.
Recommendation Specialist Chain: Based on the analysis provided by the Data Analyst Chain, this chain generates specific product recommendations that align with the customer’s financial needs and goals.
The models used by these chains are deployed and served using LangServe, ensuring efficient and scalable model serving.
The project integrates FAISS as a vector database to store and retrieve customer information efficiently. FAISS, paired with OpenAIEmbeddings, enables fast similarity searches within the customer data, ensuring that the most relevant customer information is retrieved and analyzed for product recommendations.
text-embedding-ada-002
model, which transforms textual data into high-dimensional vectors.SequentialChain
for analysis and recommendation generation.BankLLM/ │ ├── src/ │ ├── app.py # FastAPI application file │ ├── client.py # Streamlit client interface │ ├── config.py # Configuration file for environment variables │ ├── db_connect.py # Script for database connections and data fetching │ └── requirements.txt # Python dependencies for the project │ ├── data/ # Data Generation and SQL Scripts │ ├── faker_data.py # Script to generate synthetic customer data │ ├── inserting_data.py # Script to generate SQL INSERT statements for customer data │ ├── customer_profile_insert_statements.sql # SQL script for creating and inserting customer profile data │ ├── products_insert.sql # SQL script for creating and inserting product data │ ├── customer_profile.json # JSON file storing fetched customer profile data │ ├── products.json # JSON file storing fetched product data │ ├── docs/ # Project documentation and visual demonstrations │ ├── mysql.png # Screenshot of MySQL customer profile table │ ├── mysql_products.png # Screenshot of MySQL products table │ ├── langsmith.png # Screenshot of LangSmith trace monitoring │ ├── langsmith_monitor.png # Screenshot of LangSmith monitoring │ ├── api.png # API Documentation screenshot │ ├── client_streamlit.png # Streamlit client recommendation example │ ├── README.md # Project README
git clone https://github.com/Omar-Karimov/BankLLM.git cd BankLLM
conda create -n bankllm python=3.10 -y conda activate bankllm
pip install -r requirements.txt
Create a .env file:
.env
file in the src/
directory to store their API keys and configuration details. This file should include the necessary environment variables such as API keys, database credentials, and any other configurations required for the project.LangSmith Account:
.env
file along with other environment variables.uvicorn app:app --reload
streamlit run client.py
http://localhost:8501
You can access the API documentation at:
http://127.0.0.1:8000/docs
This includes the following endpoints:
GET /customers
- Retrieves a list of all customer IDs. This endpoint is typically used to populate the customer selection dropdown in the Streamlit interface.
POST /recommendation
- Generates a bank product recommendation for a specified customer ID. This endpoint triggers the LangChain process, which analyzes customer data and provides tailored product suggestions.