refactor: using DeclarativeBase as parent class of models, refactored tools

This commit is contained in:
Yeuoly
2024-09-29 17:00:58 +08:00
parent c8bc3892b3
commit e9e5c8806a
17 changed files with 225 additions and 120 deletions

View File

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

View File

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