From 1086a9788a05f6cbcb985422fa84576ffe82fe54 Mon Sep 17 00:00:00 2001 From: Wuzi Date: Fri, 7 Mar 2025 14:40:03 +0800 Subject: [PATCH] place the generated file in the workspace directory --- app/tool/file_saver.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/tool/file_saver.py b/app/tool/file_saver.py index 9f4d3cb..8b44a69 100644 --- a/app/tool/file_saver.py +++ b/app/tool/file_saver.py @@ -4,6 +4,7 @@ import os import aiofiles from app.tool.base import BaseTool +from app.config import WORKSPACE_ROOT class FileSaver(BaseTool): @@ -46,16 +47,23 @@ The tool accepts content and a file path, and saves the content to that location str: A message indicating the result of the operation. """ try: + # Place the generated file in the workspace directory + if os.path.isabs(file_path): + file_name = os.path.basename(file_path) + full_path = os.path.join(WORKSPACE_ROOT, file_name) + else: + full_path = os.path.join(WORKSPACE_ROOT, file_path) + # Ensure the directory exists - directory = os.path.dirname(file_path) + directory = os.path.dirname(full_path) if directory and not os.path.exists(directory): os.makedirs(directory) # Write directly to the file - async with aiofiles.open(file_path, mode, encoding="utf-8") as file: + async with aiofiles.open(full_path, mode, encoding="utf-8") as file: await file.write(content) - return f"Content successfully saved to {file_path}" + return f"Content successfully saved to {full_path}" except Exception as e: return f"Error saving file: {str(e)}"