Add YouTube transcript processing with yt-dlp integration

Introduced a new tool for extracting YouTube video transcripts and leveraging them to answer questions. Updated `SearchAndRead` to support reading YouTube transcripts and regular pages distinctly. Included relevant dependencies for handling subtitles and video downloads.
This commit is contained in:
2025-03-27 02:18:16 -04:00
parent 5d2c350acf
commit 1aaed4ea28
4 changed files with 137 additions and 3 deletions

View File

@@ -139,6 +139,11 @@ func (a Agent) SearchAndUseTools(ctx context.Context, searchQuery string, questi
slices.Sort(analyzed)
for j := len(analyzed) - 1; j >= 0; j-- {
v := analyzed[j]
if v < 0 || v >= len(searchResults) {
continue
}
searchResults = append(searchResults[:analyzed[j]], searchResults[analyzed[j]+1:]...)
}
@@ -181,7 +186,6 @@ Use appropriate tools to analyze the search results and determine if they answer
var learned []Knowledge
for _, r := range results.CallResults {
if r.Error != nil {
slog.Error("error executing search function", "error", err)
continue
}
@@ -208,9 +212,15 @@ Use appropriate tools to analyze the search results and determine if they answer
func (a Agent) SearchAndRead(ctx context.Context, searchQuery string, questions []string, allowConcurrent bool, maxReads int) (Knowledge, error) {
return a.SearchAndUseTools(ctx, searchQuery, questions, 2, allowConcurrent, maxReads, []SearchTool{
{
Name: "ReadPage",
Name: "readpage",
Description: "Read the search result and see if it answers the question. Try to avoid using this on low quality or spammy sites. You can use this function" + fmt.Sprint(maxReads) + " times, but do not call it multiple times on the same result.",
Function: a.ReadPage,
},
})
{
Name: "youtube",
Description: "Read the transcript to a youtube video and see if it answers the question. Try to avoid using this on low quality or spammy links. You can use this function" + fmt.Sprint(maxReads) + " times, but do not call it multiple times on the same result.",
Function: a.ReadYouTubeTranscript,
},
},
gollm.Message{Role: gollm.RoleSystem, Text: "For youtube links, only use the youtube tool. For other links, only use the readpage tool."})
}