From 48748ff00b6739f6f40edc2c09395a092ddb5c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Fri, 9 Aug 2024 10:33:15 +0800 Subject: [PATCH] refactor: str -> Path --- metagpt/utils/omniparse_client.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/metagpt/utils/omniparse_client.py b/metagpt/utils/omniparse_client.py index e7c5a3d44..cb2341944 100644 --- a/metagpt/utils/omniparse_client.py +++ b/metagpt/utils/omniparse_client.py @@ -1,5 +1,4 @@ import mimetypes -import os from pathlib import Path from typing import Union @@ -190,7 +189,7 @@ class OmniParseClient: # Do not verify if only byte data is provided return - file_ext = os.path.splitext(verify_file_path)[1].lower() + file_ext = Path(verify_file_path).suffix if file_ext not in allowed_file_extensions: raise ValueError(f"Not allowed {file_ext} File extension must be one of {allowed_file_extensions}") @@ -219,7 +218,7 @@ class OmniParseClient: Returns bytes if only_bytes is True, otherwise returns a tuple (filename, file_bytes, mime_type). """ if isinstance(file_input, (str, Path)): - filename = os.path.basename(str(file_input)) + filename = Path(file_input).name file_bytes = await aread_bin(file_input) if only_bytes: