@ravitheja thanks for taking a look at this
System prompt (you can prob skip this)
SYSTEM_PROMPT = "You are AskGeorge, an expert personal financial helper with context about my checking and\
saving account balances. The date today is 2023-10-08 (8th of October, 2023). If I ask you how\
much money I have all together, add the latest entries from my current account to my savings account. You are almost always talking\
about money or percentage changes, the currency is euros, so when you format numbers make \
sure to add the currency sign and if it's a decimal number make it 2 decimal points. Use chain of thought reasoning to make sure you're answering what the user is actually asking. \
Be conversational and informative in your responses. For example, when asked 'How much has my savings account \
grown in the last 3 months', you will respond along the lines of 'Your savings account grew \
X euros, from Y to Z, which is a A% increase. Well done!'"
building the agent + engines (yes, I'm using PandasQueryEngine) Important parts here are spending_engine and spending_df, that's what is having the issues rn
# build agent
llm = OpenAI(model="gpt-4", temperature=0)
service_context = ServiceContext.from_defaults(llm=llm)
# build balance engine
balance_df = getBalancePandas()
balance_engine = PandasQueryEngine(
balance_df,
service_context=service_context,
verbose=True,
)
# build spending engine
spending_df = getSpendingPandas()
spending_engine = PandasQueryEngine(
spending_df,
service_context=service_context,
verbose=True
)
query_engine_tools = [
QueryEngineTool(
query_engine=balance_engine,
metadata=ToolMetadata(
name="balance_pandas_df_tool",
description="Useful for translating a natural language query into a Pandas query over a dataframe containing the end of day balance of my checkings and savings account for a range of dates. It is extremely important that nothing is put after the Pandas query is outputted. df.columns: Index(['id', 'checkingAccountBalance', 'savingsAccountBalance'], dtype='object') and this is df.index: DatetimeIndex(['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', ...., '2023-10-07', '2023-10-08'], dtype='datetime64[ns]', name='date', length=281, freq=None)"
),
),
QueryEngineTool(
query_engine=spending_engine,
metadata=ToolMetadata(
name="spending_pandas_df_tool",
description="Useful for translating a natural language query into a Pandas query over a dataframe containing my monthly spending breakdown. It is extremely important that nothing is put after the Pandas query is outputted. The two columns are 'breakdown' and 'total'. df['breakdown']['01/2023']['transport'] will give you the breakdown of spending in the transport category for January 2023. df['total']['02/2023]['Total'] will give you the total spending for that month. The pandas dataframe is MultiIndex. If you're querying the Pandas df and extract data using loc, add a .apply(pd.Series) after your query to make things easier to analyze and so that data isn't concatenated"
),
),
]
Agent
agent = OpenAIAgent.from_tools(
query_engine_tools,
llm=llm,
verbose=True,
system_prompt=SYSTEM_PROMPT
)
def DataAgent(query_text):
response = agent.chat(query_text)
return response