user_entities.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 UserTool(BaseModel):
  8. author: str
  9. name: str # identifier
  10. label: I18nObject # label
  11. description: I18nObject
  12. parameters: Optional[list[ToolParameter]]
  13. class UserToolProvider(BaseModel):
  14. class ProviderType(Enum):
  15. BUILTIN = "builtin"
  16. APP = "app"
  17. API = "api"
  18. MODEL = "model"
  19. id: str
  20. author: str
  21. name: str # identifier
  22. description: I18nObject
  23. icon: str
  24. label: I18nObject # label
  25. type: ProviderType
  26. masked_credentials: dict = None
  27. original_credentials: dict = None
  28. is_team_authorization: bool = False
  29. allow_delete: bool = True
  30. tools: list[UserTool] = None
  31. def to_dict(self) -> dict:
  32. return {
  33. 'id': self.id,
  34. 'author': self.author,
  35. 'name': self.name,
  36. 'description': self.description.to_dict(),
  37. 'icon': self.icon,
  38. 'label': self.label.to_dict(),
  39. 'type': self.type.value,
  40. 'team_credentials': self.masked_credentials,
  41. 'is_team_authorization': self.is_team_authorization,
  42. 'allow_delete': self.allow_delete,
  43. 'tools': self.tools
  44. }
  45. class UserToolProviderCredentials(BaseModel):
  46. credentials: dict[str, ToolProviderCredentials]