mirror of
https://github.com/langgenius/dify.git
synced 2026-05-01 16:08:04 +08:00
perf: Remove deprecated optional props in LLM node tool config
This commit is contained in:
@ -13,8 +13,7 @@ const i18nPrefix = 'nodes.llm.computerUse'
|
||||
|
||||
type Props = {
|
||||
readonly: boolean
|
||||
isDisabledByStructuredOutput?: boolean
|
||||
disabled?: boolean
|
||||
isDisabledByStructuredOutput: boolean
|
||||
disabledTip?: string
|
||||
enabled: boolean
|
||||
onChange: (enabled: boolean) => void
|
||||
@ -26,7 +25,6 @@ type Props = {
|
||||
const ComputerUseConfig: FC<Props> = ({
|
||||
readonly,
|
||||
isDisabledByStructuredOutput,
|
||||
disabled,
|
||||
disabledTip,
|
||||
enabled,
|
||||
onChange,
|
||||
@ -35,8 +33,7 @@ const ComputerUseConfig: FC<Props> = ({
|
||||
promptTemplateKey,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const disabledByStructuredOutput = isDisabledByStructuredOutput ?? disabled ?? false
|
||||
const isDisabled = readonly || disabledByStructuredOutput
|
||||
const isDisabled = readonly || isDisabledByStructuredOutput
|
||||
|
||||
return (
|
||||
<div>
|
||||
@ -76,7 +73,7 @@ const ComputerUseConfig: FC<Props> = ({
|
||||
</div>
|
||||
<ReferenceToolConfig
|
||||
readonly={readonly}
|
||||
isDisabledByStructuredOutput={disabledByStructuredOutput}
|
||||
isDisabledByStructuredOutput={isDisabledByStructuredOutput}
|
||||
isComputerUseEnabled={enabled}
|
||||
nodeId={nodeId}
|
||||
toolSettings={toolSettings}
|
||||
|
||||
@ -22,10 +22,8 @@ import { getIconFromMarketPlace } from '@/utils/get-icon'
|
||||
|
||||
type ReferenceToolConfigProps = {
|
||||
readonly: boolean
|
||||
isDisabledByStructuredOutput?: boolean
|
||||
isComputerUseEnabled?: boolean
|
||||
disabledByStructuredOutput?: boolean
|
||||
computerUseEnabled?: boolean
|
||||
isDisabledByStructuredOutput: boolean
|
||||
isComputerUseEnabled: boolean
|
||||
nodeId: string
|
||||
toolSettings?: ToolSetting[]
|
||||
promptTemplateKey: string
|
||||
@ -40,15 +38,11 @@ const ReferenceToolConfig: FC<ReferenceToolConfigProps> = ({
|
||||
readonly,
|
||||
isDisabledByStructuredOutput,
|
||||
isComputerUseEnabled,
|
||||
disabledByStructuredOutput,
|
||||
computerUseEnabled,
|
||||
nodeId,
|
||||
toolSettings,
|
||||
promptTemplateKey,
|
||||
}) => {
|
||||
const resolvedIsComputerUseEnabled = isComputerUseEnabled ?? computerUseEnabled ?? false
|
||||
const resolvedIsDisabledByStructuredOutput = isDisabledByStructuredOutput ?? disabledByStructuredOutput ?? false
|
||||
const isReferenceToolsDisabled = readonly || !resolvedIsComputerUseEnabled || resolvedIsDisabledByStructuredOutput
|
||||
const isReferenceToolsDisabled = readonly || !isComputerUseEnabled || isDisabledByStructuredOutput
|
||||
const { i18n, t } = useTranslation()
|
||||
const { handleNodeDataUpdate } = useNodeCurdKit<LLMNodeType>(nodeId)
|
||||
const { theme } = useTheme()
|
||||
|
||||
@ -2,6 +2,7 @@ import type { LLMNodeType } from './types'
|
||||
import type { ToolDependency } from './use-node-skills'
|
||||
import { useMemo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { getToolTokenListRegexString, getToolTokenRegexString } from '@/app/components/workflow/skill/editor/skill-editor/plugins/tool-block/utils'
|
||||
|
||||
type Params = {
|
||||
inputs: LLMNodeType
|
||||
@ -17,8 +18,31 @@ export const useStructuredOutputMutualExclusion = ({
|
||||
toolDependencies,
|
||||
}: Params) => {
|
||||
const { t } = useTranslation()
|
||||
const toolTokenRegex = useMemo(() => new RegExp(getToolTokenRegexString()), [])
|
||||
const toolTokenListRegex = useMemo(() => new RegExp(getToolTokenListRegexString()), [])
|
||||
const hasToolTokensInText = useMemo(() => {
|
||||
return (value?: string) => {
|
||||
if (!value)
|
||||
return false
|
||||
return toolTokenRegex.test(value) || toolTokenListRegex.test(value)
|
||||
}
|
||||
}, [toolTokenListRegex, toolTokenRegex])
|
||||
const hasToolTokensInPrompt = useMemo(() => {
|
||||
const template = inputs.prompt_template
|
||||
const check = hasToolTokensInText
|
||||
if (Array.isArray(template)) {
|
||||
return template.some((item) => {
|
||||
if ('text' in item && check(item.text))
|
||||
return true
|
||||
if ('jinja2_text' in item && check(item.jinja2_text))
|
||||
return true
|
||||
return false
|
||||
})
|
||||
}
|
||||
return check(template.text) || check(template.jinja2_text)
|
||||
}, [hasToolTokensInText, inputs.prompt_template])
|
||||
const isStructuredOutputEnabled = !!inputs.structured_output_enabled
|
||||
const hasToolDependencies = isSupportSandbox && toolDependencies.length > 0
|
||||
const hasToolDependencies = isSupportSandbox && (toolDependencies.length > 0 || hasToolTokensInPrompt)
|
||||
const hasEnabledTools = (inputs.tools?.length ?? 0) > 0
|
||||
const hasToolConflict = !!inputs.computer_use || hasToolDependencies || hasEnabledTools
|
||||
|
||||
|
||||
Reference in New Issue
Block a user