marketplace.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from typing import Optional
  2. from pydantic import BaseModel, Field, model_validator
  3. from core.model_runtime.entities.provider_entities import ProviderEntity
  4. from core.plugin.entities.endpoint import EndpointProviderDeclaration
  5. from core.plugin.entities.plugin import PluginResourceRequirements
  6. from core.tools.entities.common_entities import I18nObject
  7. from core.tools.entities.tool_entities import ToolProviderEntity
  8. class MarketplacePluginDeclaration(BaseModel):
  9. name: str = Field(..., description="Unique identifier for the plugin within the marketplace")
  10. org: str = Field(..., description="Organization or developer responsible for creating and maintaining the plugin")
  11. plugin_id: str = Field(..., description="Globally unique identifier for the plugin across all marketplaces")
  12. icon: str = Field(..., description="URL or path to the plugin's visual representation")
  13. label: I18nObject = Field(..., description="Localized display name for the plugin in different languages")
  14. brief: I18nObject = Field(..., description="Short, localized description of the plugin's functionality")
  15. resource: PluginResourceRequirements = Field(
  16. ..., description="Specification of computational resources needed to run the plugin"
  17. )
  18. endpoint: Optional[EndpointProviderDeclaration] = Field(
  19. None, description="Configuration for the plugin's API endpoint, if applicable"
  20. )
  21. model: Optional[ProviderEntity] = Field(None, description="Details of the AI model used by the plugin, if any")
  22. tool: Optional[ToolProviderEntity] = Field(
  23. None, description="Information about the tool functionality provided by the plugin, if any"
  24. )
  25. latest_version: str = Field(
  26. ..., description="Most recent version number of the plugin available in the marketplace"
  27. )
  28. latest_package_identifier: str = Field(
  29. ..., description="Unique identifier for the latest package release of the plugin"
  30. )
  31. @model_validator(mode="before")
  32. @classmethod
  33. def transform_declaration(cls, data: dict):
  34. if "endpoint" in data and not data["endpoint"]:
  35. del data["endpoint"]
  36. if "model" in data and not data["model"]:
  37. del data["model"]
  38. if "tool" in data and not data["tool"]:
  39. del data["tool"]
  40. return data