Spaces:
Runtime error
Runtime error
Connor Adams
commited on
Commit
·
ee78eb8
1
Parent(s):
4cc3ef0
Support YouTube
Browse files
agent.py
CHANGED
|
@@ -33,11 +33,38 @@ def web_search_tool(question: str) -> str | None:
|
|
| 33 |
except Exception as e:
|
| 34 |
raise RuntimeError(f"Processing failed: {str(e)}") from e
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
class BasicAgent:
|
| 37 |
def __init__(self):
|
| 38 |
self.agent = Agent(
|
| 39 |
"gemini-2.5-flash-preview-05-20",
|
| 40 |
-
tools=[web_search_tool],
|
| 41 |
system_prompt="You are a helpful assistant that can answer questions about the world.",
|
| 42 |
)
|
| 43 |
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
raise RuntimeError(f"Processing failed: {str(e)}") from e
|
| 35 |
|
| 36 |
+
def youtube_analysis_tool(question: str, url: str) -> str | None:
|
| 37 |
+
"""Given a question and YouTube URL, analyze the video to answer the question.
|
| 38 |
+
|
| 39 |
+
Args:
|
| 40 |
+
question (str): Question about a YouTube video
|
| 41 |
+
url (str): The YouTube URL
|
| 42 |
+
|
| 43 |
+
Returns:
|
| 44 |
+
str: Answer to the question about the YouTube video
|
| 45 |
+
|
| 46 |
+
Raises:
|
| 47 |
+
RuntimeError: If processing fails"""
|
| 48 |
+
try:
|
| 49 |
+
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
| 50 |
+
|
| 51 |
+
response = client.models.generate_content(
|
| 52 |
+
model="gemini-2.5-flash-preview-05-20",
|
| 53 |
+
contents=types.Content(
|
| 54 |
+
parts=[types.Part(file_data=types.FileData(file_uri=url)),
|
| 55 |
+
types.Part(text=question)]
|
| 56 |
+
)
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
return response.text
|
| 60 |
+
except Exception as e:
|
| 61 |
+
raise RuntimeError(f"Processing failed: {str(e)}") from e
|
| 62 |
+
|
| 63 |
class BasicAgent:
|
| 64 |
def __init__(self):
|
| 65 |
self.agent = Agent(
|
| 66 |
"gemini-2.5-flash-preview-05-20",
|
| 67 |
+
tools=[web_search_tool, youtube_analysis_tool],
|
| 68 |
system_prompt="You are a helpful assistant that can answer questions about the world.",
|
| 69 |
)
|
| 70 |
|