mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fix: remove unnecessary tobytes() calls for file byte retrieval
--bug=1060633 --user=刘瑞斌 【应用】图片理解节点解析图片报错 https://www.tapd.cn/57709429/s/1758154
This commit is contained in:
parent
79e4b902c1
commit
e910217850
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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=[
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue