user_entities.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from enum import Enum
  2. from typing import Optional
  3. from pydantic import BaseModel
  4. from core.tools.entities.common_entities import I18nObject
  5. from core.tools.entities.tool_entities import ToolProviderCredentials
  6. from core.tools.tool.tool import ToolParameter
  7. class UserToolProvider(BaseModel):
  8. class ProviderType(Enum):
  9. BUILTIN = "builtin"
  10. APP = "app"
  11. API = "api"
  12. MODEL = "model"
  13. id: str
  14. author: str
  15. name: str # identifier
  16. description: I18nObject
  17. icon: str
  18. label: I18nObject # label
  19. type: ProviderType
  20. team_credentials: dict = None
  21. is_team_authorization: bool = False
  22. allow_delete: bool = True
  23. def to_dict(self) -> dict:
  24. return {
  25. 'id': self.id,
  26. 'author': self.author,
  27. 'name': self.name,
  28. 'description': self.description.to_dict(),
  29. 'icon': self.icon,
  30. 'label': self.label.to_dict(),
  31. 'type': self.type.value,
  32. 'team_credentials': self.team_credentials,
  33. 'is_team_authorization': self.is_team_authorization,
  34. 'allow_delete': self.allow_delete
  35. }
  36. class UserToolProviderCredentials(BaseModel):
  37. credentials: dict[str, ToolProviderCredentials]
  38. class UserTool(BaseModel):
  39. author: str
  40. name: str # identifier
  41. label: I18nObject # label
  42. description: I18nObject
  43. parameters: Optional[list[ToolParameter]]