Update app.py
Browse filesupdated the YouTube tool
app.py
CHANGED
|
@@ -14,7 +14,11 @@ from langgraph.prebuilt import tools_condition
|
|
| 14 |
from langgraph.prebuilt import ToolNode
|
| 15 |
import base64
|
| 16 |
from google.ai.generativelanguage_v1beta.types import Tool as GenAITool
|
| 17 |
-
from google
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# (Keep Constants as is)
|
| 20 |
# --- Constants ---
|
|
@@ -117,26 +121,32 @@ def open_image(task_id: str) -> str:
|
|
| 117 |
|
| 118 |
return base64.b64encode(image_file.read()).decode("utf-8")
|
| 119 |
|
| 120 |
-
def open_youtube_video(url: str) ->
|
| 121 |
'''
|
| 122 |
-
|
| 123 |
Args:
|
| 124 |
url: The URL of the video file.
|
|
|
|
| 125 |
Returns:
|
| 126 |
-
|
| 127 |
'''
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
def google_search(query: str) -> str:
|
| 142 |
'''
|
|
@@ -184,7 +194,7 @@ class BasicAgent:
|
|
| 184 |
If you are asked to transcribe an audio file, use the 'transcribe_audio' tool.
|
| 185 |
If you are asked to run a Python code, use the 'python_code' tool.
|
| 186 |
If you are asked to open an image, use the 'open_image' tool.
|
| 187 |
-
If you
|
| 188 |
If the question requires a web search because your internal knowledge doesn't have the information, use the 'google_search' tool.
|
| 189 |
''')
|
| 190 |
|
|
|
|
| 14 |
from langgraph.prebuilt import ToolNode
|
| 15 |
import base64
|
| 16 |
from google.ai.generativelanguage_v1beta.types import Tool as GenAITool
|
| 17 |
+
from google import genai
|
| 18 |
+
from google.genai import types
|
| 19 |
+
import os
|
| 20 |
+
|
| 21 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 22 |
|
| 23 |
# (Keep Constants as is)
|
| 24 |
# --- Constants ---
|
|
|
|
| 121 |
|
| 122 |
return base64.b64encode(image_file.read()).decode("utf-8")
|
| 123 |
|
| 124 |
+
def open_youtube_video(url: str, query:str) -> str:
|
| 125 |
'''
|
| 126 |
+
Answers a question about a video from the given URL.
|
| 127 |
Args:
|
| 128 |
url: The URL of the video file.
|
| 129 |
+
query: The question to be answered about the video.
|
| 130 |
Returns:
|
| 131 |
+
Answer to the question about the video.
|
| 132 |
'''
|
| 133 |
+
|
| 134 |
+
client = genai.Client(api_key=GOOGLE_API_KEY)
|
| 135 |
+
|
| 136 |
+
response = client.models.generate_content(
|
| 137 |
+
model='models/gemini-2.0-flash',
|
| 138 |
+
contents=types.Content(
|
| 139 |
+
parts=[
|
| 140 |
+
types.Part(
|
| 141 |
+
file_data=types.FileData(file_uri=url)
|
| 142 |
+
),
|
| 143 |
+
types.Part(text=f'''{query} YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated
|
| 144 |
+
list of numbers and/or strings.''')
|
| 145 |
+
]
|
| 146 |
+
)
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
return response.text
|
| 150 |
|
| 151 |
def google_search(query: str) -> str:
|
| 152 |
'''
|
|
|
|
| 194 |
If you are asked to transcribe an audio file, use the 'transcribe_audio' tool.
|
| 195 |
If you are asked to run a Python code, use the 'python_code' tool.
|
| 196 |
If you are asked to open an image, use the 'open_image' tool.
|
| 197 |
+
If you were given a link with www.youtube.com, use the 'open_youtube_video' tool.
|
| 198 |
If the question requires a web search because your internal knowledge doesn't have the information, use the 'google_search' tool.
|
| 199 |
''')
|
| 200 |
|