diff --git a/web/app/components/app/configuration/debug/chat-user-input.tsx b/web/app/components/app/configuration/debug/chat-user-input.tsx new file mode 100644 index 0000000000..cda41917e3 --- /dev/null +++ b/web/app/components/app/configuration/debug/chat-user-input.tsx @@ -0,0 +1,109 @@ +import React from 'react' +import { useTranslation } from 'react-i18next' +import { useContext } from 'use-context-selector' +import ConfigContext from '@/context/debug-configuration' +import Input from '@/app/components/base/input' +import Select from '@/app/components/base/select' +import Textarea from '@/app/components/base/textarea' +import { DEFAULT_VALUE_MAX_LEN } from '@/config' +import type { Inputs } from '@/models/debug' +import cn from '@/utils/classnames' + +type Props = { + inputs: Inputs +} + +const ChatUserInput = ({ + inputs, +}: Props) => { + const { t } = useTranslation() + const { modelConfig, setInputs } = useContext(ConfigContext) + + const promptVariables = modelConfig.configs.prompt_variables.filter(({ key, name }) => { + return key && key?.trim() && name && name?.trim() + }) + + const promptVariableObj = (() => { + const obj: Record = {} + promptVariables.forEach((input) => { + obj[input.key] = true + }) + return obj + })() + + const handleInputValueChange = (key: string, value: string) => { + if (!(key in promptVariableObj)) + return + + const newInputs = { ...inputs } + promptVariables.forEach((input) => { + if (input.key === key) + newInputs[key] = value + }) + setInputs(newInputs) + } + + if (!promptVariables.length) + return null + + return ( +
+
+ {promptVariables.map(({ key, name, type, options, max_length, required }, index) => ( +
+
+
+
{name || key}
+ {!required && {t('workflow.panel.optional')}} +
+
+ {type === 'string' && ( + { handleInputValueChange(key, e.target.value) }} + placeholder={name} + autoFocus={index === 0} + maxLength={max_length || DEFAULT_VALUE_MAX_LEN} + /> + )} + {type === 'paragraph' && ( +