From d95c47e5d6e3ccbd87c7f73c7ac389d57873cbcc Mon Sep 17 00:00:00 2001 From: xiangjinyu <1376193973@qq.com> Date: Fri, 7 Mar 2025 03:19:00 +0800 Subject: [PATCH] fix file_saver.py bug --- app/tool/file_saver.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/tool/file_saver.py b/app/tool/file_saver.py index d057067..9f4d3cb 100644 --- a/app/tool/file_saver.py +++ b/app/tool/file_saver.py @@ -1,5 +1,8 @@ +import asyncio import os +import aiofiles + from app.tool.base import BaseTool @@ -49,9 +52,10 @@ The tool accepts content and a file path, and saves the content to that location os.makedirs(directory) # Write directly to the file - with open(file_path, mode, encoding="utf-8") as file: - file.write(content) + async with aiofiles.open(file_path, mode, encoding="utf-8") as file: + await file.write(content) return f"Content successfully saved to {file_path}" except Exception as e: return f"Error saving file: {str(e)}" +