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

55 lines
1.3 KiB
Python
Raw Normal View History

2024-09-26 12:49:00 +08:00
from datetime import datetime
from typing import Optional
2024-09-26 12:49:00 +08:00
2024-10-09 22:58:36 +08:00
from pydantic import BaseModel, Field, model_validator
2024-09-26 14:51:10 +08:00
2024-10-09 22:58:36 +08:00
from configs import dify_config
2024-09-26 14:51:10 +08:00
from core.entities.provider_entities import ProviderConfig
2024-09-26 12:49:00 +08:00
from core.plugin.entities.base import BasePluginEntity
2024-09-26 14:51:10 +08:00
class EndpointDeclaration(BaseModel):
"""
declaration of an endpoint
"""
path: str
method: str
2024-12-13 22:53:08 +08:00
hidden: bool = Field(default=False)
class EndpointProviderDeclaration(BaseModel):
"""
declaration of an endpoint group
"""
2024-09-30 17:39:13 +08:00
settings: list[ProviderConfig] = Field(default_factory=list)
endpoints: Optional[list[EndpointDeclaration]] = Field(default_factory=list)
2024-09-26 14:51:10 +08:00
2024-09-26 12:49:00 +08:00
class EndpointEntity(BasePluginEntity):
2024-09-26 14:51:10 +08:00
"""
entity of an endpoint
"""
2024-09-26 12:49:00 +08:00
settings: dict
tenant_id: str
plugin_id: str
expired_at: datetime
declaration: EndpointProviderDeclaration = Field(default_factory=EndpointProviderDeclaration)
class EndpointEntityWithInstance(EndpointEntity):
2024-09-30 16:57:09 +08:00
name: str
2024-10-09 22:58:36 +08:00
enabled: bool
url: str
2024-09-26 12:49:00 +08:00
hook_id: str
2024-10-09 22:58:36 +08:00
@model_validator(mode="before")
@classmethod
def render_url_template(cls, values):
if "url" not in values:
url_template = dify_config.ENDPOINT_URL_TEMPLATE
values["url"] = url_template.replace("{hook_id}", values["hook_id"])
return values