From 2fd16834d0b3ca67abcb0da76ee03d751f17e2e3 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Tue, 3 Dec 2024 16:54:01 +0800 Subject: [PATCH] feat: support mime type and type for File --- python/dify_plugin/file/file.py | 5 ++++- python/dify_plugin/interfaces/tool/__init__.py | 16 ++++++++++++++-- python/pyproject.toml | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/python/dify_plugin/file/file.py b/python/dify_plugin/file/file.py index 9bf2035..a2e43ff 100644 --- a/python/dify_plugin/file/file.py +++ b/python/dify_plugin/file/file.py @@ -8,7 +8,10 @@ class File(BaseModel): dify_model_identity: str = DIFY_FILE_IDENTITY url: str - mime_type: str | None + mime_type: str | None = None + filename: str | None = None + extension: str | None = None + size: int | None = None type: FileType _blob: bytes | None = None diff --git a/python/dify_plugin/interfaces/tool/__init__.py b/python/dify_plugin/interfaces/tool/__init__.py index a0f2421..b3bb980 100644 --- a/python/dify_plugin/interfaces/tool/__init__.py +++ b/python/dify_plugin/interfaces/tool/__init__.py @@ -159,13 +159,25 @@ def _convert_parameters(cls, tool_parameters: dict) -> dict: for parameter, value in tool_parameters.items(): if isinstance(value, dict) and value.get("dify_model_identity") == DIFY_FILE_IDENTITY: tool_parameters[parameter] = File( - url=value["url"], mime_type=value.get("mime_type"), type=FileType(value.get("type")) + url=value["url"], + mime_type=value.get("mime_type"), + type=FileType(value.get("type")), + filename=value.get("filename"), + extension=value.get("extension"), + size=value.get("size"), ) elif isinstance(value, list) and all( isinstance(item, dict) and item.get("dify_model_identity") == DIFY_FILE_IDENTITY for item in value ): tool_parameters[parameter] = [ - File(url=item["url"], mime_type=item.get("mime_type"), type=FileType(item.get("type"))) + File( + url=item["url"], + mime_type=item.get("mime_type"), + type=FileType(item.get("type")), + filename=item.get("filename"), + extension=item.get("extension"), + size=item.get("size"), + ) for item in value ] diff --git a/python/pyproject.toml b/python/pyproject.toml index 778fde6..838693f 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dify_plugin" -version = "0.0.1-beta46" +version = "0.0.1-beta47" description = "Dify Plugin SDK" authors = [ {name = "langgenius", email = "hello@dify.ai"},