fix: avoid empty plugin entity

This commit is contained in:
Yeuoly 2024-11-11 13:29:26 +08:00
parent 0b2b6a3ef3
commit 2a87f61515
No known key found for this signature in database
GPG Key ID: A66E7E320FB19F61

View File

@ -1,6 +1,6 @@
from typing import Optional
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, model_validator
from core.model_runtime.entities.provider_entities import ProviderEntity
from core.plugin.entities.endpoint import EndpointProviderDeclaration
@ -32,3 +32,14 @@ class MarketplacePluginDeclaration(BaseModel):
latest_package_identifier: str = Field(
..., description="Unique identifier for the latest package release of the plugin"
)
@model_validator(mode="before")
@classmethod
def transform_declaration(cls, data: dict):
if "endpoint" in data and not data["endpoint"]:
del data["endpoint"]
if "model" in data and not data["model"]:
del data["model"]
if "tool" in data and not data["tool"]:
del data["tool"]
return data