Spaces:
Sleeping
Sleeping
jesusgj
commited on
Commit
Β·
b31685b
1
Parent(s):
54202aa
Modified files
Browse files
agent.py
CHANGED
|
@@ -119,7 +119,13 @@ def initialize_agent():
|
|
| 119 |
@tool
|
| 120 |
@retry
|
| 121 |
def query_webpage(url: str, query: str) -> str:
|
| 122 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
logging.info(f"π Querying webpage: {url}")
|
| 124 |
loader = download_loader("BeautifulSoupWebReader")()
|
| 125 |
docs = loader.load_data(urls=[url])
|
|
@@ -132,7 +138,13 @@ def initialize_agent():
|
|
| 132 |
@tool
|
| 133 |
@retry
|
| 134 |
def query_youtube_video(video_url: str, query: str) -> str:
|
| 135 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
logging.info(f"π¬ Querying YouTube video: {video_url}")
|
| 137 |
video_id_match = re.search(r'(?:v=|\/)([a-zA-Z0-9_-]{11}).*', video_url)
|
| 138 |
if not video_id_match: return "Error: Invalid YouTube URL."
|
|
@@ -152,7 +164,7 @@ def initialize_agent():
|
|
| 152 |
Searches Wikipedia for a given query and returns a summary.
|
| 153 |
|
| 154 |
Args:
|
| 155 |
-
|
| 156 |
"""
|
| 157 |
try:
|
| 158 |
return wikipedia.summary(query, sentences=5)
|
|
@@ -175,7 +187,6 @@ def initialize_agent():
|
|
| 175 |
|
| 176 |
google_search_tool = GoogleSearchTool(provider='serpapi', serpapi_api_key=api_keys['serpapi']) if api_keys['serpapi'] else None
|
| 177 |
|
| 178 |
-
# LOGICAL FIX: Create a single, powerful CodeAgent with all necessary tools.
|
| 179 |
tools_list = [tool for tool in [google_search_tool, query_webpage, query_youtube_video, wikipedia_search] if tool]
|
| 180 |
|
| 181 |
agent = CodeAgent(
|
|
@@ -208,8 +219,9 @@ def initialize_agent():
|
|
| 208 |
*Example 2: Multi-step question involving web search*
|
| 209 |
```python
|
| 210 |
# Find the birth date of the author of 'Pride and Prejudice'
|
| 211 |
-
|
| 212 |
# Let's assume the tool returns "Jane Austen"
|
|
|
|
| 213 |
birth_date_info = wikipedia_search(query="Jane Austen birth date")
|
| 214 |
print(birth_date_info)
|
| 215 |
```
|
|
|
|
| 119 |
@tool
|
| 120 |
@retry
|
| 121 |
def query_webpage(url: str, query: str) -> str:
|
| 122 |
+
"""
|
| 123 |
+
Extracts specific information from a webpage by asking a targeted question.
|
| 124 |
+
|
| 125 |
+
Args:
|
| 126 |
+
url (str): The full URL of the webpage to query.
|
| 127 |
+
query (str): The specific question to ask about the webpage's content.
|
| 128 |
+
"""
|
| 129 |
logging.info(f"π Querying webpage: {url}")
|
| 130 |
loader = download_loader("BeautifulSoupWebReader")()
|
| 131 |
docs = loader.load_data(urls=[url])
|
|
|
|
| 138 |
@tool
|
| 139 |
@retry
|
| 140 |
def query_youtube_video(video_url: str, query: str) -> str:
|
| 141 |
+
"""
|
| 142 |
+
Extracts specific information from a YouTube video transcript.
|
| 143 |
+
|
| 144 |
+
Args:
|
| 145 |
+
video_url (str): The full URL of the YouTube video.
|
| 146 |
+
query (str): The specific question to ask about the video's content.
|
| 147 |
+
"""
|
| 148 |
logging.info(f"π¬ Querying YouTube video: {video_url}")
|
| 149 |
video_id_match = re.search(r'(?:v=|\/)([a-zA-Z0-9_-]{11}).*', video_url)
|
| 150 |
if not video_id_match: return "Error: Invalid YouTube URL."
|
|
|
|
| 164 |
Searches Wikipedia for a given query and returns a summary.
|
| 165 |
|
| 166 |
Args:
|
| 167 |
+
query (str): The term or question to search for on Wikipedia.
|
| 168 |
"""
|
| 169 |
try:
|
| 170 |
return wikipedia.summary(query, sentences=5)
|
|
|
|
| 187 |
|
| 188 |
google_search_tool = GoogleSearchTool(provider='serpapi', serpapi_api_key=api_keys['serpapi']) if api_keys['serpapi'] else None
|
| 189 |
|
|
|
|
| 190 |
tools_list = [tool for tool in [google_search_tool, query_webpage, query_youtube_video, wikipedia_search] if tool]
|
| 191 |
|
| 192 |
agent = CodeAgent(
|
|
|
|
| 219 |
*Example 2: Multi-step question involving web search*
|
| 220 |
```python
|
| 221 |
# Find the birth date of the author of 'Pride and Prejudice'
|
| 222 |
+
author_name_info = GoogleSearchTool(query="author of Pride and Prejudice")
|
| 223 |
# Let's assume the tool returns "Jane Austen"
|
| 224 |
+
# Now get the birth date from Wikipedia
|
| 225 |
birth_date_info = wikipedia_search(query="Jane Austen birth date")
|
| 226 |
print(birth_date_info)
|
| 227 |
```
|