From c2a56f8c85c5516065145edf14762006d69de93a Mon Sep 17 00:00:00 2001 From: -LAN- Date: Wed, 4 Dec 2024 13:03:15 +0800 Subject: [PATCH 1/2] feat(entities): Add VideoPromptMessageContent and AudioPromptMessageContent Signed-off-by: -LAN- --- python/dify_plugin/entities/model/message.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/python/dify_plugin/entities/model/message.py b/python/dify_plugin/entities/model/message.py index 5084a2b..8e14b35 100644 --- a/python/dify_plugin/entities/model/message.py +++ b/python/dify_plugin/entities/model/message.py @@ -1,7 +1,7 @@ from enum import Enum from typing import Literal, Optional -from pydantic import BaseModel, field_validator +from pydantic import BaseModel, Field, field_validator class PromptMessageRole(Enum): @@ -55,6 +55,8 @@ class PromptMessageContentType(Enum): TEXT = "text" IMAGE = "image" + AUDIO = "audio" + VIDEO = "video" DOCUMENT = "document" @@ -75,6 +77,18 @@ class TextPromptMessageContent(PromptMessageContent): type: PromptMessageContentType = PromptMessageContentType.TEXT +class VideoPromptMessageContent(PromptMessageContent): + data: str = Field(..., description="Base64 encoded video data") + type: PromptMessageContentType = PromptMessageContentType.VIDEO + format: str = Field(..., description="Video format") + + +class AudioPromptMessageContent(PromptMessageContent): + type: PromptMessageContentType = PromptMessageContentType.AUDIO + data: str = Field(..., description="Base64 encoded audio data") + format: str = Field(..., description="Audio format") + + class ImagePromptMessageContent(PromptMessageContent): """ Model class for image prompt message content. From 42980322a0dad31b2c2db20fcca0d2edfae5c603 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Wed, 4 Dec 2024 15:09:37 +0800 Subject: [PATCH 2/2] feat: support convert in the `PromptMessage.transform_content` Signed-off-by: -LAN- --- python/dify_plugin/entities/model/message.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/dify_plugin/entities/model/message.py b/python/dify_plugin/entities/model/message.py index 8e14b35..a6a2c91 100644 --- a/python/dify_plugin/entities/model/message.py +++ b/python/dify_plugin/entities/model/message.py @@ -147,6 +147,10 @@ def transform_content(cls, value: list[dict] | str | None) -> Optional[str | lis result.append(ImagePromptMessageContent(**content)) elif content.get("type") == PromptMessageContentType.DOCUMENT.value: result.append(DocumentPromptMessageContent(**content)) + elif content.get("type") == PromptMessageContentType.AUDIO.value: + result.append(AudioPromptMessageContent(**content)) + elif content.get("type") == PromptMessageContentType.VIDEO.value: + result.append(VideoPromptMessageContent(**content)) return result