Skip to content

Commit 26aaa80

Browse files
Merge pull request #4 from yashksaini-coder/patch
Minor Fixes & Patch
2 parents 5a750f8 + a917402 commit 26aaa80

File tree

3 files changed

+97
-69
lines changed

3 files changed

+97
-69
lines changed

agents.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import groq
2+
import os
3+
from dotenv import load_dotenv
4+
5+
# AI assistant imports
6+
from agno.agent import Agent
7+
from agno.models.groq import Groq
8+
from agno.tools.yfinance import YFinanceTools
9+
from agno.tools.duckduckgo import DuckDuckGoTools
10+
from agno.agent import Agent, RunResponse
11+
12+
load_dotenv(dotenv_path=".env")
13+
GROQ_API_KEY = os.getenv("api_key")
14+
15+
groq_client = groq.Client(api_key=GROQ_API_KEY)
16+
17+
if not GROQ_API_KEY:
18+
raise ValueError("Please provide a GROQ API key")
19+
20+
21+
web_search_agent = Agent(
22+
name="web_agent",
23+
role="search the web for information based on the user given input",
24+
model=Groq(id="llama-3.3-70b-specdec",api_key=GROQ_API_KEY),
25+
tools=[
26+
DuckDuckGoTools(search=True, news=True),
27+
28+
],
29+
instructions=[
30+
"You are a very professional web search AI agent",
31+
"your job is to search the web for information based on the user given input",
32+
"provide exact information to the user available on the web",
33+
],
34+
structured_outputs=False,
35+
markdown=True,
36+
)
37+
financial_agent = Agent(
38+
name="financial_agent",
39+
role="get financial information",
40+
model=Groq(id="llama-3.3-70b-specdec",api_key=GROQ_API_KEY),
41+
tools=[
42+
YFinanceTools(stock_price=True,
43+
analyst_recommendations=True,
44+
stock_fundamentals=True,
45+
company_info=True,
46+
technical_indicators=True,
47+
historical_prices=True,
48+
key_financial_ratios = True,
49+
income_statements = True,
50+
),
51+
],
52+
instructions=[
53+
"You are a very professional financial advisor AI agent",
54+
"your job is to provide financial information to users",
55+
"you can provide stock price, analyst recommendations, and stock fundamentals",
56+
"you can also provide information about companies, industries, and financial terms",
57+
],
58+
structured_outputs=False,
59+
markdown=True,
60+
)
61+
62+
multi_ai = Agent(
63+
team=[web_search_agent, financial_agent],
64+
model=Groq(id="llama-3.3-70b-specdec",api_key=GROQ_API_KEY),
65+
markdown=True,
66+
)

app.py

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
# API imports
12
from fastapi import FastAPI
23
import groq
3-
from agno.agent import Agent
4-
from agno.models.groq import Groq
5-
from agno.tools.yfinance import YFinanceTools
6-
from agno.tools.duckduckgo import DuckDuckGoTools
7-
from agno.agent import Agent, RunResponse
84
import os
95
from dotenv import load_dotenv
10-
# Load API key from .env file
116
from fastapi.middleware.cors import CORSMiddleware
127
from topStocks import get_top_stocks
8+
from agents import multi_ai
9+
from agno.agent import RunResponse
10+
11+
1312
load_dotenv(dotenv_path=".env")
1413
GROQ_API_KEY = os.getenv("api_key")
1514

@@ -28,59 +27,35 @@
2827
allow_headers=["*"],
2928
)
3029

31-
web_search_agent = Agent(
32-
name="web_agent",
33-
role="search the web for information based on the user given input",
34-
model=Groq(id="llama-3.3-70b-specdec",api_key=GROQ_API_KEY),
35-
tools=[
36-
DuckDuckGoTools(search=True, news=True),
37-
38-
],
39-
instructions=[
40-
"You are a very professional web search AI agent",
41-
"your job is to search the web for information based on the user given input",
42-
"provide exact information to the user available on the web",
43-
],
44-
structured_outputs=False,
45-
markdown=True,
46-
)
47-
financial_agent = Agent(
48-
name="financial_agent",
49-
role="get financial information",
50-
model=Groq(id="llama-3.3-70b-specdec",api_key=GROQ_API_KEY),
51-
tools=[
52-
YFinanceTools(stock_price=True,
53-
analyst_recommendations=True,
54-
stock_fundamentals=True,
55-
company_info=True,
56-
technical_indicators=True,
57-
historical_prices=True,
58-
key_financial_ratios = True,
59-
income_statements = True,
60-
),
61-
],
62-
instructions=[
63-
"You are a very professional financial advisor AI agent",
64-
"your job is to provide financial information to users",
65-
"you can provide stock price, analyst recommendations, and stock fundamentals",
66-
"you can also provide information about companies, industries, and financial terms",
67-
],
68-
structured_outputs=False,
69-
markdown=True,
70-
)
71-
72-
multi_ai = Agent(
73-
team=[web_search_agent, financial_agent],
74-
model=Groq(id="llama-3.3-70b-specdec",api_key=GROQ_API_KEY),
75-
markdown=True,
76-
)
77-
7830
@app.get("/top-stocks")
7931
async def read_top_stocks():
8032
top_stocks = ['AAPL', 'GOOGL', 'MSFT', 'AMZN', 'TSLA']
8133
stock_info = get_top_stocks(top_stocks)
8234
return stock_info
8335

36+
37+
@app.get("/chat")
38+
def chat(query: str):
39+
"""
40+
API endpoint to handle user investment-related questions and return AI-generated insights.
41+
"""
42+
if not query:
43+
return {"error": "Query parameter is required"}
44+
45+
try:
46+
response = groq_client.chat.completions.create(
47+
model="llama-3.3-70b-versatile",
48+
messages=[{"role": "system", "content": "You are an AI investment assistant."},
49+
{"role": "user", "content": query}]
50+
)
51+
52+
answer = response.choices[0].message.content
53+
return {"question": query, "answer": answer}
54+
55+
except Exception as e:
56+
return {"error": str(e)}
57+
58+
8459
@app.get("/ask")
8560
def ask(query: str):
8661
"""
@@ -90,7 +65,6 @@ def ask(query: str):
9065
return {"error": "Query parameter is required"}
9166

9267
try:
93-
# response = financial_agent.print_response(query)
9468
response: RunResponse = multi_ai.run(query)
9569
answer = response.content
9670

main.py renamed to ask.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
from fastapi import FastAPI
21
import groq
32
import os
43
from dotenv import load_dotenv
54

6-
# Load API key from .env file
7-
85
load_dotenv(dotenv_path=".env")
9-
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
6+
GROQ_API_KEY = os.getenv("api_key")
107

118
groq_client = groq.Client(api_key=GROQ_API_KEY)
129

13-
if not GROQ_API_KEY:
14-
raise ValueError("Please provide a GROQ API key")
15-
exit(1)
16-
17-
app = FastAPI()
18-
19-
20-
21-
@app.get("/ask")
22-
def ask(query: str):
10+
def chat(query: str):
2311
"""
2412
API endpoint to handle user investment-related questions and return AI-generated insights.
2513
"""
@@ -37,4 +25,4 @@ def ask(query: str):
3725
return {"question": query, "answer": answer}
3826

3927
except Exception as e:
40-
return {"error": str(e)}
28+
return {"error": str(e)}

0 commit comments

Comments
 (0)