Table of Contents
Finance AIdvisor is an chatbot with access to financial advice documents from the Reddit Personal Finance wiki. It is designed to answer any questions about finance, but can also answer unrelated questions due to the initial training of the LLM and the web search tool. It is an agentic RAG system that utilizes large language models(LLM) to evaluate a user's query, a vector database to retrieve information related to the query, a web search tool to answer any query unrelated to the database, and again using the LLM to assess and assemble the context into an answer. The answer is then graded for hallucinations and if grounded, will output a response to the initial query. The frontend UI is extremely simple and built using Streamlit. The front end is connected to the backend using LangServe which is built on top of FastAPI. The backend architecture is built from the Langchain and Langgraph framework, Qdrant vector database, Voyager embedding model, and Cohere Command R+ and Llama3 for query answering and context filtering, respectively. The user can supply their own API keys to use different models as they choose. The application can be run locally using the Docker Compose file or deployed to Google Cloud Platform(GCP). The workflow trace is logged to LangSmith. User must provide their own vector database and subsequent documents for use.
This project's purpose is to demonstrate the usage of the above mentioned tools and has many areas for improvement in latency, accuracy, structure, and more.
Note: ALl APIs used are free, so rate limits will apply. GCP will incur charges, be aware when using.
└── finance_ai/
├── Dockerfile_gcp
├── Dockerfile_local
├── README.md
├── app
│ ├── __init__.py
│ ├── app.py
│ ├── backend.py
│ └── server.py
├── cloudbuild.yaml
├── docker-compose.yml
├── poetry.lock
├── pyproject.toml
├── start.sh
└── test
└──test.ipynb
root
File | Summary |
---|---|
Dockerfile_local | Dockerfile for running local version of the application. Add your own API keys to the ENV variables. Used in docker-compose.yml. |
cloudbuild.yaml | Automating Cloud-Native Deployment!This file enables automated deployment of a cloud-native application, leveraging Googles Cloud Build and Run services. It builds a Docker image from the local Dockerfile_gcp , pushes it to a Artifact Registry, deploys the app to Cloud Run, sets environment variables, and secures API keys for various integrations through Secrets Manager.Need to setup your own project and secrets in GCP and initiate gcloud cli before running. |
pyproject.toml | Configure dependencies for the finance_ai application using Poetry. This file defines essential packages such as Uvicorn, Langserve, Pydantic, and others to support AI-powered financial analysis and streamlit-based visualization tools within the repositorys architecture. |
Dockerfile_gcp | Dockerfile for Google Cloud Platform environment. Defines base image, installs Poetry package manager, and configures virtual environments. Copies application code, packages, and scripts to designated locations, and exposes ports. Initializes project with start script. Facilitates development on Google Cloud Platform. |
docker-compose.yml | Docker-compose file for easy local start up of the application. Simply run "docker-compose up" in terminal while Docker desktop is running to build dockerfile_local and run start.sh. Application will be accessible at localhost:8501. |
start.sh | Bash script to start backend and front end of the application. |
app
File | Summary |
---|---|
server.py | LangServe for serving backend to front end application. Using FastAPI to connect front end to back end. |
backend.py | Backend for the application that uses LangGraph to define nodes for agentic structure. Each node performs a different function such as Vector Database retrieval, Web Search, grading retrieved results, generating an answer, and grading the answer for hallucinations and relevancy to the query. These use a variety of tools such as LLMs, vector databases, |
app.py | Simple chat interface using Streamlit. Queries will be routed to the backend and answers will appear in the chat along with the sources used to generate the answer. |
test
File | Summary |
---|---|
test.ipynb | Test notebook for developing the backend. Example of creating vector database and uploading chunks to the database included within. Run each cell to understand the function of each node in the backend. |
System Requirements:
- Python, Docker, Google Cloud SDK(Optional)
Other Requirements:
- API keys to LLM, API Key to Vector Database with documents ingested
- Clone the finance_ai repository:
$ git clone https://github.com/tyw006/finance_ai
- Change to the project directory:
$ cd finance_ai
- Install the dependencies:
$ poetry install
Modify dockerfile_local with appropriate API keys per ENV variable.
Run finance_ai locally using Docker below:
$ docker-compose up -d
Access from browser:
localhost:8501
Google Cloud SDK must be initialized. Permissions for Cloud Build, Artifiact Registry, Secrets Manager, Cloud Run must be enabled. Edit cloudbuild.yaml with your own secrets. In the console:
gcloud builds submit --config cloudbuild.yaml .
- Based off of the Adaptive RAG article by Langchain: https://langchain-ai.github.io/langgraph/tutorials/rag/langgraph_adaptive_rag/
- Using Google Cloud Build/Run with Secrets Manager: https://ho3einmolavi.medium.com/how-to-use-secret-manager-in-google-cloud-build-gcp-eb6fad9a2d4a