base.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from abc import abstractmethod, ABC
  2. from typing import Optional
  3. from core.extension.extensible import Extensible, ExtensionModule
  4. class ExternalDataTool(Extensible, ABC):
  5. """
  6. The base class of external data tool.
  7. """
  8. module: ExtensionModule = ExtensionModule.EXTERNAL_DATA_TOOL
  9. app_id: str
  10. """the id of app"""
  11. variable: str
  12. """the tool variable name of app tool"""
  13. def __init__(self, tenant_id: str, app_id: str, variable: str, config: Optional[dict] = None) -> None:
  14. super().__init__(tenant_id, config)
  15. self.app_id = app_id
  16. self.variable = variable
  17. @classmethod
  18. @abstractmethod
  19. def validate_config(cls, tenant_id: str, config: dict) -> None:
  20. """
  21. Validate the incoming form config data.
  22. :param tenant_id: the id of workspace
  23. :param config: the form config data
  24. :return:
  25. """
  26. raise NotImplementedError
  27. @abstractmethod
  28. def query(self, inputs: dict, query: Optional[str] = None) -> str:
  29. """
  30. Query the external data tool.
  31. :param inputs: user inputs
  32. :param query: the query of chat app
  33. :return: the tool query result
  34. """
  35. raise NotImplementedError