Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- .env +2 -0
- agent 2.py +82 -0
.env
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
GROQ_DEEPSEEK_API_KEY="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"
|
2 |
+
GROQ_QWEN_API_KEY="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"
|
agent 2.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
from phi.agent import Agent
|
5 |
+
from phi.model.groq import Groq
|
6 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
7 |
+
from phi.tools.yfinance import YFinanceTools
|
8 |
+
|
9 |
+
# Load environment variables
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
# Retrieve API keys from the environment
|
13 |
+
deepseek_api_key = os.getenv("GROQ_DEEPSEEK_API_KEY")
|
14 |
+
qwen_api_key = os.getenv("GROQ_QWEN_API_KEY")
|
15 |
+
|
16 |
+
# Debugging API key loading
|
17 |
+
if not deepseek_api_key or not qwen_api_key:
|
18 |
+
raise ValueError("Missing API keys. Check your .env file.")
|
19 |
+
print("DeepSeek API Key Loaded")
|
20 |
+
print("Qwen API Key Loaded")
|
21 |
+
|
22 |
+
# Define the Web Agent using Groq's QWEN model
|
23 |
+
web_agent = Agent(
|
24 |
+
name="Web Agent",
|
25 |
+
model=Groq(id="qwen-2.5-coder-32b", api_key=qwen_api_key),
|
26 |
+
tools=[DuckDuckGo()],
|
27 |
+
instructions=["Always include sources"],
|
28 |
+
show_tool_calls=True,
|
29 |
+
markdown=True,
|
30 |
+
)
|
31 |
+
|
32 |
+
# Define the Finance Agent using Groq's DeepSeek model
|
33 |
+
finance_agent = Agent(
|
34 |
+
name="Finance Agent",
|
35 |
+
role="Get financial data",
|
36 |
+
model=Groq(id="qwen-2.5-coder-32b", api_key=qwen_api_key),
|
37 |
+
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)],
|
38 |
+
instructions=["Use tables to display data"],
|
39 |
+
show_tool_calls=True,
|
40 |
+
markdown=True,
|
41 |
+
)
|
42 |
+
|
43 |
+
# Combine agents into a team
|
44 |
+
agent_team = Agent(
|
45 |
+
model=Groq(id="deepseek-r1-distill-llama-70b", api_key=deepseek_api_key),
|
46 |
+
team=[web_agent, finance_agent],
|
47 |
+
instructions=["Always include sources", "Use tables to display data"],
|
48 |
+
show_tool_calls=True,
|
49 |
+
markdown=True,
|
50 |
+
)
|
51 |
+
|
52 |
+
# Debugging agent_team initialization
|
53 |
+
if not agent_team:
|
54 |
+
raise ValueError("Agent team failed to initialize.")
|
55 |
+
print("Agent team initialized successfully")
|
56 |
+
|
57 |
+
# Streamlit UI
|
58 |
+
st.set_page_config(page_title="AI Chat Assistant", layout="wide")
|
59 |
+
st.title("🤖 AI Chat Assistant")
|
60 |
+
|
61 |
+
# User input
|
62 |
+
if prompt := st.chat_input("Ask me anything..."):
|
63 |
+
with st.chat_message("user"):
|
64 |
+
st.markdown(prompt)
|
65 |
+
|
66 |
+
with st.chat_message("assistant"):
|
67 |
+
response_container = st.empty()
|
68 |
+
response_text = ""
|
69 |
+
|
70 |
+
# Ensure agent_team has a valid method to generate responses
|
71 |
+
if hasattr(agent_team, "respond") and callable(agent_team.respond):
|
72 |
+
try:
|
73 |
+
response_text = web_agent.respond(prompt) # Try this instead
|
74 |
+
response_container.markdown(response_text if response_text else "No response received.")
|
75 |
+
except Exception as e:
|
76 |
+
error_message = f"Error during response: {str(e)}"
|
77 |
+
print(error_message)
|
78 |
+
response_container.markdown(error_message)
|
79 |
+
else:
|
80 |
+
error_message = "Error: Agent does not support valid response methods."
|
81 |
+
print(error_message)
|
82 |
+
response_container.markdown(error_message)
|