@@ -24,7 +24,7 @@ class DuckDuckGoVideoSearchTool(BuiltinTool):
24
24
25
25
def _invoke (self , user_id : str , tool_parameters : dict [str , Any ]) -> list [ToolInvokeMessage ]:
26
26
query_dict = {
27
- "keywords" : tool_parameters .get ("query" ),
27
+ "keywords" : tool_parameters .get ("query" ), # LLM's query
28
28
"region" : tool_parameters .get ("region" , "wt-wt" ),
29
29
"safesearch" : tool_parameters .get ("safesearch" , "moderate" ),
30
30
"timelimit" : tool_parameters .get ("timelimit" ),
@@ -40,6 +40,12 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> list[ToolInv
40
40
# Get proxy URL from parameters
41
41
proxy_url = tool_parameters .get ("proxy_url" , "" ).strip ()
42
42
43
+ query_prefix = tool_parameters .get ("query_prefix" , "" ).strip ()
44
+ final_query = f"{ query_prefix } { query_dict ['keywords' ]} " .strip ()
45
+
46
+ # Update the keywords in query_dict with the final_query
47
+ query_dict ["keywords" ] = final_query
48
+
43
49
response = DDGS ().videos (** query_dict )
44
50
45
51
# Create HTML result with embedded iframes
@@ -51,9 +57,13 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> list[ToolInv
51
57
embed_html = res .get ("embed_html" , "" )
52
58
description = res .get ("description" , "" )
53
59
content_url = res .get ("content" , "" )
60
+ transcript_url = None
54
61
55
62
# Handle TED.com videos
56
- if not embed_html and "ted.com/talks" in content_url :
63
+ if "ted.com/talks" in content_url :
64
+ # Create transcript URL
65
+ transcript_url = f"{ content_url } /transcript"
66
+ # Create embed URL
57
67
embed_url = content_url .replace ("www.ted.com" , "embed.ted.com" )
58
68
if proxy_url :
59
69
embed_url = f"{ proxy_url } { embed_url } "
@@ -68,8 +78,14 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> list[ToolInv
68
78
69
79
markdown_result += f"{ title } \n \n "
70
80
markdown_result += f"{ embed_html } \n \n "
81
+ if description :
82
+ markdown_result += f"{ description } \n \n "
71
83
markdown_result += "---\n \n "
72
84
73
- json_result .append (self .create_json_message (res ))
85
+ # Add transcript_url to the JSON result if available
86
+ result_dict = res .copy ()
87
+ if transcript_url :
88
+ result_dict ["transcript_url" ] = transcript_url
89
+ json_result .append (self .create_json_message (result_dict ))
74
90
75
91
return [self .create_text_message (markdown_result )] + json_result
0 commit comments