Skip to content

Commit b947d7b

Browse files
committed
youtube-agent-phi-1652
1 parent e39df1d commit b947d7b

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

agents/youtube.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from typing import Optional
2+
3+
from phi.agent import Agent
4+
from phi.model.openai import OpenAIChat
5+
from phi.tools.youtube_tools import YouTubeTools
6+
7+
from agents.settings import agent_settings
8+
from phi.storage.agent.postgres import PgAgentStorage
9+
10+
from db.session import db_url
11+
12+
finance_agent_storage = PgAgentStorage(table_name="finance_agent", db_url=db_url)
13+
14+
15+
def get_youtube_agent(
16+
user_id: Optional[str] = None,
17+
session_id: Optional[str] = None,
18+
debug_mode: bool = False,
19+
) -> Agent:
20+
return Agent(
21+
name="YouTube Agent",
22+
agent_id="youtube-agent",
23+
session_id=session_id,
24+
user_id=user_id,
25+
model=OpenAIChat(
26+
model=agent_settings.gpt_4,
27+
max_tokens=agent_settings.default_max_completion_tokens,
28+
temperature=agent_settings.default_temperature,
29+
),
30+
tools=[YouTubeTools()],
31+
description="You are a YouTube agent. Obtain the captions of a YouTube video and answer questions.",
32+
markdown=True,
33+
add_history_to_messages=True,
34+
num_history_responses=5,
35+
show_tool_calls=True,
36+
add_datetime_to_instructions=True,
37+
storage=finance_agent_storage,
38+
# Enable monitoring on phidata.app
39+
monitoring=True,
40+
debug_mode=debug_mode,
41+
)

api/routes/playground.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from agents.finance import get_finance_agent
55
from agents.research import get_research_agent
66
from agents.web_search import get_web_search_agent
7+
from agents.youtube import get_youtube_agent
78

89
######################################################
910
## Router for the agent playground
@@ -12,9 +13,10 @@
1213
finance_agent = get_finance_agent(debug_mode=True)
1314
research_agent = get_research_agent(debug_mode=True)
1415
web_search_agent = get_web_search_agent(debug_mode=True)
16+
youtube_agent = get_youtube_agent(debug_mode=True)
1517

1618
# Create a playground instance
17-
playground = Playground(agents=[finance_agent, research_agent, web_search_agent])
19+
playground = Playground(agents=[finance_agent, research_agent, web_search_agent, youtube_agent])
1820
# Log the playground endpoint with phidata.app
1921
if getenv("RUNTIME_ENV") == "dev":
2022
playground.create_endpoint("http://localhost:8000")

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dependencies = [
3030
"types-beautifulsoup4",
3131
"types-Pillow",
3232
"yfinance",
33+
"youtube_transcript_api"
3334
]
3435

3536
[build-system]

requirements.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ duckdb==1.1.2
1616
duckduckgo-search==6.3.2
1717
email-validator==2.2.0
1818
exa-py==1.4.0
19+
exceptiongroup==1.2.2
1920
fastapi==0.115.2
2021
fastapi-cli==0.0.5
2122
frozendict==2.4.6
@@ -41,7 +42,7 @@ multitasking==0.0.11
4142
mypy==1.12.0
4243
mypy-extensions==1.0.0
4344
nest-asyncio==1.6.0
44-
numpy==2.1.2
45+
numpy==2.0.2
4546
openai==1.51.2
4647
packaging==24.1
4748
pandas==2.2.3
@@ -52,8 +53,8 @@ pillow==11.0.0
5253
platformdirs==4.3.6
5354
pluggy==1.5.0
5455
primp==0.6.4
55-
psycopg==3.1.19
56-
psycopg-binary==3.1.19
56+
psycopg==3.1.18
57+
psycopg-binary==3.1.18
5758
pydantic==2.9.2
5859
pydantic-core==2.23.4
5960
pydantic-settings==2.5.2
@@ -87,10 +88,11 @@ types-html5lib==1.1.11.20240806
8788
types-pillow==10.2.0.20240822
8889
typing-extensions==4.12.2
8990
tzdata==2024.2
90-
urllib3==2.2.3
91+
urllib3==1.26.20
9192
uvicorn==0.32.0
9293
uvloop==0.21.0
9394
watchfiles==0.24.0
9495
webencodings==0.5.1
9596
websockets==13.1
9697
yfinance==0.2.44
98+
youtube-transcript-api==0.6.2

0 commit comments

Comments
 (0)