Skip to content

Commit e910217

Browse files
committed
fix: remove unnecessary tobytes() calls for file byte retrieval
--bug=1060633 --user=刘瑞斌 【应用】图片理解节点解析图片报错 https://www.tapd.cn/57709429/s/1758154
1 parent 79e4b90 commit e910217

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

apps/application/flow/step_node/document_extract_node/impl/base_document_extract_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def save_image(image_list):
6666

6767
for doc in document:
6868
file = QuerySet(File).filter(id=doc['file_id']).first()
69-
buffer = io.BytesIO(file.get_byte().tobytes())
69+
buffer = io.BytesIO(file.get_byte())
7070
buffer.name = doc['name'] # this is the important line
7171

7272
for split_handle in (parse_table_handle_list + split_handles):

apps/application/flow/step_node/image_understand_step_node/impl/base_image_understand_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def file_id_to_base64(file_id: str):
6262
file = QuerySet(File).filter(id=file_id).first()
6363
file_bytes = file.get_byte()
6464
base64_image = base64.b64encode(file_bytes).decode("utf-8")
65-
return [base64_image, what(None, file_bytes.tobytes())]
65+
return [base64_image, what(None, file_bytes)]
6666

6767

6868
class BaseImageUnderstandNode(IImageUnderstandNode):
@@ -172,7 +172,7 @@ def generate_message_list(self, image_model, system: str, prompt: str, history_m
172172
file = QuerySet(File).filter(id=file_id).first()
173173
image_bytes = file.get_byte()
174174
base64_image = base64.b64encode(image_bytes).decode("utf-8")
175-
image_format = what(None, image_bytes.tobytes())
175+
image_format = what(None, image_bytes)
176176
images.append({'type': 'image_url', 'image_url': {'url': f'data:image/{image_format};base64,{base64_image}'}})
177177
messages = [HumanMessage(
178178
content=[

apps/application/flow/step_node/speech_to_text_step_node/impl/base_speech_to_text_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def process_audio_item(audio_item, model):
3232
# 根据file_name 吧文件转成mp3格式
3333
file_format = file.file_name.split('.')[-1]
3434
with tempfile.NamedTemporaryFile(delete=False, suffix=f'.{file_format}') as temp_file:
35-
temp_file.write(file.get_byte().tobytes())
35+
temp_file.write(file.get_byte())
3636
temp_file_path = temp_file.name
3737
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp3') as temp_amr_file:
3838
temp_mp3_path = temp_amr_file.name

0 commit comments

Comments
 (0)