I built a GPT Investment Banker using this 312 PAGE document
Science & Technology
Introduction
In the era of artificial intelligence, leveraging your own documents can significantly enhance the capabilities of large language models (LLMs). Recently, I embarked on a journey to build a personal AI-powered investment banker using Streamlit and a banking annual report. In this article, I’ll share how you can replicate my results without the need for fine-tuning, all while analyzing a comprehensive 312-page document.
Why Use Your Own Documents?
Using personal documents allows for greater flexibility and precision in tasks tailored to your needs. For instance, you can provide meeting minutes and request a summary, upload an assignment outline for a generated response, or analyze financial statements from an annual report. By utilizing your documents, you create an AI that better understands your specific context.
Getting Started
To initiate this project, you’ll first need to install some essential dependencies. These include Langchain, OpenAI, Streamlit, ChromaDB, PDF file loaders, and others. Additionally, an OpenAI API key is needed; however, it can be substituted with Llama CPP or various Hugging Face models if you prefer.
Required Libraries
- Install the following libraries:
- Langchain
- OpenAI
- Streamlit
- ChromaDB
- Pi PDF and Crypto Dome
Initial Setup
Create a Python file named app.py
and import your dependencies. You will set the OpenAI API key and create the OpenAI service. Keep in mind that you can adjust the temperature of the model based on how creative or objective you wish your responses to be. To gather user input, use Streamlit's text input element.
import os
from langchain.llms import OpenAI
import streamlit as st
## Introduction
os.environ["OPENAI_API_KEY"] = "your-api-key"
llm = OpenAI(temperature=0.5)
## Introduction
prompt = st.text_input("Enter your query here:")
if st.button('Submit'):
response = llm(prompt)
st.write(response)
Loading Your Document
To analyze your own document, you need to enhance the initial script. Import additional dependencies for loading and querying your PDF:
from langchain.document_loaders import PyPDFLoader
from chromadb import Chroma
Now, load your banking annual report and employ Chroma to perform similarity searches within the document. This will help return relevant segments based on your query.
Load the document:
pdf_loader = PyPDFLoader("banking_annual_report.pdf")
documents = pdf_loader.load_documents()
vector_store = Chroma.from_documents(documents)
Integrating with Langchain
We can delve deeper by integrating the vector storage mechanisms and create a Vector Store Agent. To do this, you need a few more imports:
from langchain.agents import create_vector_store_agent, VectorStoreToolkit
from langchain.agents.agent_toolkits import VectorStoreInfo
Finally, wrap everything together and run the agent with your queries:
vector_store_info = VectorStoreInfo(
name="Banking Report",
description="A comprehensive analysis of the bank's annual performance.",
vector_store=vector_store
)
toolkit = VectorStoreToolkit(vector_store_info)
agent = create_vector_store_agent(llm, toolkit)
if st.button('Ask'):
result = agent.run(prompt)
st.write(result)
Testing the Investment Banker
You can now pose questions such as:
- What was the net profit of the company?
- What initiatives did the bank take towards sustainability?
- Summarize the financial performance of the bank.
The model will return accurate information drawn from the 312-page document, providing actionable insights as if you were consulting an investment banker.
Conclusion
In just a few lines of code, we successfully created a personal investment banker powered by AI. This illustrates the capability of modern LLMs when coupled with your own documents. If you want to experience this firsthand, feel free to check the linked resources for a comprehensive guide.
Keywords
- AI
- Investment Banker
- Langchain
- OpenAI
- Streamlit
- ChromaDB
- Financial Analysis
- Document Loading
- Similarity Search
FAQ
Q1: What is Langchain?
A1: Langchain is a framework that facilitates the creation of applications powered by large language models, allowing for customization and enhancement with specific documents.
Q2: Do I need extensive programming knowledge to build this?
A2: Basic knowledge of Python is sufficient to follow the setup and build your own AI application as described in this article.
Q3: Can I use other models besides OpenAI?
A3: Yes, you can substitute the OpenAI service with other models such as Llama CPP or those hosted on Hugging Face.
Q4: Is there any limit to the size of the document I can upload?
A4: While the process can handle large documents, the speed of response may vary based on the document's length and complexity. It’s recommended to keep documents manageable for quicker analysis.
Q5: What practical uses can this AI Investment Banker serve?
A5: It can be utilized for a variety of purposes, including financial analysis, report summarization, performance metrics extraction, and stakeholder communications.