From d9def46baef70c17fa968a918ef524fc9b4b2d39 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 22 Apr 2026 10:38:26 +0800 Subject: [PATCH] feat: update FileReadTool description to include support for docx and epub files; change base64 decoding to utf-8 --- astrbot/core/computer/file_read_utils.py | 16 ++++++++-------- astrbot/core/tools/computer_tools/fs.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/astrbot/core/computer/file_read_utils.py b/astrbot/core/computer/file_read_utils.py index 0f4d0811c..20233d2b0 100644 --- a/astrbot/core/computer/file_read_utils.py +++ b/astrbot/core/computer/file_read_utils.py @@ -91,7 +91,7 @@ print( json.dumps( {{ "size_bytes": path.stat().st_size, - "sample_b64": base64.b64encode(sample).decode("ascii"), + "sample_b64": base64.b64encode(sample).decode("utf-8"), }} ) ) @@ -140,7 +140,7 @@ print( json.dumps( {{ "size_bytes": len(data), - "base64": base64.b64encode(data).decode("ascii"), + "base64": base64.b64encode(data).decode("utf-8"), }} ) ) @@ -278,7 +278,7 @@ async def _probe_local_file(path: str) -> dict[str, str | int]: sample = file_obj.read(_FILE_SNIFF_BYTES) return { "size_bytes": file_path.stat().st_size, - "sample_b64": base64.b64encode(sample).decode("ascii"), + "sample_b64": base64.b64encode(sample).decode("utf-8"), } return await to_thread(_run) @@ -289,7 +289,7 @@ async def _read_local_image_base64(path: str) -> dict[str, str | int]: data = Path(path).read_bytes() return { "size_bytes": len(data), - "base64": base64.b64encode(data).decode("ascii"), + "base64": base64.b64encode(data).decode("utf-8"), } return await to_thread(_run) @@ -319,7 +319,7 @@ async def _compress_image_bytes_to_base64(data: bytes) -> dict[str, str | int]: return { "size_bytes": len(compressed_bytes), - "base64": base64.b64encode(compressed_bytes).decode("ascii"), + "base64": base64.b64encode(compressed_bytes).decode("utf-8"), "mime_type": "image/jpeg", } @@ -659,14 +659,14 @@ async def read_file_tool_result( return "Error reading file: image payload is empty." raw_bytes = base64.b64decode(raw_base64_data) compressed_payload = await _compress_image_bytes_to_base64(raw_bytes) - base64_data = str(compressed_payload.get("base64", "") or "") - if not base64_data: + compressed_base64_data = str(compressed_payload.get("base64", "") or "") + if not compressed_base64_data: return "Error reading file: compressed image payload is empty." return mcp.types.CallToolResult( content=[ mcp.types.ImageContent( type="image", - data=base64_data, + data=compressed_base64_data, mimeType=str( compressed_payload.get("mime_type", "") or "image/jpeg" ), diff --git a/astrbot/core/tools/computer_tools/fs.py b/astrbot/core/tools/computer_tools/fs.py index b48db0a4f..60c21d949 100644 --- a/astrbot/core/tools/computer_tools/fs.py +++ b/astrbot/core/tools/computer_tools/fs.py @@ -171,7 +171,7 @@ def _decode_escaped_text(value: str) -> str: @dataclass class FileReadTool(FunctionTool): name: str = "astrbot_file_read_tool" - description: str = "read file content. Supports text, image (OCR), and PDF (text extraction) files." + description: str = "read file content. Supports text, image, and PDF (text extraction), docx and epub files." parameters: dict = field( default_factory=lambda: { "type": "object",