Connor Adams commited on
Commit
5a46645
·
1 Parent(s): 7033ed5

Add YouTube transcript tool (although not very helpful)

Browse files
agent.py CHANGED
@@ -1,7 +1,7 @@
1
  import logfire
2
 
3
  from pydantic_ai import Agent
4
- from tools.safe_duck import safe_duckduckgo_search_tool
5
  logfire.configure()
6
  logfire.instrument_pydantic_ai()
7
 
@@ -9,7 +9,7 @@ class BasicAgent:
9
  def __init__(self):
10
  self.agent = Agent(
11
  "openai:o3-mini",
12
- tools=[safe_duckduckgo_search_tool()],
13
  system_prompt="Search DuckDuckGo for the given query and return the results.",
14
  )
15
 
 
1
  import logfire
2
 
3
  from pydantic_ai import Agent
4
+ from tools import safe_duckduckgo_search_tool, get_youtube_transcript
5
  logfire.configure()
6
  logfire.instrument_pydantic_ai()
7
 
 
9
  def __init__(self):
10
  self.agent = Agent(
11
  "openai:o3-mini",
12
+ tools=[safe_duckduckgo_search_tool(), get_youtube_transcript],
13
  system_prompt="Search DuckDuckGo for the given query and return the results.",
14
  )
15
 
requirements.lock CHANGED
@@ -50,6 +50,8 @@ colorama==0.4.6
50
  # via griffe
51
  cryptography==45.0.2
52
  # via authlib
 
 
53
  deprecated==1.2.18
54
  # via
55
  # opentelemetry-api
@@ -299,6 +301,7 @@ requests==2.32.3
299
  # huggingface-hub
300
  # opentelemetry-exporter-otlp-proto-http
301
  # pydantic-ai-slim
 
302
  rich==14.0.0
303
  # via
304
  # logfire
@@ -397,5 +400,7 @@ wrapt==1.17.2
397
  # via
398
  # deprecated
399
  # opentelemetry-instrumentation
 
 
400
  zipp==3.21.0
401
  # via importlib-metadata
 
50
  # via griffe
51
  cryptography==45.0.2
52
  # via authlib
53
+ defusedxml==0.7.1
54
+ # via youtube-transcript-api
55
  deprecated==1.2.18
56
  # via
57
  # opentelemetry-api
 
301
  # huggingface-hub
302
  # opentelemetry-exporter-otlp-proto-http
303
  # pydantic-ai-slim
304
+ # youtube-transcript-api
305
  rich==14.0.0
306
  # via
307
  # logfire
 
400
  # via
401
  # deprecated
402
  # opentelemetry-instrumentation
403
+ youtube-transcript-api==1.0.3
404
+ # via -r requirements.txt
405
  zipp==3.21.0
406
  # via importlib-metadata
requirements.txt CHANGED
@@ -3,4 +3,5 @@ gradio[oauth]
3
  requests
4
  pydantic-ai
5
  pydantic-ai-slim[duckduckgo]
6
- pydantic-ai[logfire]
 
 
3
  requests
4
  pydantic-ai
5
  pydantic-ai-slim[duckduckgo]
6
+ pydantic-ai[logfire]
7
+ youtube-transcript-api
tools/__init__.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ from .safe_duck import safe_duckduckgo_search_tool
2
+ from .youtube_transcript_tool import get_youtube_transcript
tools/youtube_transcript_tool.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from youtube_transcript_api import YouTubeTranscriptApi
2
+
3
+ def get_youtube_transcript(video_id: str) -> str:
4
+ """
5
+ Fetches the transcript for a given YouTube video ID.
6
+
7
+ Args:
8
+ video_id: The ID of the YouTube video.
9
+
10
+ Returns:
11
+ The transcript of the video as a string, or an error message if the transcript cannot be fetched.
12
+ """
13
+ try:
14
+ transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
15
+ transcript = transcript_list.find_generated_transcript(['en'])
16
+ fetched_transcript = transcript.fetch()
17
+ return " ".join([segment['text'] for segment in fetched_transcript])
18
+ except Exception as e:
19
+ return f"Error fetching transcript: {str(e)}"