mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
Merge branch 'feat/enhance-multi-modal-support' into deploy/dev
This commit is contained in:
commit
739919556d
|
@ -28,18 +28,23 @@ class ToolFilePreviewApi(Resource):
|
|||
raise Forbidden("Invalid request.")
|
||||
|
||||
try:
|
||||
result = ToolFileManager.get_file_generator_by_tool_file_id(
|
||||
stream, tool_file = ToolFileManager.get_file_generator_by_tool_file_id(
|
||||
file_id,
|
||||
)
|
||||
|
||||
if not result:
|
||||
if not stream or not tool_file:
|
||||
raise NotFound("file is not found")
|
||||
|
||||
generator, mimetype = result
|
||||
except Exception:
|
||||
raise UnsupportedFileTypeError()
|
||||
|
||||
return Response(generator, mimetype=mimetype)
|
||||
return Response(
|
||||
stream,
|
||||
mimetype=tool_file.mimetype,
|
||||
direct_passthrough=True,
|
||||
headers={
|
||||
"Content-Length": str(tool_file.size),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
api.add_resource(ToolFilePreviewApi, "/files/tools/<uuid:file_id>.<string:extension>")
|
||||
|
|
|
@ -4,7 +4,6 @@ import hmac
|
|||
import logging
|
||||
import os
|
||||
import time
|
||||
from collections.abc import Generator
|
||||
from mimetypes import guess_extension, guess_type
|
||||
from typing import Optional, Union
|
||||
from uuid import uuid4
|
||||
|
@ -194,7 +193,7 @@ class ToolFileManager:
|
|||
return blob, tool_file.mimetype
|
||||
|
||||
@staticmethod
|
||||
def get_file_generator_by_tool_file_id(tool_file_id: str) -> Union[tuple[Generator, str], None]:
|
||||
def get_file_generator_by_tool_file_id(tool_file_id: str):
|
||||
"""
|
||||
get file binary
|
||||
|
||||
|
@ -211,11 +210,11 @@ class ToolFileManager:
|
|||
)
|
||||
|
||||
if not tool_file:
|
||||
return None
|
||||
return None, None
|
||||
|
||||
generator = storage.load_stream(tool_file.file_key)
|
||||
stream = storage.load_stream(tool_file.file_key)
|
||||
|
||||
return generator, tool_file.mimetype
|
||||
return stream, tool_file
|
||||
|
||||
|
||||
# init tool_file_parser
|
||||
|
|
Loading…
Reference in New Issue
Block a user