Delete tools/file/save_content_to_file.py
Browse files
tools/file/save_content_to_file.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 1 |
-
from langchain_core.tools import tool
|
| 2 |
-
from typing import Optional
|
| 3 |
-
import os
|
| 4 |
-
from urllib.parse import urlparse
|
| 5 |
-
import tempfile
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
@tool
|
| 9 |
-
def save_content_to_file(content: str, filename: Optional[str] = None) -> str:
|
| 10 |
-
"""
|
| 11 |
-
Save content to a file and return the path.
|
| 12 |
-
Args:
|
| 13 |
-
content (str): the content to save to the file
|
| 14 |
-
filename (str, optional): the name of the file. If not provided, a random name file will be created.
|
| 15 |
-
"""
|
| 16 |
-
temp_dir = tempfile.gettempdir()
|
| 17 |
-
if filename is None:
|
| 18 |
-
temp_file = tempfile.NamedTemporaryFile(delete=False, dir=temp_dir)
|
| 19 |
-
filepath = temp_file.name
|
| 20 |
-
else:
|
| 21 |
-
filepath = os.path.join(temp_dir, filename)
|
| 22 |
-
|
| 23 |
-
with open(filepath, "w") as f:
|
| 24 |
-
f.write(content)
|
| 25 |
-
|
| 26 |
-
return f"File saved to {filepath}. You can read this file to process its contents."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|