fix: custom tool parser

This commit is contained in:
Yeuoly 2024-11-01 14:26:56 +08:00
parent 6fd0a55b00
commit 8c2dbe876f
No known key found for this signature in database
GPG Key ID: A66E7E320FB19F61
3 changed files with 26 additions and 17 deletions

View File

@ -2,11 +2,15 @@ from pydantic import Field
from core.entities.provider_entities import ProviderConfig from core.entities.provider_entities import ProviderConfig
from core.tools.__base.tool_provider import ToolProviderController from core.tools.__base.tool_provider import ToolProviderController
from core.tools.__base.tool_runtime import ToolRuntime
from core.tools.custom_tool.tool import ApiTool from core.tools.custom_tool.tool import ApiTool
from core.tools.entities.common_entities import I18nObject from core.tools.entities.common_entities import I18nObject
from core.tools.entities.tool_bundle import ApiToolBundle from core.tools.entities.tool_bundle import ApiToolBundle
from core.tools.entities.tool_entities import ( from core.tools.entities.tool_entities import (
ApiProviderAuthType, ApiProviderAuthType,
ToolDescription,
ToolEntity,
ToolIdentity,
ToolProviderEntity, ToolProviderEntity,
ToolProviderIdentity, ToolProviderIdentity,
ToolProviderType, ToolProviderType,
@ -86,6 +90,7 @@ class ApiToolProviderController(ToolProviderController):
icon=db_provider.icon, icon=db_provider.icon,
), ),
credentials_schema=credentials_schema, credentials_schema=credentials_schema,
plugin_id=None,
), ),
provider_id=db_provider.id or "", provider_id=db_provider.id or "",
tenant_id=db_provider.tenant_id or "", tenant_id=db_provider.tenant_id or "",
@ -103,21 +108,25 @@ class ApiToolProviderController(ToolProviderController):
:return: the tool :return: the tool
""" """
return ApiTool( return ApiTool(
**{ api_bundle=tool_bundle,
"api_bundle": tool_bundle, entity=ToolEntity(
"identity": { identity=ToolIdentity(
"author": tool_bundle.author, author=tool_bundle.author,
"name": tool_bundle.operation_id, name=tool_bundle.operation_id or "default_tool",
"label": {"en_US": tool_bundle.operation_id, "zh_Hans": tool_bundle.operation_id}, label=I18nObject(
"icon": self.entity.identity.icon, en_US=tool_bundle.operation_id or "default_tool",
"provider": self.provider_id, zh_Hans=tool_bundle.operation_id or "default_tool",
}, ),
"description": { icon=self.entity.identity.icon,
"human": {"en_US": tool_bundle.summary or "", "zh_Hans": tool_bundle.summary or ""}, provider=self.provider_id,
"llm": tool_bundle.summary or "", ),
}, description=ToolDescription(
"parameters": tool_bundle.parameters or [], human=I18nObject(en_US=tool_bundle.summary or "", zh_Hans=tool_bundle.summary or ""),
} llm=tool_bundle.summary or "",
),
parameters=tool_bundle.parameters or [],
),
runtime=ToolRuntime(tenant_id=self.tenant_id),
) )
def load_bundled_tools(self, tools: list[ApiToolBundle]) -> list[ApiTool]: def load_bundled_tools(self, tools: list[ApiToolBundle]) -> list[ApiTool]:

View File

@ -459,7 +459,7 @@ class ApiToolManageService:
user_provider.labels = labels user_provider.labels = labels
# add icon # add icon
ToolTransformService.repack_provider(user_provider) ToolTransformService.repack_provider(tenant_id=tenant_id, provider=user_provider)
tools = provider_controller.get_tools(tenant_id=tenant_id) tools = provider_controller.get_tools(tenant_id=tenant_id)

View File

@ -198,7 +198,7 @@ class WorkflowToolManageService:
user_tool_provider = ToolTransformService.workflow_provider_to_user_provider( user_tool_provider = ToolTransformService.workflow_provider_to_user_provider(
provider_controller=tool, labels=labels.get(tool.provider_id, []) provider_controller=tool, labels=labels.get(tool.provider_id, [])
) )
ToolTransformService.repack_provider(user_tool_provider) ToolTransformService.repack_provider(tenant_id=tenant_id, provider=user_tool_provider)
user_tool_provider.tools = [ user_tool_provider.tools = [
ToolTransformService.convert_tool_entity_to_api_entity( ToolTransformService.convert_tool_entity_to_api_entity(
tool=tool.get_tools(tenant_id)[0], tool=tool.get_tools(tenant_id)[0],