Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -212,6 +212,26 @@ def read_file(file_path: str) -> dict:
|
|
| 212 |
except Exception as e:
|
| 213 |
return {"error": f"Failed to read file: {str(e)}"}
|
| 214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
# @tool
|
| 216 |
# def get_youtube_transcript(url: str) -> dict:
|
| 217 |
# """
|
|
@@ -238,26 +258,6 @@ def read_file(file_path: str) -> dict:
|
|
| 238 |
|
| 239 |
# except Exception as e:
|
| 240 |
# return {"error": f"Failed to search for transcript using web search: {str(e)}"}
|
| 241 |
-
|
| 242 |
-
@tool
|
| 243 |
-
def save_and_read_file(content: str, filename: Optional[str] = None) -> str:
|
| 244 |
-
"""
|
| 245 |
-
Save content to a file and return the path.
|
| 246 |
-
Args:
|
| 247 |
-
content (str): the content to save to the file
|
| 248 |
-
filename (str, optional): the name of the file. If not provided, a random name file will be created.
|
| 249 |
-
"""
|
| 250 |
-
temp_dir = tempfile.gettempdir()
|
| 251 |
-
if filename is None:
|
| 252 |
-
temp_file = tempfile.NamedTemporaryFile(delete=False, dir=temp_dir)
|
| 253 |
-
filepath = temp_file.name
|
| 254 |
-
else:
|
| 255 |
-
filepath = os.path.join(temp_dir, filename)
|
| 256 |
-
|
| 257 |
-
with open(filepath, "w") as f:
|
| 258 |
-
f.write(content)
|
| 259 |
-
|
| 260 |
-
return f"File saved to {filepath}. You can read this file to process its contents."
|
| 261 |
|
| 262 |
@tool
|
| 263 |
def download_file_from_url(url: str, filename: Optional[str] = None) -> str:
|
|
|
|
| 212 |
except Exception as e:
|
| 213 |
return {"error": f"Failed to read file: {str(e)}"}
|
| 214 |
|
| 215 |
+
@tool
|
| 216 |
+
def save_and_read_file(content: str, filename: Optional[str] = None) -> str:
|
| 217 |
+
"""
|
| 218 |
+
Save content to a file and return the path.
|
| 219 |
+
Args:
|
| 220 |
+
content (str): the content to save to the file
|
| 221 |
+
filename (str, optional): the name of the file. If not provided, a random name file will be created.
|
| 222 |
+
"""
|
| 223 |
+
temp_dir = tempfile.gettempdir()
|
| 224 |
+
if filename is None:
|
| 225 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, dir=temp_dir)
|
| 226 |
+
filepath = temp_file.name
|
| 227 |
+
else:
|
| 228 |
+
filepath = os.path.join(temp_dir, filename)
|
| 229 |
+
|
| 230 |
+
with open(filepath, "w") as f:
|
| 231 |
+
f.write(content)
|
| 232 |
+
|
| 233 |
+
return f"File saved to {filepath}. You can read this file to process its contents."
|
| 234 |
+
|
| 235 |
# @tool
|
| 236 |
# def get_youtube_transcript(url: str) -> dict:
|
| 237 |
# """
|
|
|
|
| 258 |
|
| 259 |
# except Exception as e:
|
| 260 |
# return {"error": f"Failed to search for transcript using web search: {str(e)}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
@tool
|
| 263 |
def download_file_from_url(url: str, filename: Optional[str] = None) -> str:
|