Skip to content

Commit

Permalink
Merge pull request #3 from langgenius/feat/add-video-and-audio-prompt…
Browse files Browse the repository at this point in the history
…-message

feat(entities): Add VideoPromptMessageContent and AudioPromptMessageContent
  • Loading branch information
Yeuoly authored Dec 4, 2024
2 parents 2fd1683 + 4298032 commit b9c83b1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion python/dify_plugin/entities/model/message.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -55,6 +55,8 @@ class PromptMessageContentType(Enum):

TEXT = "text"
IMAGE = "image"
AUDIO = "audio"
VIDEO = "video"
DOCUMENT = "document"


Expand All @@ -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.
Expand Down Expand Up @@ -133,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


Expand Down

0 comments on commit b9c83b1

Please sign in to comment.