mirror of
https://github.com/langgenius/dify.git
synced 2026-01-14 06:07:33 +08:00
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: Yeuoly <admin@srmxy.cn>
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
from collections.abc import Generator
|
|
from typing import Any, Optional
|
|
|
|
from core.callback_handler.workflow_tool_callback_handler import DifyWorkflowCallbackHandler
|
|
from core.plugin.backwards_invocation.base import BaseBackwardsInvocation
|
|
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolProviderType
|
|
from core.tools.tool_engine import ToolEngine
|
|
from core.tools.tool_manager import ToolManager
|
|
from core.tools.utils.message_transformer import ToolFileMessageTransformer
|
|
|
|
|
|
class PluginToolBackwardsInvocation(BaseBackwardsInvocation):
|
|
"""
|
|
Backwards invocation for plugin tools.
|
|
"""
|
|
|
|
@classmethod
|
|
def invoke_tool(
|
|
cls,
|
|
tenant_id: str,
|
|
user_id: str,
|
|
tool_type: ToolProviderType,
|
|
provider: str,
|
|
tool_name: str,
|
|
tool_parameters: dict[str, Any],
|
|
credential_id: Optional[str] = None,
|
|
) -> Generator[ToolInvokeMessage, None, None]:
|
|
"""
|
|
invoke tool
|
|
"""
|
|
# get tool runtime
|
|
try:
|
|
tool_runtime = ToolManager.get_tool_runtime_from_plugin(
|
|
tool_type, tenant_id, provider, tool_name, tool_parameters, credential_id
|
|
)
|
|
response = ToolEngine.generic_invoke(
|
|
tool_runtime, tool_parameters, user_id, DifyWorkflowCallbackHandler(), workflow_call_depth=1
|
|
)
|
|
|
|
response = ToolFileMessageTransformer.transform_tool_invoke_messages(
|
|
response, user_id=user_id, tenant_id=tenant_id
|
|
)
|
|
|
|
return response
|
|
except Exception as e:
|
|
raise e
|