ソースを参照

fix: tool id (#13932)

tags/1.0.0
zxhlyh 8ヶ月前
コミット
3460c1dfbd
コミッターのメールアドレスに関連付けられたアカウントが存在しません

+ 2
- 1
web/app/components/app/configuration/debug/debug-with-multiple-model/chat-item.tsx ファイルの表示

import { useFeatures } from '@/app/components/base/features/hooks' import { useFeatures } from '@/app/components/base/features/hooks'
import type { InputForm } from '@/app/components/base/chat/chat/type' import type { InputForm } from '@/app/components/base/chat/chat/type'
import { getLastAnswer } from '@/app/components/base/chat/utils' import { getLastAnswer } from '@/app/components/base/chat/utils'
import { canFindTool } from '@/utils'


type ChatItemProps = { type ChatItemProps = {
modelAndParameter: ModelAndParameter modelAndParameter: ModelAndParameter
const allToolIcons = useMemo(() => { const allToolIcons = useMemo(() => {
const icons: Record<string, any> = {} const icons: Record<string, any> = {}
modelConfig.agentConfig.tools?.forEach((item: any) => { 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 return icons
}, [collectionList, modelConfig.agentConfig.tools]) }, [collectionList, modelConfig.agentConfig.tools])

+ 2
- 1
web/app/components/app/configuration/debug/debug-with-single-model/index.tsx ファイルの表示

import { useFeatures } from '@/app/components/base/features/hooks' import { useFeatures } from '@/app/components/base/features/hooks'
import { getLastAnswer, isValidGeneratedAnswer } from '@/app/components/base/chat/utils' import { getLastAnswer, isValidGeneratedAnswer } from '@/app/components/base/chat/utils'
import type { InputForm } from '@/app/components/base/chat/chat/type' import type { InputForm } from '@/app/components/base/chat/chat/type'
import { canFindTool } from '@/utils'


type DebugWithSingleModelProps = { type DebugWithSingleModelProps = {
checkCanSend?: () => boolean checkCanSend?: () => boolean
const allToolIcons = useMemo(() => { const allToolIcons = useMemo(() => {
const icons: Record<string, any> = {} const icons: Record<string, any> = {}
modelConfig.agentConfig.tools?.forEach((item: any) => { 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 return icons
}, [collectionList, modelConfig.agentConfig.tools]) }, [collectionList, modelConfig.agentConfig.tools])

+ 9
- 6
web/app/components/app/configuration/index.tsx ファイルの表示

import { SupportUploadFileTypes } from '@/app/components/workflow/types' import { SupportUploadFileTypes } from '@/app/components/workflow/types'
import NewFeaturePanel from '@/app/components/base/features/new-feature-panel' import NewFeaturePanel from '@/app/components/base/features/new-feature-panel'
import { fetchFileUploadConfig } from '@/service/common' import { fetchFileUploadConfig } from '@/service/common'
import { correctProvider } from '@/utils'
import {
correctModelProvider,
correctToolProvider,
} from '@/utils'
import PluginDependency from '@/app/components/workflow/plugin-dependency' import PluginDependency from '@/app/components/workflow/plugin-dependency'


type PublishConfig = { type PublishConfig = {
...modelConfig.annotation_reply, ...modelConfig.annotation_reply,
embedding_model: { embedding_model: {
...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),
}, },
} }
} }


const config = { const config = {
modelConfig: { modelConfig: {
provider: correctProvider(model.provider),
provider: correctModelProvider(model.provider),
model_id: model.name, model_id: model.name,
mode: model.mode, mode: model.mode,
configs: { configs: {
isDeleted: res.deleted_tools?.some((deletedTool: any) => deletedTool.id === tool.id && deletedTool.tool_name === tool.tool_name), 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, notAuthor: collectionList.find(c => tool.provider_id === c.id)?.is_team_authorization === false,
...(tool.provider_type === 'builtin' ? { ...(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),
} : {}), } : {}),
} }
}), }),
...(retrievalConfig.reranking_model ? { ...(retrievalConfig.reranking_model ? {
reranking_model: { reranking_model: {
...retrievalConfig.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),
}, },
} : {}), } : {}),
}) })

+ 2
- 1
web/app/components/workflow/hooks/use-checklist.ts ファイルの表示

import { useGetLanguage } from '@/context/i18n' import { useGetLanguage } from '@/context/i18n'
import type { AgentNodeType } from '../nodes/agent/types' import type { AgentNodeType } from '../nodes/agent/types'
import { useStrategyProviders } from '@/service/use-strategy' import { useStrategyProviders } from '@/service/use-strategy'
import { canFindTool } from '@/utils'


export const useChecklist = (nodes: Node[], edges: Edge[]) => { export const useChecklist = (nodes: Node[], edges: Edge[]) => {
const { t } = useTranslation() const { t } = useTranslation()


moreDataForCheckValid = getToolCheckParams(node.data as ToolNodeType, buildInTools, customTools, workflowTools, language) moreDataForCheckValid = getToolCheckParams(node.data as ToolNodeType, buildInTools, customTools, workflowTools, language)
if (provider_type === CollectionType.builtIn) 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) if (provider_type === CollectionType.custom)
toolIcon = customTools.find(tool => tool.id === node.data.provider_id)?.icon toolIcon = customTools.find(tool => tool.id === node.data.provider_id)?.icon

+ 2
- 5
web/app/components/workflow/hooks/use-workflow.ts ファイルの表示

import { CollectionType } from '@/app/components/tools/types' import { CollectionType } from '@/app/components/tools/types'
import { CUSTOM_ITERATION_START_NODE } from '@/app/components/workflow/nodes/iteration-start/constants' import { CUSTOM_ITERATION_START_NODE } from '@/app/components/workflow/nodes/iteration-start/constants'
import { useWorkflowConfig } from '@/service/use-workflow' import { useWorkflowConfig } from '@/service/use-workflow'
import { canFindTool } from '@/utils'


export const useIsChatMode = () => { export const useIsChatMode = () => {
const appDetail = useAppStore(s => s.appDetail) const appDetail = useAppStore(s => s.appDetail)
targetTools = customTools targetTools = customTools
else else
targetTools = workflowTools 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]) }, [data, buildInTools, customTools, workflowTools])



