Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
import groq
|
| 4 |
+
import phi
|
| 5 |
+
import phi.api
|
| 6 |
+
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
from phi.agent import Agent
|
| 9 |
+
from phi.model.groq import Groq
|
| 10 |
+
from phi.tools.yfinance import YFinanceTools
|
| 11 |
+
from phi.tools.youtube_tools import YouTubeTools
|
| 12 |
+
from phi.tools.googlesearch import GoogleSearch
|
| 13 |
+
from phi.playground import Playground
|
| 14 |
+
|
| 15 |
+
# 1. Load environment variables
|
| 16 |
+
load_dotenv()
|
| 17 |
+
|
| 18 |
+
phi.api = os.getenv("PHI_API_KEY")
|
| 19 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 20 |
+
|
| 21 |
+
# 2. Create a groq client
|
| 22 |
+
groq_client = groq.Client(api_key=groq_api_key)
|
| 23 |
+
|
| 24 |
+
# 3. Define Agents
|
| 25 |
+
|
| 26 |
+
# Websearch Agent
|
| 27 |
+
websearch_agent = Agent(
|
| 28 |
+
name='websearch_agent',
|
| 29 |
+
role="Search the web for financial information including all the latest news too.",
|
| 30 |
+
model=Groq(id="llama-3.3-70b-versatile"),
|
| 31 |
+
tools=[GoogleSearch()],
|
| 32 |
+
instructions=["Always include the sources for the information in APA format."],
|
| 33 |
+
markdown=True,
|
| 34 |
+
# debug_mode=True,
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Youtube Agent
|
| 38 |
+
youtube_agent = Agent(
|
| 39 |
+
name="YouTube Agent",
|
| 40 |
+
role="You are a YouTube agent that has the special skill of understanding YouTube videos and answering questions about them. You can only answer if the duration is less than 22 minutes.",
|
| 41 |
+
model=Groq(id="llama-3.3-70b-versatile"),
|
| 42 |
+
tools=[YouTubeTools()],
|
| 43 |
+
instructions=[
|
| 44 |
+
"1. When the user asks about a video, confirm that they have provided a valid YouTube URL. If not, ask them for it.",
|
| 45 |
+
"2. Using a video URL, get the video data using the get_youtube_video_data tool. Using the video data, get the video captions using the get_youtube_video_captions tool.",
|
| 46 |
+
"3. Using the data and captions, answer the user questions in an engaging and thoughtful manner and only focus on the important information.",
|
| 47 |
+
"4. If you cannot find the information, let the user know by asking for more details, and don't hallucinate.",
|
| 48 |
+
"5. Keep your answers concise and engaging."
|
| 49 |
+
],
|
| 50 |
+
markdown=True,
|
| 51 |
+
read_chat_history=True,
|
| 52 |
+
# debug_mode=True,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Financial Agent
|
| 56 |
+
finance_agent = Agent(
|
| 57 |
+
name="Finance AI Agent",
|
| 58 |
+
model=Groq(id="llama-3.3-70b-versatile"),
|
| 59 |
+
tools=[
|
| 60 |
+
YFinanceTools(
|
| 61 |
+
stock_price=True,
|
| 62 |
+
analyst_recommendations=True,
|
| 63 |
+
stock_fundamentals=True,
|
| 64 |
+
company_news=True
|
| 65 |
+
),
|
| 66 |
+
],
|
| 67 |
+
description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.",
|
| 68 |
+
instructions=["Format your response using markdown and use tables to display data where possible."],
|
| 69 |
+
markdown=True,
|
| 70 |
+
# debug_mode=True,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
# Multi-Model Agent
|
| 74 |
+
MultiModelAgent = Agent(
|
| 75 |
+
team=[websearch_agent, finance_agent, youtube_agent],
|
| 76 |
+
model=Groq(id="llama-3.3-70b-versatile"),
|
| 77 |
+
name="Multi-Model Agent",
|
| 78 |
+
instructions=["Always include sources and use tables to display data where possible."],
|
| 79 |
+
show_tool_calls=True,
|
| 80 |
+
markdown=True,
|
| 81 |
+
# debug_mode=True,
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
# 4. Create the Playground app with all agents
|
| 85 |
+
playground = Playground(agents=[websearch_agent, finance_agent, MultiModelAgent, youtube_agent])
|
| 86 |
+
|
| 87 |
+
# 5. The Hugging Face Space will look for 'app' to serve
|
| 88 |
+
app = playground.get_app()
|