dify/api/core/plugin/entities/plugin_daemon.py

109 lines
2.8 KiB
Python
Raw Normal View History

from datetime import datetime
2024-09-20 21:35:19 +08:00
from enum import Enum
2024-09-20 14:43:01 +08:00
from typing import Generic, Optional, TypeVar
from pydantic import BaseModel, ConfigDict, Field
2024-09-20 14:43:01 +08:00
from core.model_runtime.entities.model_entities import AIModelEntity
from core.model_runtime.entities.provider_entities import ProviderEntity
2024-09-23 18:06:16 +08:00
from core.tools.entities.tool_entities import ToolProviderEntityWithPlugin
2024-09-23 13:09:46 +08:00
T = TypeVar("T", bound=(BaseModel | dict | list | bool))
2024-09-20 14:43:01 +08:00
class PluginDaemonBasicResponse(BaseModel, Generic[T]):
"""
Basic response from plugin daemon.
"""
code: int
message: str
data: Optional[T]
2024-09-20 21:35:19 +08:00
class InstallPluginMessage(BaseModel):
"""
Message for installing a plugin.
"""
2024-09-20 21:35:19 +08:00
class Event(Enum):
Info = "info"
Done = "done"
Error = "error"
event: Event
2024-09-23 18:06:16 +08:00
data: str
class PluginToolProviderEntity(BaseModel):
provider: str
plugin_unique_identifier: str
plugin_id: str
2024-09-23 21:13:02 +08:00
declaration: ToolProviderEntityWithPlugin
class PluginBasicBooleanResponse(BaseModel):
"""
Basic boolean response from plugin daemon.
"""
result: bool
class PluginModelSchemaEntity(BaseModel):
model_schema: AIModelEntity = Field(description="The model schema.")
# pydantic configs
model_config = ConfigDict(protected_namespaces=())
class PluginModelProviderEntity(BaseModel):
id: str = Field(alias="ID", description="ID")
created_at: datetime = Field(alias="CreatedAt", description="The created at time of the model provider.")
updated_at: datetime = Field(alias="UpdatedAt", description="The updated at time of the model provider.")
provider: str = Field(description="The provider of the model.")
tenant_id: str = Field(description="The tenant ID.")
plugin_unique_identifier: str = Field(description="The plugin unique identifier.")
plugin_id: str = Field(description="The plugin ID.")
declaration: ProviderEntity = Field(description="The declaration of the model provider.")
class PluginNumTokensResponse(BaseModel):
"""
Response for number of tokens.
"""
num_tokens: int = Field(description="The number of tokens.")
class PluginStringResultResponse(BaseModel):
result: str = Field(description="The result of the string.")
class PluginVoiceEntity(BaseModel):
name: str = Field(description="The name of the voice.")
value: str = Field(description="The value of the voice.")
class PluginVoicesResponse(BaseModel):
voices: list[PluginVoiceEntity] = Field(description="The result of the voices.")
2024-09-29 13:12:22 +08:00
class PluginDaemonError(BaseModel):
"""
Error from plugin daemon.
"""
error_type: str
message: str
args: Optional[dict] = None
class PluginDaemonInnerError(Exception):
code: int
message: str
def __init__(self, code: int, message: str):
self.code = code
self.message = message