Spaces:
Runtime error
Runtime error
JK commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,6 +26,30 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 26 |
"""
|
| 27 |
return "What magic will you build ?"
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
@tool
|
| 30 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 31 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 26 |
"""
|
| 27 |
return "What magic will you build ?"
|
| 28 |
|
| 29 |
+
@tool
|
| 30 |
+
def my_youtube_search__tool(arg1:str)-> list[str]:
|
| 31 |
+
"""A tool that search for videos in youtube and returns the list of links based on the video publish date
|
| 32 |
+
Args:
|
| 33 |
+
arg1: search text
|
| 34 |
+
"""
|
| 35 |
+
api_key = os.getenv("MY_YOUTUBE_API_KEY")
|
| 36 |
+
search_url = "https://www.googleapis.com/youtube/v3/search"
|
| 37 |
+
params = {
|
| 38 |
+
"part": "snippet",
|
| 39 |
+
"q": arg1,
|
| 40 |
+
"type": "video",
|
| 41 |
+
"order": "date",
|
| 42 |
+
"maxResults": 5,
|
| 43 |
+
"key": api_key
|
| 44 |
+
}
|
| 45 |
+
response = requests.get(search_url, params=params, timeout=10)
|
| 46 |
+
if response.status_code != 200:
|
| 47 |
+
return [f"Error fetching videos. Status code: {response.status_code}"]
|
| 48 |
+
|
| 49 |
+
results = response.json().get("items", [])
|
| 50 |
+
video_links = [ f"https://www.youtube.com/watch?v={item['id']['videoId']}" for item in results]
|
| 51 |
+
return video_links
|
| 52 |
+
|
| 53 |
@tool
|
| 54 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 55 |
"""A tool that fetches the current local time in a specified timezone.
|