mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-28 14:52:58 +00:00
fix: replace get_byte() with get_bytes() for consistency in file handling
This commit is contained in:
parent
93530e0a9b
commit
758f424000
|
|
@ -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_bytes().tobytes())
|
||||
buffer.name = doc['name'] # this is the important line
|
||||
|
||||
for split_handle in (parse_table_handle_list + split_handles):
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ def write_context(node_variable: Dict, workflow_variable: Dict, node: INode, wor
|
|||
|
||||
def file_id_to_base64(file_id: str):
|
||||
file = QuerySet(File).filter(id=file_id).first()
|
||||
file_bytes = file.get_byte()
|
||||
file_bytes = file.get_bytes()
|
||||
base64_image = base64.b64encode(file_bytes).decode("utf-8")
|
||||
return [base64_image, what(None, file_bytes.tobytes())]
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ class BaseImageUnderstandNode(IImageUnderstandNode):
|
|||
for img in image:
|
||||
file_id = img['file_id']
|
||||
file = QuerySet(File).filter(id=file_id).first()
|
||||
image_bytes = file.get_byte()
|
||||
image_bytes = file.get_bytes()
|
||||
base64_image = base64.b64encode(image_bytes).decode("utf-8")
|
||||
image_format = what(None, image_bytes.tobytes())
|
||||
images.append(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,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_bytes().tobytes())
|
||||
temp_file_path = temp_file.name
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp3') as temp_amr_file:
|
||||
temp_mp3_path = temp_amr_file.name
|
||||
|
|
|
|||
|
|
@ -558,7 +558,8 @@ class DocumentSerializers(serializers.Serializer):
|
|||
|
||||
def download_source_file(self):
|
||||
self.is_valid(raise_exception=True)
|
||||
return FileSerializer.Operate(id=self.data.get('knowledge_id')).get(with_valid=True)
|
||||
file = QuerySet(File).filter(source_id=self.data.get('document_id')).first()
|
||||
return FileSerializer.Operate(id=file.id).get(with_valid=True)
|
||||
|
||||
def one(self, with_valid=False):
|
||||
if with_valid:
|
||||
|
|
|
|||
Loading…
Reference in New Issue