54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
|
|
from typing import Any
|
||
|
|
|
||
|
|
from dify_plugin import ToolProvider
|
||
|
|
from dify_plugin.errors.tool import ToolProviderCredentialValidationError
|
||
|
|
|
||
|
|
|
||
|
|
class PdfProvider(ToolProvider):
|
||
|
|
|
||
|
|
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
|
||
|
|
try:
|
||
|
|
"""
|
||
|
|
IMPLEMENT YOUR VALIDATION HERE
|
||
|
|
"""
|
||
|
|
except Exception as e:
|
||
|
|
raise ToolProviderCredentialValidationError(str(e))
|
||
|
|
|
||
|
|
#########################################################################################
|
||
|
|
# If OAuth is supported, uncomment the following functions.
|
||
|
|
# Warning: please make sure that the sdk version is 0.4.2 or higher.
|
||
|
|
#########################################################################################
|
||
|
|
# def _oauth_get_authorization_url(self, redirect_uri: str, system_credentials: Mapping[str, Any]) -> str:
|
||
|
|
# """
|
||
|
|
# Generate the authorization URL for pdf OAuth.
|
||
|
|
# """
|
||
|
|
# try:
|
||
|
|
# """
|
||
|
|
# IMPLEMENT YOUR AUTHORIZATION URL GENERATION HERE
|
||
|
|
# """
|
||
|
|
# except Exception as e:
|
||
|
|
# raise ToolProviderOAuthError(str(e))
|
||
|
|
# return ""
|
||
|
|
|
||
|
|
# def _oauth_get_credentials(
|
||
|
|
# self, redirect_uri: str, system_credentials: Mapping[str, Any], request: Request
|
||
|
|
# ) -> Mapping[str, Any]:
|
||
|
|
# """
|
||
|
|
# Exchange code for access_token.
|
||
|
|
# """
|
||
|
|
# try:
|
||
|
|
# """
|
||
|
|
# IMPLEMENT YOUR CREDENTIALS EXCHANGE HERE
|
||
|
|
# """
|
||
|
|
# except Exception as e:
|
||
|
|
# raise ToolProviderOAuthError(str(e))
|
||
|
|
# return dict()
|
||
|
|
|
||
|
|
# def _oauth_refresh_credentials(
|
||
|
|
# self, redirect_uri: str, system_credentials: Mapping[str, Any], credentials: Mapping[str, Any]
|
||
|
|
# ) -> OAuthCredentials:
|
||
|
|
# """
|
||
|
|
# Refresh the credentials
|
||
|
|
# """
|
||
|
|
# return OAuthCredentials(credentials=credentials, expires_at=-1)
|