From aef43910b1a0b3cc5efb404efc6eac34d14bfada Mon Sep 17 00:00:00 2001 From: Will Date: Mon, 10 Mar 2025 09:49:27 +0800 Subject: [PATCH] fix: octet/stream => application/octet-stream (#15329) Co-authored-by: crazywoola <427733928@qq.com> --- api/core/tools/docs/en_US/advanced_scale_out.md | 2 +- api/core/tools/docs/ja_JP/advanced_scale_out.md | 2 +- api/core/tools/docs/zh_Hans/advanced_scale_out.md | 2 +- api/core/tools/tool_engine.py | 6 ++++-- api/core/tools/tool_file_manager.py | 2 +- api/core/tools/utils/message_transformer.py | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/core/tools/docs/en_US/advanced_scale_out.md b/api/core/tools/docs/en_US/advanced_scale_out.md index 644ad29129..d6cab690cc 100644 --- a/api/core/tools/docs/en_US/advanced_scale_out.md +++ b/api/core/tools/docs/en_US/advanced_scale_out.md @@ -55,7 +55,7 @@ If you need to return a text message, you can use the following interface. If you need to return the raw data of a file, such as images, audio, video, PPT, Word, Excel, etc., you can use the following interface. - `blob` The raw data of the file, of bytes type -- `meta` The metadata of the file, if you know the type of the file, it is best to pass a `mime_type`, otherwise Dify will use `octet/stream` as the default type +- `meta` The metadata of the file, if you know the type of the file, it is best to pass a `mime_type`, otherwise Dify will use `application/octet-stream` as the default type ```python def create_blob_message(self, blob: bytes, meta: dict = None, save_as: str = '') -> ToolInvokeMessage: diff --git a/api/core/tools/docs/ja_JP/advanced_scale_out.md b/api/core/tools/docs/ja_JP/advanced_scale_out.md index 96f843354f..10ede6fda6 100644 --- a/api/core/tools/docs/ja_JP/advanced_scale_out.md +++ b/api/core/tools/docs/ja_JP/advanced_scale_out.md @@ -58,7 +58,7 @@ Difyは`テキスト`、`リンク`、`画像`、`ファイルBLOB`、`JSON`な 画像、音声、動画、PPT、Word、Excelなどのファイルの生データを返す必要がある場合は、以下のインターフェースを使用できます。 - `blob` ファイルの生データ(bytes型) -- `meta` ファイルのメタデータ。ファイルの種類が分かっている場合は、`mime_type`を渡すことをお勧めします。そうでない場合、Difyはデフォルトタイプとして`octet/stream`を使用します。 +- `meta` ファイルのメタデータ。ファイルの種類が分かっている場合は、`mime_type`を渡すことをお勧めします。そうでない場合、Difyはデフォルトタイプとして`application/octet-stream`を使用します。 ```python def create_blob_message(self, blob: bytes, meta: dict = None, save_as: str = '') -> ToolInvokeMessage: diff --git a/api/core/tools/docs/zh_Hans/advanced_scale_out.md b/api/core/tools/docs/zh_Hans/advanced_scale_out.md index 0385dfe4e7..c436a64881 100644 --- a/api/core/tools/docs/zh_Hans/advanced_scale_out.md +++ b/api/core/tools/docs/zh_Hans/advanced_scale_out.md @@ -58,7 +58,7 @@ Dify支持`文本` `链接` `图片` `文件BLOB` `JSON` 等多种消息类型 如果你需要返回文件的原始数据,如图片、音频、视频、PPT、Word、Excel等,可以使用以下接口。 - `blob` 文件的原始数据,bytes类型 -- `meta` 文件的元数据,如果你知道该文件的类型,最好传递一个`mime_type`,否则Dify将使用`octet/stream`作为默认类型 +- `meta` 文件的元数据,如果你知道该文件的类型,最好传递一个`mime_type`,否则Dify将使用`application/octet-stream`作为默认类型 ```python def create_blob_message(self, blob: bytes, meta: dict = None, save_as: str = '') -> ToolInvokeMessage: diff --git a/api/core/tools/tool_engine.py b/api/core/tools/tool_engine.py index 37b4582381..cf5411112d 100644 --- a/api/core/tools/tool_engine.py +++ b/api/core/tools/tool_engine.py @@ -290,14 +290,16 @@ class ToolEngine: raise ValueError("missing meta data") yield ToolInvokeMessageBinary( - mimetype=response.meta.get("mime_type", "octet/stream"), + mimetype=response.meta.get("mime_type", "application/octet-stream"), url=cast(ToolInvokeMessage.TextMessage, response.message).text, ) elif response.type == ToolInvokeMessage.MessageType.LINK: # check if there is a mime type in meta if response.meta and "mime_type" in response.meta: yield ToolInvokeMessageBinary( - mimetype=response.meta.get("mime_type", "octet/stream") if response.meta else "octet/stream", + mimetype=response.meta.get("mime_type", "application/octet-stream") + if response.meta + else "application/octet-stream", url=cast(ToolInvokeMessage.TextMessage, response.message).text, ) diff --git a/api/core/tools/tool_file_manager.py b/api/core/tools/tool_file_manager.py index 967cddac6c..360dfb9b4c 100644 --- a/api/core/tools/tool_file_manager.py +++ b/api/core/tools/tool_file_manager.py @@ -101,7 +101,7 @@ class ToolFileManager: except httpx.TimeoutException: raise ValueError(f"timeout when downloading file from {file_url}") - mimetype = guess_type(file_url)[0] or "octet/stream" + mimetype = guess_type(file_url)[0] or "application/octet-stream" extension = guess_extension(mimetype) or ".bin" unique_name = uuid4().hex filename = f"{unique_name}{extension}" diff --git a/api/core/tools/utils/message_transformer.py b/api/core/tools/utils/message_transformer.py index d92aa5ee60..ec0b3a5863 100644 --- a/api/core/tools/utils/message_transformer.py +++ b/api/core/tools/utils/message_transformer.py @@ -58,7 +58,7 @@ class ToolFileMessageTransformer: # get mime type and save blob to storage meta = message.meta or {} - mimetype = meta.get("mime_type", "octet/stream") + mimetype = meta.get("mime_type", "application/octet-stream") # if message is str, encode it to bytes if not isinstance(message.message, ToolInvokeMessage.BlobMessage):