From 8c8c250570777d548615fcb6f91d9a29ab768b96 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 9 Jul 2025 14:28:36 +0800 Subject: [PATCH] feat: completion support boolean --- .../app/configuration/debug/index.tsx | 4 ++-- .../prompt-value-panel/index.tsx | 21 ++++++++++++++----- web/utils/model-config.ts | 16 +++++++++++++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/web/app/components/app/configuration/debug/index.tsx b/web/app/components/app/configuration/debug/index.tsx index 38b0c890e2..9a50d1b872 100644 --- a/web/app/components/app/configuration/debug/index.tsx +++ b/web/app/components/app/configuration/debug/index.tsx @@ -34,7 +34,7 @@ import { RefreshCcw01 } from '@/app/components/base/icons/src/vender/line/arrows import TooltipPlus from '@/app/components/base/tooltip' import ActionButton, { ActionButtonState } from '@/app/components/base/action-button' import type { ModelConfig as BackendModelConfig, VisionFile, VisionSettings } from '@/types/app' -import { promptVariablesToUserInputsForm } from '@/utils/model-config' +import { formatBooleanInputs, promptVariablesToUserInputsForm } from '@/utils/model-config' import TextGeneration from '@/app/components/app/text-generate/item' import { IS_CE_EDITION } from '@/config' import type { Inputs } from '@/models/debug' @@ -259,7 +259,7 @@ const Debug: FC = ({ } const data: Record = { - inputs, + inputs: formatBooleanInputs(modelConfig.configs.prompt_variables, inputs), model_config: postModelConfig, } diff --git a/web/app/components/app/configuration/prompt-value-panel/index.tsx b/web/app/components/app/configuration/prompt-value-panel/index.tsx index e509ee50e4..2bfd512d66 100644 --- a/web/app/components/app/configuration/prompt-value-panel/index.tsx +++ b/web/app/components/app/configuration/prompt-value-panel/index.tsx @@ -22,6 +22,7 @@ import type { VisionFile, VisionSettings } from '@/types/app' import { DEFAULT_VALUE_MAX_LEN } from '@/config' import { useStore as useAppStore } from '@/app/components/app/store' import cn from '@/utils/classnames' +import BoolInput from '@/app/components/workflow/nodes/_base/components/before-run-form/bool-input' export type IPromptValuePanelProps = { appType: AppType @@ -66,7 +67,7 @@ const PromptValuePanel: FC = ({ else { return !modelConfig.configs.prompt_template } }, [chatPromptConfig.prompt, completionPromptConfig.prompt?.text, isAdvancedMode, mode, modelConfig.configs.prompt_template, modelModeType]) - const handleInputValueChange = (key: string, value: string) => { + const handleInputValueChange = (key: string, value: string | boolean) => { if (!(key in promptVariableObj)) return @@ -109,10 +110,12 @@ const PromptValuePanel: FC = ({ className='mb-4 last-of-type:mb-0' >
-
-
{name || key}
- {!required && {t('workflow.panel.optional')}} -
+ {type !== 'boolean' && ( +
+
{name || key}
+ {!required && {t('workflow.panel.optional')}} +
+ )}
{type === 'string' && ( = ({ maxLength={max_length || DEFAULT_VALUE_MAX_LEN} /> )} + {type === 'boolean' && ( + { handleInputValueChange(key, value) }} + /> + )}
diff --git a/web/utils/model-config.ts b/web/utils/model-config.ts index 330d8f9b52..1e02bb61ee 100644 --- a/web/utils/model-config.ts +++ b/web/utils/model-config.ts @@ -130,7 +130,7 @@ export const promptVariablesToUserInputsForm = (promptVariables: PromptVariable[ } as any) return } - if (item.type === 'number') { + if (item.type === 'number' || item.type === 'boolean') { userInputs.push({ number: { label: item.name, @@ -172,3 +172,17 @@ export const promptVariablesToUserInputsForm = (promptVariables: PromptVariable[ return userInputs } + +export const formatBooleanInputs = (useInputs: PromptVariable[] | null, inputs: Record) => { + if(!useInputs) + return inputs + const res = { ...(inputs || {}) } + useInputs.forEach((item) => { + const isBooleanInput = item.type === 'boolean' + if (isBooleanInput) { + // Convert boolean inputs to boolean type + res[item.key] = !!res[item.key] + } + }) + return res +}