From 3460c1dfbd10ed0f76a48b562acd29af8b19ea2d Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Tue, 18 Feb 2025 18:17:41 +0800 Subject: [PATCH] fix: tool id (#13932) --- .../debug-with-multiple-model/chat-item.tsx | 3 ++- .../debug/debug-with-single-model/index.tsx | 3 ++- .../components/app/configuration/index.tsx | 15 +++++++----- .../workflow/hooks/use-checklist.ts | 3 ++- .../components/workflow/hooks/use-workflow.ts | 7 ++---- .../panel-operator/panel-operator-popup.tsx | 5 ++-- .../extract-parameter/import-from-tool.tsx | 3 ++- .../workflow/nodes/tool/use-config.ts | 3 ++- web/app/components/workflow/utils.ts | 12 +++++----- web/utils/index.ts | 24 ++++++++++++++++++- 10 files changed, 53 insertions(+), 25 deletions(-) diff --git a/web/app/components/app/configuration/debug/debug-with-multiple-model/chat-item.tsx b/web/app/components/app/configuration/debug/debug-with-multiple-model/chat-item.tsx index 5d2f33a005..ad4c06bb00 100644 --- a/web/app/components/app/configuration/debug/debug-with-multiple-model/chat-item.tsx +++ b/web/app/components/app/configuration/debug/debug-with-multiple-model/chat-item.tsx @@ -30,6 +30,7 @@ import { ModelFeatureEnum } from '@/app/components/header/account-setting/model- import { useFeatures } from '@/app/components/base/features/hooks' import type { InputForm } from '@/app/components/base/chat/chat/type' import { getLastAnswer } from '@/app/components/base/chat/utils' +import { canFindTool } from '@/utils' type ChatItemProps = { modelAndParameter: ModelAndParameter @@ -128,7 +129,7 @@ const ChatItem: FC = ({ const allToolIcons = useMemo(() => { const icons: Record = {} modelConfig.agentConfig.tools?.forEach((item: any) => { - icons[item.tool_name] = collectionList.find((collection: any) => collection.id === item.provider_id)?.icon + icons[item.tool_name] = collectionList.find((collection: any) => canFindTool(collection.id, item.provider_id))?.icon }) return icons }, [collectionList, modelConfig.agentConfig.tools]) diff --git a/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx b/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx index 2b3c3b8fe2..74c4a30807 100644 --- a/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx +++ b/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx @@ -26,6 +26,7 @@ import { useStore as useAppStore } from '@/app/components/app/store' import { useFeatures } from '@/app/components/base/features/hooks' import { getLastAnswer, isValidGeneratedAnswer } from '@/app/components/base/chat/utils' import type { InputForm } from '@/app/components/base/chat/chat/type' +import { canFindTool } from '@/utils' type DebugWithSingleModelProps = { checkCanSend?: () => boolean @@ -134,7 +135,7 @@ const DebugWithSingleModel = forwardRef { const icons: Record = {} modelConfig.agentConfig.tools?.forEach((item: any) => { - icons[item.tool_name] = collectionList.find((collection: any) => collection.id === item.provider_id)?.icon + icons[item.tool_name] = collectionList.find((collection: any) => canFindTool(collection.id, item.provider_id))?.icon }) return icons }, [collectionList, modelConfig.agentConfig.tools]) diff --git a/web/app/components/app/configuration/index.tsx b/web/app/components/app/configuration/index.tsx index 1d37f73724..5f2c8909a5 100644 --- a/web/app/components/app/configuration/index.tsx +++ b/web/app/components/app/configuration/index.tsx @@ -72,7 +72,10 @@ import { FILE_EXTS } from '@/app/components/base/prompt-editor/constants' import { SupportUploadFileTypes } from '@/app/components/workflow/types' import NewFeaturePanel from '@/app/components/base/features/new-feature-panel' import { fetchFileUploadConfig } from '@/service/common' -import { correctProvider } from '@/utils' +import { + correctModelProvider, + correctToolProvider, +} from '@/utils' import PluginDependency from '@/app/components/workflow/plugin-dependency' type PublishConfig = { @@ -557,7 +560,7 @@ const Configuration: FC = () => { ...modelConfig.annotation_reply, embedding_model: { ...modelConfig.annotation_reply.embedding_model, - embedding_provider_name: correctProvider(modelConfig.annotation_reply.embedding_model.embedding_provider_name), + embedding_provider_name: correctModelProvider(modelConfig.annotation_reply.embedding_model.embedding_provider_name), }, } } @@ -572,7 +575,7 @@ const Configuration: FC = () => { const config = { modelConfig: { - provider: correctProvider(model.provider), + provider: correctModelProvider(model.provider), model_id: model.name, mode: model.mode, configs: { @@ -627,8 +630,8 @@ const Configuration: FC = () => { isDeleted: res.deleted_tools?.some((deletedTool: any) => deletedTool.id === tool.id && deletedTool.tool_name === tool.tool_name), notAuthor: collectionList.find(c => tool.provider_id === c.id)?.is_team_authorization === false, ...(tool.provider_type === 'builtin' ? { - provider_id: correctProvider(tool.provider_name), - provider_name: correctProvider(tool.provider_name), + provider_id: correctToolProvider(tool.provider_name), + provider_name: correctToolProvider(tool.provider_name), } : {}), } }), @@ -653,7 +656,7 @@ const Configuration: FC = () => { ...(retrievalConfig.reranking_model ? { reranking_model: { ...retrievalConfig.reranking_model, - reranking_provider_name: correctProvider(modelConfig.dataset_configs.reranking_model.reranking_provider_name), + reranking_provider_name: correctModelProvider(modelConfig.dataset_configs.reranking_model.reranking_provider_name), }, } : {}), }) diff --git a/web/app/components/workflow/hooks/use-checklist.ts b/web/app/components/workflow/hooks/use-checklist.ts index 0ef374493c..7a3a99ab38 100644 --- a/web/app/components/workflow/hooks/use-checklist.ts +++ b/web/app/components/workflow/hooks/use-checklist.ts @@ -26,6 +26,7 @@ import { CollectionType } from '@/app/components/tools/types' import { useGetLanguage } from '@/context/i18n' import type { AgentNodeType } from '../nodes/agent/types' import { useStrategyProviders } from '@/service/use-strategy' +import { canFindTool } from '@/utils' export const useChecklist = (nodes: Node[], edges: Edge[]) => { const { t } = useTranslation() @@ -51,7 +52,7 @@ export const useChecklist = (nodes: Node[], edges: Edge[]) => { moreDataForCheckValid = getToolCheckParams(node.data as ToolNodeType, buildInTools, customTools, workflowTools, language) if (provider_type === CollectionType.builtIn) - toolIcon = buildInTools.find(tool => tool.id === node.data.provider_id)?.icon + toolIcon = buildInTools.find(tool => canFindTool(tool.id, node.data.provider_id || ''))?.icon if (provider_type === CollectionType.custom) toolIcon = customTools.find(tool => tool.id === node.data.provider_id)?.icon diff --git a/web/app/components/workflow/hooks/use-workflow.ts b/web/app/components/workflow/hooks/use-workflow.ts index f56c5a615d..7920d82eb8 100644 --- a/web/app/components/workflow/hooks/use-workflow.ts +++ b/web/app/components/workflow/hooks/use-workflow.ts @@ -58,6 +58,7 @@ import I18n from '@/context/i18n' import { CollectionType } from '@/app/components/tools/types' import { CUSTOM_ITERATION_START_NODE } from '@/app/components/workflow/nodes/iteration-start/constants' import { useWorkflowConfig } from '@/service/use-workflow' +import { canFindTool } from '@/utils' export const useIsChatMode = () => { const appDetail = useAppStore(s => s.appDetail) @@ -608,11 +609,7 @@ export const useToolIcon = (data: Node['data']) => { targetTools = customTools else targetTools = workflowTools - return targetTools.find((toolWithProvider) => { - return toolWithProvider.id === data.provider_id - || toolWithProvider.id === `langgenius/${data.provider_id}/${data.provider_id}` - || toolWithProvider.id === `langgenius/${data.provider_id}_tool/${data.provider_id}` - })?.icon + return targetTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.icon } }, [data, buildInTools, customTools, workflowTools]) diff --git a/web/app/components/workflow/nodes/_base/components/panel-operator/panel-operator-popup.tsx b/web/app/components/workflow/nodes/_base/components/panel-operator/panel-operator-popup.tsx index cd44d15606..65823c43e6 100644 --- a/web/app/components/workflow/nodes/_base/components/panel-operator/panel-operator-popup.tsx +++ b/web/app/components/workflow/nodes/_base/components/panel-operator/panel-operator-popup.tsx @@ -22,6 +22,7 @@ import type { Node } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types' import { useGetLanguage } from '@/context/i18n' import { CollectionType } from '@/app/components/tools/types' +import { canFindTool } from '@/utils' type PanelOperatorPopupProps = { id: string @@ -57,7 +58,7 @@ const PanelOperatorPopup = ({ return nodesExtraData[data.type].author if (data.provider_type === CollectionType.builtIn) - return buildInTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.author + return buildInTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.author if (data.provider_type === CollectionType.workflow) return workflowTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.author @@ -70,7 +71,7 @@ const PanelOperatorPopup = ({ return nodesExtraData[data.type].about if (data.provider_type === CollectionType.builtIn) - return buildInTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.description[language] + return buildInTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.description[language] if (data.provider_type === CollectionType.workflow) return workflowTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.description[language] diff --git a/web/app/components/workflow/nodes/parameter-extractor/components/extract-parameter/import-from-tool.tsx b/web/app/components/workflow/nodes/parameter-extractor/components/extract-parameter/import-from-tool.tsx index 76432b70ae..34e509a5d3 100644 --- a/web/app/components/workflow/nodes/parameter-extractor/components/extract-parameter/import-from-tool.tsx +++ b/web/app/components/workflow/nodes/parameter-extractor/components/extract-parameter/import-from-tool.tsx @@ -14,6 +14,7 @@ import type { ToolParameter } from '@/app/components/tools/types' import { CollectionType } from '@/app/components/tools/types' import type { BlockEnum } from '@/app/components/workflow/types' import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks' +import { canFindTool } from '@/utils' const i18nPrefix = 'workflow.nodes.parameterExtractor' @@ -56,7 +57,7 @@ const ImportFromTool: FC = ({ return [] } })() - const currCollection = currentTools.find(item => item.id === provider_id) + const currCollection = currentTools.find(item => canFindTool(item.id, provider_id)) const currTool = currCollection?.tools.find(tool => tool.name === tool_name) const toExactParams = (currTool?.parameters || []).filter((item: any) => item.form === 'llm') const formattedParams = toParmExactParams(toExactParams, language) diff --git a/web/app/components/workflow/nodes/tool/use-config.ts b/web/app/components/workflow/nodes/tool/use-config.ts index acc20ec7ea..36519ce991 100644 --- a/web/app/components/workflow/nodes/tool/use-config.ts +++ b/web/app/components/workflow/nodes/tool/use-config.ts @@ -18,6 +18,7 @@ import { useFetchToolsData, useNodesReadOnly, } from '@/app/components/workflow/hooks' +import { canFindTool } from '@/utils' const useConfig = (id: string, payload: ToolNodeType) => { const { nodesReadOnly: readOnly } = useNodesReadOnly() @@ -49,7 +50,7 @@ const useConfig = (id: string, payload: ToolNodeType) => { return [] } })() - const currCollection = currentTools.find(item => item.id === provider_id) + const currCollection = currentTools.find(item => canFindTool(item.id, provider_id)) // Auth const needAuth = !!currCollection?.allow_delete diff --git a/web/app/components/workflow/utils.ts b/web/app/components/workflow/utils.ts index 9a24c4fce0..6de7b8d354 100644 --- a/web/app/components/workflow/utils.ts +++ b/web/app/components/workflow/utils.ts @@ -41,7 +41,7 @@ import type { ToolNodeType } from './nodes/tool/types' import type { IterationNodeType } from './nodes/iteration/types' import { CollectionType } from '@/app/components/tools/types' import { toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema' -import { correctProvider } from '@/utils' +import { canFindTool, correctModelProvider } from '@/utils' const WHITE = 'WHITE' const GRAY = 'GRAY' @@ -284,16 +284,16 @@ export const initialNodes = (originNodes: Node[], originEdges: Edge[]) => { // legacy provider handle if (node.data.type === BlockEnum.LLM) - (node as any).data.model.provider = correctProvider((node as any).data.model.provider) + (node as any).data.model.provider = correctModelProvider((node as any).data.model.provider) if (node.data.type === BlockEnum.KnowledgeRetrieval && (node as any).data.multiple_retrieval_config.reranking_model) - (node as any).data.multiple_retrieval_config.reranking_model.provider = correctProvider((node as any).data.multiple_retrieval_config.reranking_model.provider) + (node as any).data.multiple_retrieval_config.reranking_model.provider = correctModelProvider((node as any).data.multiple_retrieval_config.reranking_model.provider) if (node.data.type === BlockEnum.QuestionClassifier) - (node as any).data.model.provider = correctProvider((node as any).data.model.provider) + (node as any).data.model.provider = correctModelProvider((node as any).data.model.provider) if (node.data.type === BlockEnum.ParameterExtractor) - (node as any).data.model.provider = correctProvider((node as any).data.model.provider) + (node as any).data.model.provider = correctModelProvider((node as any).data.model.provider) if (node.data.type === BlockEnum.HttpRequest && !node.data.retry_config) { node.data.retry_config = { retry_enabled: true, @@ -517,7 +517,7 @@ export const getToolCheckParams = ( const { provider_id, provider_type, tool_name } = toolData const isBuiltIn = provider_type === CollectionType.builtIn const currentTools = provider_type === CollectionType.builtIn ? buildInTools : provider_type === CollectionType.custom ? customTools : workflowTools - const currCollection = currentTools.find(item => item.id === provider_id) + const currCollection = currentTools.find(item => canFindTool(item.id, provider_id)) const currTool = currCollection?.tools.find(tool => tool.name === tool_name) const formSchemas = currTool ? toolParametersToFormSchemas(currTool.parameters) : [] const toolInputVarSchema = formSchemas.filter((item: any) => item.form === 'llm') diff --git a/web/utils/index.ts b/web/utils/index.ts index 4342a08519..02d3281a0d 100644 --- a/web/utils/index.ts +++ b/web/utils/index.ts @@ -56,12 +56,34 @@ export async function fetchWithRetry(fn: Promise, retries = 3): Prom } } -export const correctProvider = (provider: string) => { +export const correctModelProvider = (provider: string) => { if (!provider) return '' if (provider.includes('/')) return provider + if (['google'].includes(provider)) + return 'langgenius/gemini/google' + return `langgenius/${provider}/${provider}` } + +export const correctToolProvider = (provider: string) => { + if (!provider) + return '' + + if (provider.includes('/')) + return provider + + if (['stepfun', 'jina', 'siliconflow'].includes(provider)) + return `langgenius/${provider}_tool/${provider}` + + return `langgenius/${provider}/${provider}` +} + +export const canFindTool = (providerId: string, oldToolId?: string) => { + return providerId === oldToolId + || providerId === `langgenius/${oldToolId}/${oldToolId}` + || providerId === `langgenius/${oldToolId}_tool/${oldToolId}` +}