Skip to content

Commit

Permalink
feat: support mime type and type for File
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Dec 3, 2024
1 parent bc1097d commit 2fd1683
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion python/dify_plugin/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions python/dify_plugin/interfaces/tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"},
Expand Down

0 comments on commit 2fd1683

Please sign in to comment.