You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

base.py 1.2KB

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