Update tools.py
Browse files
tools.py
CHANGED
|
@@ -49,9 +49,43 @@ class FileDownloadTool(Tool):
|
|
| 49 |
print(f"There is no file to download for task {task_id}")
|
| 50 |
return f"There is no file to download for task {task_id}", None
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
# Initialize the download file tool
|
| 53 |
file_download_tool = FileDownloadTool()
|
| 54 |
|
|
|
|
|
|
|
| 55 |
# Initialize the DuckDuckGo search tool
|
| 56 |
search_tool = DuckDuckGoSearchTool(max_results=10)
|
| 57 |
|
|
|
|
| 49 |
print(f"There is no file to download for task {task_id}")
|
| 50 |
return f"There is no file to download for task {task_id}", None
|
| 51 |
|
| 52 |
+
class ReadTextFileTool(Tool):
|
| 53 |
+
name = "read_text_file_tool"
|
| 54 |
+
description = """
|
| 55 |
+
This tool open and read the text file given the file name as the input
|
| 56 |
+
It returns the file content as a string"""
|
| 57 |
+
|
| 58 |
+
inputs = {
|
| 59 |
+
"file_name": {
|
| 60 |
+
"type": "string",
|
| 61 |
+
"description": "The file name to read",
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
}
|
| 65 |
+
def forward(self, file_name:str)->str:
|
| 66 |
+
"""
|
| 67 |
+
This function opens an text file and returns its content as a string.
|
| 68 |
+
|
| 69 |
+
:param file_name: The name of the text file to be opened.
|
| 70 |
+
:return: The content of the text file as a string.
|
| 71 |
+
"""
|
| 72 |
+
try:
|
| 73 |
+
with open(file_name, 'r') as file:
|
| 74 |
+
content = file.read()
|
| 75 |
+
return content
|
| 76 |
+
except FileNotFoundError:
|
| 77 |
+
print(f"File `{file_name}` not found.")
|
| 78 |
+
return f"File `{file_name}` not found.", None
|
| 79 |
+
except Exception as e:
|
| 80 |
+
print(f"An error occurred while opening the file: {e}")
|
| 81 |
+
return f"An error occurred while opening the file: {e}"
|
| 82 |
+
|
| 83 |
+
|
| 84 |
# Initialize the download file tool
|
| 85 |
file_download_tool = FileDownloadTool()
|
| 86 |
|
| 87 |
+
read_text_file_tool = ReadTextFileTool()
|
| 88 |
+
|
| 89 |
# Initialize the DuckDuckGo search tool
|
| 90 |
search_tool = DuckDuckGoSearchTool(max_results=10)
|
| 91 |
|