+ 3
- 2
web/app/components/workflow/nodes/_base/components/panel-operator/panel-operator-popup.tsx ファイルの表示

import { BlockEnum } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types'
import { useGetLanguage } from '@/context/i18n' import { useGetLanguage } from '@/context/i18n'
import { CollectionType } from '@/app/components/tools/types' import { CollectionType } from '@/app/components/tools/types'
import { canFindTool } from '@/utils'


type PanelOperatorPopupProps = { type PanelOperatorPopupProps = {
id: string id: string
return nodesExtraData[data.type].author return nodesExtraData[data.type].author


if (data.provider_type === CollectionType.builtIn) 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) if (data.provider_type === CollectionType.workflow)
return workflowTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.author return workflowTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.author
return nodesExtraData[data.type].about return nodesExtraData[data.type].about


if (data.provider_type === CollectionType.builtIn) 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) if (data.provider_type === CollectionType.workflow)
return workflowTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.description[language] return workflowTools.find(toolWithProvider => toolWithProvider.id === data.provider_id)?.description[language]

+ 2
- 1
web/app/components/workflow/nodes/parameter-extractor/components/extract-parameter/import-from-tool.tsx ファイルの表示

import { CollectionType } from '@/app/components/tools/types' import { CollectionType } from '@/app/components/tools/types'
import type { BlockEnum } from '@/app/components/workflow/types' import type { BlockEnum } from '@/app/components/workflow/types'
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks' import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { canFindTool } from '@/utils'


const i18nPrefix = 'workflow.nodes.parameterExtractor' const i18nPrefix = 'workflow.nodes.parameterExtractor'


return [] 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 currTool = currCollection?.tools.find(tool => tool.name === tool_name)
const toExactParams = (currTool?.parameters || []).filter((item: any) => item.form === 'llm') const toExactParams = (currTool?.parameters || []).filter((item: any) => item.form === 'llm')
const formattedParams = toParmExactParams(toExactParams, language) const formattedParams = toParmExactParams(toExactParams, language)

+ 2
- 1
web/app/components/workflow/nodes/tool/use-config.ts ファイルの表示

useFetchToolsData, useFetchToolsData,
useNodesReadOnly, useNodesReadOnly,
} from '@/app/components/workflow/hooks' } from '@/app/components/workflow/hooks'
import { canFindTool } from '@/utils'


const useConfig = (id: string, payload: ToolNodeType) => { const useConfig = (id: string, payload: ToolNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly() const { nodesReadOnly: readOnly } = useNodesReadOnly()
return [] return []
} }
})() })()
const currCollection = currentTools.find(item => item.id === provider_id)
const currCollection = currentTools.find(item => canFindTool(item.id, provider_id))


// Auth // Auth
const needAuth = !!currCollection?.allow_delete const needAuth = !!currCollection?.allow_delete

+ 6
- 6
web/app/components/workflow/utils.ts ファイルの表示

import type { IterationNodeType } from './nodes/iteration/types' import type { IterationNodeType } from './nodes/iteration/types'
import { CollectionType } from '@/app/components/tools/types' import { CollectionType } from '@/app/components/tools/types'
import { toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema' import { toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
import { correctProvider } from '@/utils'
import { canFindTool, correctModelProvider } from '@/utils'


const WHITE = 'WHITE' const WHITE = 'WHITE'
const GRAY = 'GRAY' const GRAY = 'GRAY'


// legacy provider handle // legacy provider handle
if (node.data.type === BlockEnum.LLM) 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) 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) 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) 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) { if (node.data.type === BlockEnum.HttpRequest && !node.data.retry_config) {
node.data.retry_config = { node.data.retry_config = {
retry_enabled: true, retry_enabled: true,
const { provider_id, provider_type, tool_name } = toolData const { provider_id, provider_type, tool_name } = toolData
const isBuiltIn = provider_type === CollectionType.builtIn const isBuiltIn = provider_type === CollectionType.builtIn
const currentTools = provider_type === CollectionType.builtIn ? buildInTools : provider_type === CollectionType.custom ? customTools : workflowTools 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 currTool = currCollection?.tools.find(tool => tool.name === tool_name)
const formSchemas = currTool ? toolParametersToFormSchemas(currTool.parameters) : [] const formSchemas = currTool ? toolParametersToFormSchemas(currTool.parameters) : []
const toolInputVarSchema = formSchemas.filter((item: any) => item.form === 'llm') const toolInputVarSchema = formSchemas.filter((item: any) => item.form === 'llm')

+ 23
- 1
web/utils/index.ts ファイルの表示

} }
} }


export const correctProvider = (provider: string) => {
export const correctModelProvider = (provider: string) => {
if (!provider) if (!provider)
return '' return ''


if (provider.includes('/')) if (provider.includes('/'))
return provider return provider


if (['google'].includes(provider))
return 'langgenius/gemini/google'

return `langgenius/${provider}/${provider}` 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}`
}

読み込み中…
キャンセル
保存