mirror of https://github.com/langgenius/dify.git
feat: completion support boolean
This commit is contained in:
parent
b5782fff8f
commit
8c8c250570
|
|
@ -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<IDebug> = ({
|
|||
}
|
||||
|
||||
const data: Record<string, any> = {
|
||||
inputs,
|
||||
inputs: formatBooleanInputs(modelConfig.configs.prompt_variables, inputs),
|
||||
model_config: postModelConfig,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<IPromptValuePanelProps> = ({
|
|||
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<IPromptValuePanelProps> = ({
|
|||
className='mb-4 last-of-type:mb-0'
|
||||
>
|
||||
<div>
|
||||
<div className='system-sm-semibold mb-1 flex h-6 items-center gap-1 text-text-secondary'>
|
||||
<div className='truncate'>{name || key}</div>
|
||||
{!required && <span className='system-xs-regular text-text-tertiary'>{t('workflow.panel.optional')}</span>}
|
||||
</div>
|
||||
{type !== 'boolean' && (
|
||||
<div className='system-sm-semibold mb-1 flex h-6 items-center gap-1 text-text-secondary'>
|
||||
<div className='truncate'>{name || key}</div>
|
||||
{!required && <span className='system-xs-regular text-text-tertiary'>{t('workflow.panel.optional')}</span>}
|
||||
</div>
|
||||
)}
|
||||
<div className='grow'>
|
||||
{type === 'string' && (
|
||||
<Input
|
||||
|
|
@ -151,6 +154,14 @@ const PromptValuePanel: FC<IPromptValuePanelProps> = ({
|
|||
maxLength={max_length || DEFAULT_VALUE_MAX_LEN}
|
||||
/>
|
||||
)}
|
||||
{type === 'boolean' && (
|
||||
<BoolInput
|
||||
name={name || key}
|
||||
value={!!inputs[key]}
|
||||
required={required}
|
||||
onChange={(value) => { handleInputValueChange(key, value) }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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<string, string | number | object | boolean>) => {
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue