-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added youtube tool * fix: fixed excessive whitespace in patch example prompt
- Loading branch information
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import logging | ||
|
||
from ..llm import summarize | ||
from .base import ToolSpec | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
try: | ||
# noreorder | ||
from youtube_transcript_api import YouTubeTranscriptApi # fmt: skip | ||
except ImportError: | ||
YouTubeTranscriptApi = None | ||
logger.warning( | ||
"youtube_transcript_api not available. YouTube tool will be disabled." | ||
) | ||
|
||
|
||
def get_transcript(video_id: str) -> str: | ||
if not YouTubeTranscriptApi: | ||
return "Error: youtube_transcript_api is not installed." | ||
try: | ||
transcript = YouTubeTranscriptApi.get_transcript(video_id) | ||
return " ".join([entry["text"] for entry in transcript]) | ||
except Exception as e: | ||
logger.error(f"Error fetching transcript: {e}") | ||
return f"Error fetching transcript: {e}" | ||
|
||
|
||
def summarize_transcript(transcript: str) -> str: | ||
return summarize(transcript).content | ||
|
||
|
||
tool: ToolSpec = ToolSpec( | ||
name="youtube", | ||
desc="Fetch and summarize YouTube video transcripts", | ||
instructions=""" | ||
To use this tool, provide a YouTube video ID and specify whether you want the transcript or a summary. | ||
""", | ||
functions=[get_transcript, summarize_transcript], | ||
block_types=["youtube"], | ||
available=bool(YouTubeTranscriptApi), | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters