From 590a0d217c762c0fdf3ef3166ea521425db80efc Mon Sep 17 00:00:00 2001 From: Madhu Shantan Date: Mon, 17 Mar 2025 19:11:22 +0530 Subject: [PATCH] Update investment_agent.py --- .../ai_investment_agent/investment_agent.py | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/ai_agent_tutorials/ai_investment_agent/investment_agent.py b/ai_agent_tutorials/ai_investment_agent/investment_agent.py index 6231508..699c2cc 100644 --- a/ai_agent_tutorials/ai_investment_agent/investment_agent.py +++ b/ai_agent_tutorials/ai_investment_agent/investment_agent.py @@ -1,31 +1,34 @@ -# Import the required libraries import streamlit as st from agno.agent import Agent from agno.models.openai import OpenAIChat from agno.tools.yfinance import YFinanceTools -# Set up the Streamlit app st.title("AI Investment Agent 📈🤖") st.caption("This app allows you to compare the performance of two stocks and generate detailed reports.") -# Get OpenAI API key from user openai_api_key = st.text_input("OpenAI API Key", type="password") if openai_api_key: - # Create an instance of the Agent - agent = Agent( - llm=OpenAIChat(model="gpt-4o", api_key=openai_api_key), - tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)], + assistant = Agent( + model=OpenAIChat(id="gpt-4o", api_key=openai_api_key), + tools=[ + YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True) + ], show_tool_calls=True, - markdown=True + description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.", + instructions=[ + "Format your response using markdown and use tables to display data where possible." + ], ) - # Input fields for the stocks to compare - stock1 = st.text_input("Enter the first stock symbol") - stock2 = st.text_input("Enter the second stock symbol") + col1, col2 = st.columns(2) + with col1: + stock1 = st.text_input("Enter first stock symbol (e.g. AAPL)") + with col2: + stock2 = st.text_input("Enter second stock symbol (e.g. MSFT)") if stock1 and stock2: - # Get the response from the Agent - query = f"Compare {stock1} to {stock2}. Use every tool you have." - response = agent.run(query, stream=False) - st.write(response.content) \ No newline at end of file + with st.spinner(f"Analyzing {stock1} and {stock2}..."): + query = f"Compare both the stocks - {stock1} and {stock2} and make a detailed report for an investment trying to invest and compare these stocks" + response = assistant.run(query, stream=False) + st.markdown(response.content)