Martin Bär commited on
Commit
872f41a
·
1 Parent(s): 9f1ce17

Implement youtube tool

Browse files
Files changed (2) hide show
  1. multimodality_tools.py +24 -2
  2. requirements.txt +2 -1
multimodality_tools.py CHANGED
@@ -142,13 +142,35 @@ def get_csv_analysis_tool():
142
  description="Analyse a csv file that is identified by its file id and get common statistics such as mean or max per column."
143
  )
144
 
145
- def watch_video(video_url: str) -> str:
 
 
146
  return "You are not able to watch a Video yet. Reply with 'I don't know' to the question."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  def get_video_tool():
149
  return FunctionTool.from_defaults(
150
  fn=watch_video,
151
- description="Watch a video and get a content description as a string."
152
  )
153
 
154
  def _build_file_url(task_id: str) -> str:
 
142
  description="Analyse a csv file that is identified by its file id and get common statistics such as mean or max per column."
143
  )
144
 
145
+ def watch_video(question: str, youtube_url: str) -> str:
146
+ """Answer a question about a YouTube video identified by its url."""
147
+ # TODO our Gemini Key cannot be used to watch videos.
148
  return "You are not able to watch a Video yet. Reply with 'I don't know' to the question."
149
+ try:
150
+ from google import genai
151
+ from google.genai import types
152
+
153
+ client = genai.Client(api_key="GOOGLE_API_KEY")
154
+ response = client.models.generate_content(
155
+ model='models/gemini-2.0-flash',
156
+ contents=types.Content(
157
+ parts=[
158
+ types.Part(
159
+ file_data=types.FileData(file_uri=youtube_url)
160
+ ),
161
+ types.Part(text=question)
162
+ ]
163
+ )
164
+ )
165
+ except Exception as e:
166
+ print(e)
167
+ return "You are not able to watch a Video yet. Reply with 'I don't know' to the question."
168
+ return str(response.text)
169
 
170
  def get_video_tool():
171
  return FunctionTool.from_defaults(
172
  fn=watch_video,
173
+ description="Answer a question about a YouTube video identified by its url."
174
  )
175
 
176
  def _build_file_url(task_id: str) -> str:
requirements.txt CHANGED
@@ -16,4 +16,5 @@ pandas
16
  openpyxl
17
  huggingface_hub
18
  transformers
19
- tavily-python
 
 
16
  openpyxl
17
  huggingface_hub
18
  transformers
19
+ tavily-python
20
+ google-genai