refactor: using plugin id to dispatch request instead

This commit is contained in:
Yeuoly
2024-09-27 21:48:48 +08:00
parent 2da32e49d0
commit c3359a9291
7 changed files with 34 additions and 31 deletions

View File

@ -11,12 +11,12 @@ from core.tools.plugin_tool.tool import PluginTool
class PluginToolProviderController(BuiltinToolProviderController):
entity: ToolProviderEntityWithPlugin
tenant_id: str
plugin_unique_identifier: str
plugin_id: str
def __init__(self, entity: ToolProviderEntityWithPlugin, tenant_id: str, plugin_unique_identifier: str) -> None:
def __init__(self, entity: ToolProviderEntityWithPlugin, tenant_id: str, plugin_id: str) -> None:
self.entity = entity
self.tenant_id = tenant_id
self.plugin_unique_identifier = plugin_unique_identifier
self.plugin_id = plugin_id
@property
def provider_type(self) -> ToolProviderType:
@ -35,7 +35,7 @@ class PluginToolProviderController(BuiltinToolProviderController):
if not manager.validate_provider_credentials(
tenant_id=self.tenant_id,
user_id=user_id,
plugin_unique_identifier=self.plugin_unique_identifier,
plugin_id=self.plugin_id,
provider=self.entity.identity.name,
credentials=credentials,
):
@ -54,7 +54,7 @@ class PluginToolProviderController(BuiltinToolProviderController):
entity=tool_entity,
runtime=ToolRuntime(tenant_id=self.tenant_id),
tenant_id=self.tenant_id,
plugin_unique_identifier=self.plugin_unique_identifier,
plugin_id=self.plugin_id,
)
def get_tools(self) -> list[PluginTool]:
@ -66,7 +66,7 @@ class PluginToolProviderController(BuiltinToolProviderController):
entity=tool_entity,
runtime=ToolRuntime(tenant_id=self.tenant_id),
tenant_id=self.tenant_id,
plugin_unique_identifier=self.plugin_unique_identifier,
plugin_id=self.plugin_id,
)
for tool_entity in self.entity.tools
]

View File

@ -9,12 +9,12 @@ from core.tools.entities.tool_entities import ToolEntity, ToolInvokeMessage, Too
class PluginTool(Tool):
tenant_id: str
plugin_unique_identifier: str
plugin_id: str
def __init__(self, entity: ToolEntity, runtime: ToolRuntime, tenant_id: str, plugin_unique_identifier: str) -> None:
def __init__(self, entity: ToolEntity, runtime: ToolRuntime, tenant_id: str, plugin_id: str) -> None:
super().__init__(entity, runtime)
self.tenant_id = tenant_id
self.plugin_unique_identifier = plugin_unique_identifier
self.plugin_id = plugin_id
@property
def tool_provider_type(self) -> ToolProviderType:
@ -25,7 +25,7 @@ class PluginTool(Tool):
return manager.invoke(
tenant_id=self.tenant_id,
user_id=user_id,
plugin_unique_identifier=self.plugin_unique_identifier,
plugin_id=self.plugin_id,
tool_provider=self.entity.identity.provider,
tool_name=self.entity.identity.name,
credentials=self.runtime.credentials,
@ -37,5 +37,5 @@ class PluginTool(Tool):
entity=self.entity,
runtime=runtime,
tenant_id=self.tenant_id,
plugin_unique_identifier=self.plugin_unique_identifier,
plugin_id=self.plugin_id,
)