image_fitz.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from typing import Any
  2. from dify_plugin import ToolProvider
  3. from dify_plugin.errors.tool import ToolProviderCredentialValidationError
  4. class ImageFitzProvider(ToolProvider):
  5. def _validate_credentials(self, credentials: dict[str, Any]) -> None:
  6. try:
  7. """
  8. IMPLEMENT YOUR VALIDATION HERE
  9. """
  10. except Exception as e:
  11. raise ToolProviderCredentialValidationError(str(e))
  12. #########################################################################################
  13. # If OAuth is supported, uncomment the following functions.
  14. # Warning: please make sure that the sdk version is 0.4.2 or higher.
  15. #########################################################################################
  16. # def _oauth_get_authorization_url(self, redirect_uri: str, system_credentials: Mapping[str, Any]) -> str:
  17. # """
  18. # Generate the authorization URL for image_fitz OAuth.
  19. # """
  20. # try:
  21. # """
  22. # IMPLEMENT YOUR AUTHORIZATION URL GENERATION HERE
  23. # """
  24. # except Exception as e:
  25. # raise ToolProviderOAuthError(str(e))
  26. # return ""
  27. # def _oauth_get_credentials(
  28. # self, redirect_uri: str, system_credentials: Mapping[str, Any], request: Request
  29. # ) -> Mapping[str, Any]:
  30. # """
  31. # Exchange code for access_token.
  32. # """
  33. # try:
  34. # """
  35. # IMPLEMENT YOUR CREDENTIALS EXCHANGE HERE
  36. # """
  37. # except Exception as e:
  38. # raise ToolProviderOAuthError(str(e))
  39. # return dict()
  40. # def _oauth_refresh_credentials(
  41. # self, redirect_uri: str, system_credentials: Mapping[str, Any], credentials: Mapping[str, Any]
  42. # ) -> OAuthCredentials:
  43. # """
  44. # Refresh the credentials
  45. # """
  46. # return OAuthCredentials(credentials=credentials, expires_at=-1)