user_entities.py 1.4 KB

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