theakshayrane commited on
Commit
e82fdff
·
verified ·
1 Parent(s): 75dd41c

Update tools/tools.py

Browse files
Files changed (1) hide show
  1. tools/tools.py +8 -12
tools/tools.py CHANGED
@@ -74,24 +74,20 @@ def ask_youtube_video(url: str, question: str) -> str:
74
  Sends a YouTube video to a multimodal model and asks a question about it.
75
 
76
  Args:
77
- url (str): The URI of the video file (already uploaded and hosted).
78
  question (str): The natural language question to ask about the video.
79
 
80
  Returns:
81
  str: The model's answer to the question.
82
  """
83
-
84
  try:
85
- client = genai.Client(api_key=os.getenv('GEMINI_API'))
86
- response = client.generate_content(
87
- model=MODEL_ID,
88
- contents=[
89
- {"role": "user", "parts": [
90
- {"text": question},
91
- {"file_data": {"file_uri": url}}
92
- ]}
93
- ]
94
- )
95
  return response.text
96
  except Exception as e:
97
  return f"Error asking {MODEL_ID} about video: {str(e)}"
 
74
  Sends a YouTube video to a multimodal model and asks a question about it.
75
 
76
  Args:
77
+ url (str): The URL of the YouTube video.
78
  question (str): The natural language question to ask about the video.
79
 
80
  Returns:
81
  str: The model's answer to the question.
82
  """
 
83
  try:
84
+ genai.configure(api_key=os.getenv('GEMINI_API'))
85
+ model = genai.GenerativeModel(MODEL_ID)
86
+
87
+ # Gemini natively supports YouTube links passed directly in the prompt!
88
+ prompt = f"Watch this video carefully: {url}\n\nQuestion: {question}"
89
+ response = model.generate_content(prompt)
90
+
 
 
 
91
  return response.text
92
  except Exception as e:
93
  return f"Error asking {MODEL_ID} about video: {str(e)}"