fix: remove unnecessary tobytes() calls for file byte retrieval

--bug=1060633 --user=刘瑞斌 【应用】图片理解节点解析图片报错 https://www.tapd.cn/57709429/s/1758154
This commit is contained in:
CaptainB 2025-08-20 11:17:44 +08:00
parent 79e4b902c1
commit e910217850
3 changed files with 4 additions and 4 deletions

View File

@ -66,7 +66,7 @@ class BaseDocumentExtractNode(IDocumentExtractNode):
for doc in document:
file = QuerySet(File).filter(id=doc['file_id']).first()
buffer = io.BytesIO(file.get_byte().tobytes())
buffer = io.BytesIO(file.get_byte())
buffer.name = doc['name'] # this is the important line
for split_handle in (parse_table_handle_list + split_handles):

View File

@ -62,7 +62,7 @@ def file_id_to_base64(file_id: str):
file = QuerySet(File).filter(id=file_id).first()
file_bytes = file.get_byte()
base64_image = base64.b64encode(file_bytes).decode("utf-8")
return [base64_image, what(None, file_bytes.tobytes())]
return [base64_image, what(None, file_bytes)]
class BaseImageUnderstandNode(IImageUnderstandNode):
@ -172,7 +172,7 @@ class BaseImageUnderstandNode(IImageUnderstandNode):
file = QuerySet(File).filter(id=file_id).first()
image_bytes = file.get_byte()
base64_image = base64.b64encode(image_bytes).decode("utf-8")
image_format = what(None, image_bytes.tobytes())
image_format = what(None, image_bytes)
images.append({'type': 'image_url', 'image_url': {'url': f'data:image/{image_format};base64,{base64_image}'}})
messages = [HumanMessage(
content=[

View File

@ -32,7 +32,7 @@ class BaseSpeechToTextNode(ISpeechToTextNode):
# 根据file_name 吧文件转成mp3格式
file_format = file.file_name.split('.')[-1]
with tempfile.NamedTemporaryFile(delete=False, suffix=f'.{file_format}') as temp_file:
temp_file.write(file.get_byte().tobytes())
temp_file.write(file.get_byte())
temp_file_path = temp_file.name
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp3') as temp_amr_file:
temp_mp3_path = temp_amr_file.name