Update app.py
Browse filesadded file extension and debug
app.py
CHANGED
|
@@ -67,6 +67,10 @@ class FetchFileTool(Tool):
|
|
| 67 |
"type": "string",
|
| 68 |
"description": "The internet location of the file to fetch",
|
| 69 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
"file_path": {
|
| 71 |
"type": "string",
|
| 72 |
"description": "The path to the directory where the file will be saved",
|
|
@@ -74,11 +78,11 @@ class FetchFileTool(Tool):
|
|
| 74 |
"file_name": {
|
| 75 |
"type": "string",
|
| 76 |
"description": "The name of the file where content will be saved",
|
| 77 |
-
}
|
| 78 |
}
|
| 79 |
output_type = "boolean"
|
| 80 |
|
| 81 |
-
def forward(self, location: str, file_path: str, file_name: str):
|
| 82 |
try:
|
| 83 |
response = requests.get(location)
|
| 84 |
response.raise_for_status()
|
|
@@ -93,9 +97,13 @@ class FetchFileTool(Tool):
|
|
| 93 |
if response.status_code == 429:
|
| 94 |
# get last part of location separated by slash
|
| 95 |
file_id = location.split('/')[-1]
|
| 96 |
-
local_path = f"files/{file_id}"
|
|
|
|
|
|
|
| 97 |
full_path = os.path.join(file_path, file_name)
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
return True
|
| 100 |
else:
|
| 101 |
print(f"Error saving content to file: {e}")
|
|
|
|
| 67 |
"type": "string",
|
| 68 |
"description": "The internet location of the file to fetch",
|
| 69 |
},
|
| 70 |
+
"file_extension": {
|
| 71 |
+
"type": "string",
|
| 72 |
+
"description": "Assumed file extension of the file to fetch, like mp3 or png for example",
|
| 73 |
+
},
|
| 74 |
"file_path": {
|
| 75 |
"type": "string",
|
| 76 |
"description": "The path to the directory where the file will be saved",
|
|
|
|
| 78 |
"file_name": {
|
| 79 |
"type": "string",
|
| 80 |
"description": "The name of the file where content will be saved",
|
| 81 |
+
}
|
| 82 |
}
|
| 83 |
output_type = "boolean"
|
| 84 |
|
| 85 |
+
def forward(self, location: str, file_extension: str, file_path: str, file_name: str):
|
| 86 |
try:
|
| 87 |
response = requests.get(location)
|
| 88 |
response.raise_for_status()
|
|
|
|
| 97 |
if response.status_code == 429:
|
| 98 |
# get last part of location separated by slash
|
| 99 |
file_id = location.split('/')[-1]
|
| 100 |
+
local_path = f"files/{file_id}.{file_extension}"
|
| 101 |
+
print(f"Copying from: {local_path}")
|
| 102 |
+
|
| 103 |
full_path = os.path.join(file_path, file_name)
|
| 104 |
+
print(f"Copying to: {full_path}")
|
| 105 |
+
|
| 106 |
+
shutil.copy(local_path, full_path)
|
| 107 |
return True
|
| 108 |
else:
|
| 109 |
print(f"Error saving content to file: {e}")
|