diff --git a/web/app/components/app/configuration/config/index.tsx b/web/app/components/app/configuration/config/index.tsx index 9615e01716..6fbf43941c 100644 --- a/web/app/components/app/configuration/config/index.tsx +++ b/web/app/components/app/configuration/config/index.tsx @@ -40,7 +40,7 @@ const Config: FC = () => { } = useContext(ConfigContext) const isChatApp = mode === AppType.chat const { data: userInfo } = useSWR({ url: '/info' }, fetchTenantInfo) - const targetProvider = userInfo?.providers?.find(({ token_is_set, is_valid }) => token_is_set && is_valid) + const openaiProvider = userInfo?.providers?.find(({ token_is_set, is_valid, provider_name }) => token_is_set && is_valid && provider_name === 'openai') const promptTemplate = modelConfig.configs.prompt_template const promptVariables = modelConfig.configs.prompt_variables @@ -92,7 +92,7 @@ const Config: FC = () => { }, }) - const hasChatConfig = isChatApp && (featureConfig.openingStatement || featureConfig.suggestedQuestionsAfterAnswer || (featureConfig.speechToText && targetProvider?.provider_name === 'openai')) + const hasChatConfig = isChatApp && (featureConfig.openingStatement || featureConfig.suggestedQuestionsAfterAnswer || (featureConfig.speechToText && openaiProvider)) const hasToolbox = false const [showAutomatic, { setTrue: showAutomaticTrue, setFalse: showAutomaticFalse }] = useBoolean(false) @@ -122,7 +122,7 @@ const Config: FC = () => { isChatApp={isChatApp} config={featureConfig} onChange={handleFeatureChange} - showSpeechToTextItem={targetProvider?.provider_name === 'openai'} + showSpeechToTextItem={!!openaiProvider} /> )} {showAutomatic && ( diff --git a/web/app/components/app/configuration/debug/index.tsx b/web/app/components/app/configuration/debug/index.tsx index a7582bb2de..6c524d570f 100644 --- a/web/app/components/app/configuration/debug/index.tsx +++ b/web/app/components/app/configuration/debug/index.tsx @@ -116,22 +116,22 @@ const Debug: FC = ({ } const checkCanSend = () => { - let hasEmptyInput = false + let hasEmptyInput = '' const requiredVars = modelConfig.configs.prompt_variables.filter(({ key, name, required }) => { const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null) return res }) // compatible with old version // debugger - requiredVars.forEach(({ key }) => { + requiredVars.forEach(({ key, name }) => { if (hasEmptyInput) return if (!inputs[key]) - hasEmptyInput = true + hasEmptyInput = name }) if (hasEmptyInput) { - logError(t('appDebug.errorMessage.valueOfVarRequired')) + logError(t('appDebug.errorMessage.valueOfVarRequired', { key: hasEmptyInput })) return false } return !hasEmptyInput 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 cb19f4f642..949a7d2097 100644 --- a/web/app/components/app/configuration/prompt-value-panel/index.tsx +++ b/web/app/components/app/configuration/prompt-value-panel/index.tsx @@ -122,6 +122,7 @@ const PromptValuePanel: FC = ({ items={(options || []).map(i => ({ name: i, value: i }))} allowSearch={false} bgClassName='bg-gray-50' + overlayClassName='z-[11]' /> ) : ( diff --git a/web/app/components/base/select/index.tsx b/web/app/components/base/select/index.tsx index 02b73ffe0e..5971421aa6 100644 --- a/web/app/components/base/select/index.tsx +++ b/web/app/components/base/select/index.tsx @@ -31,6 +31,7 @@ export type ISelectProps = { allowSearch?: boolean bgClassName?: string placeholder?: string + overlayClassName?: string } const Select: FC = ({ className, @@ -40,6 +41,7 @@ const Select: FC = ({ onSelect, allowSearch = true, bgClassName = 'bg-gray-100', + overlayClassName, }) => { const [query, setQuery] = useState('') const [open, setOpen] = useState(false) @@ -48,9 +50,9 @@ const Select: FC = ({ useEffect(() => { let defaultSelect = null const existed = items.find((item: Item) => item.value === defaultValue) - if (existed) { + if (existed) defaultSelect = existed - } + setSelectedItem(defaultSelect) }, [defaultValue]) @@ -104,7 +106,7 @@ const Select: FC = ({ {filteredItems.length > 0 && ( - + {filteredItems.map((item: Item) => ( = ({ useEffect(() => { let defaultSelect = null const existed = items.find((item: Item) => item.value === defaultValue) - if (existed) { + if (existed) defaultSelect = existed - } + setSelectedItem(defaultSelect) }, [defaultValue]) @@ -173,7 +175,7 @@ const SimpleSelect: FC = ({ >
- {selectedItem?.name ?? localPlaceholder} + {selectedItem?.name ?? localPlaceholder} = ({ if (!inputs || !prompt_variables || prompt_variables?.length === 0) return true - let hasEmptyInput = false + let hasEmptyInput = '' const requiredVars = prompt_variables?.filter(({ key, name, required }) => { const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null) return res }) || [] // compatible with old version - requiredVars.forEach(({ key }) => { + requiredVars.forEach(({ key, name }) => { if (hasEmptyInput) return if (!inputs?.[key]) - hasEmptyInput = true + hasEmptyInput = name }) if (hasEmptyInput) { - logError(t('appDebug.errorMessage.valueOfVarRequired')) + logError(t('appDebug.errorMessage.valueOfVarRequired', { key: hasEmptyInput })) return false } return !hasEmptyInput diff --git a/web/app/components/share/chat/welcome/index.tsx b/web/app/components/share/chat/welcome/index.tsx index 415bc3bd81..b16936d7ba 100644 --- a/web/app/components/share/chat/welcome/index.tsx +++ b/web/app/components/share/chat/welcome/index.tsx @@ -1,16 +1,16 @@ 'use client' import type { FC } from 'react' -import React, { useState, useEffect } from 'react' +import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' +import TemplateVarPanel, { PanelTitle, VarOpBtnGroup } from '../value-panel' import s from './style.module.css' +import { AppInfo, ChatBtn, EditBtn, FootLogo, PromptTemplate } from './massive-component' import type { SiteInfo } from '@/models/share' import type { PromptConfig } from '@/models/debug' import { ToastContext } from '@/app/components/base/toast' import Select from '@/app/components/base/select' import { DEFAULT_VALUE_MAX_LEN } from '@/config' -import TemplateVarPanel, { PanelTitle, VarOpBtnGroup } from '../value-panel' -import { AppInfo, PromptTemplate, ChatBtn, EditBtn, FootLogo } from './massive-component' // regex to match the {{}} and replace it with a span const regex = /\{\{([^}]+)\}\}/g @@ -38,15 +38,15 @@ const Welcome: FC = ({ onStartChat, canEidtInpus, savedInputs, - onInputsChange + onInputsChange, }) => { const { t } = useTranslation() const hasVar = promptConfig.prompt_variables.length > 0 const [isFold, setIsFold] = useState(true) const [inputs, setInputs] = useState>((() => { - if (hasSetInputs) { + if (hasSetInputs) return savedInputs - } + const res: Record = {} if (promptConfig) { promptConfig.prompt_variables.forEach((item) => { @@ -65,7 +65,8 @@ const Welcome: FC = ({ }) } setInputs(res) - } else { + } + else { setInputs(savedInputs) } }, [savedInputs]) @@ -98,24 +99,26 @@ const Welcome: FC = ({ {promptConfig.prompt_variables.map(item => (
- {item.type === 'select' ? ( - { setInputs({ ...inputs, [item.key]: e.target.value }) }} - className={`w-full flex-grow py-2 pl-3 pr-3 box-border rounded-lg bg-gray-50`} - maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN} - /> - )} + {item.type === 'select' + ? ( + { setInputs({ ...inputs, [item.key]: e.target.value }) }} + className={'w-full flex-grow py-2 pl-3 pr-3 box-border rounded-lg bg-gray-50'} + maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN} + /> + )}
))}
@@ -124,34 +127,33 @@ const Welcome: FC = ({ const canChat = () => { const prompt_variables = promptConfig?.prompt_variables - if (!inputs || !prompt_variables || prompt_variables?.length === 0) { + if (!inputs || !prompt_variables || prompt_variables?.length === 0) return true - } - let hasEmptyInput = false + + let hasEmptyInput = '' const requiredVars = prompt_variables?.filter(({ key, name, required }) => { const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null) return res }) || [] // compatible with old version - requiredVars.forEach(({ key }) => { - if (hasEmptyInput) { + requiredVars.forEach(({ key, name }) => { + if (hasEmptyInput) return - } - if (!inputs?.[key]) { - hasEmptyInput = true - } + + if (!inputs?.[key]) + hasEmptyInput = name }) if (hasEmptyInput) { - logError(t('appDebug.errorMessage.valueOfVarRequired')) + logError(t('appDebug.errorMessage.valueOfVarRequired', { key: hasEmptyInput })) return false } return !hasEmptyInput } const handleChat = () => { - if (!canChat()) { + if (!canChat()) return - } + onStartChat(inputs) } @@ -211,9 +213,9 @@ const Welcome: FC = ({ return ( { - if (!canChat()) { + if (!canChat()) return - } + onInputsChange(inputs) setIsFold(true) }} @@ -269,9 +271,9 @@ const Welcome: FC = ({ } const renderHasSetInputsPrivate = () => { - if (!canEidtInpus || !hasVar) { + if (!canEidtInpus || !hasVar) return null - } + return ( = ({ } const renderHasSetInputs = () => { - if (!isPublicVersion && !canEidtInpus || !hasVar) { + if ((!isPublicVersion && !canEidtInpus) || !hasVar) return null - } + return (
= ({ { !hasSetInputs && (
- {hasVar ? ( - renderVarPanel() - ) : ( - renderNoVarPanel() - )} + {hasVar + ? ( + renderVarPanel() + ) + : ( + renderNoVarPanel() + )}
) } diff --git a/web/app/components/share/chatbot/index.tsx b/web/app/components/share/chatbot/index.tsx index 474941eb1d..5f72c37593 100644 --- a/web/app/components/share/chatbot/index.tsx +++ b/web/app/components/share/chatbot/index.tsx @@ -390,21 +390,21 @@ const Main: FC = ({ if (!inputs || !prompt_variables || prompt_variables?.length === 0) return true - let hasEmptyInput = false + let hasEmptyInput = '' const requiredVars = prompt_variables?.filter(({ key, name, required }) => { const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null) return res }) || [] // compatible with old version - requiredVars.forEach(({ key }) => { + requiredVars.forEach(({ key, name }) => { if (hasEmptyInput) return if (!inputs?.[key]) - hasEmptyInput = true + hasEmptyInput = name }) if (hasEmptyInput) { - logError(t('appDebug.errorMessage.valueOfVarRequired')) + logError(t('appDebug.errorMessage.valueOfVarRequired', { key: hasEmptyInput })) return false } return !hasEmptyInput diff --git a/web/app/components/share/chatbot/welcome/index.tsx b/web/app/components/share/chatbot/welcome/index.tsx index bd170a4030..b58f9d1e27 100644 --- a/web/app/components/share/chatbot/welcome/index.tsx +++ b/web/app/components/share/chatbot/welcome/index.tsx @@ -130,21 +130,21 @@ const Welcome: FC = ({ if (!inputs || !prompt_variables || prompt_variables?.length === 0) return true - let hasEmptyInput = false + let hasEmptyInput = '' const requiredVars = prompt_variables?.filter(({ key, name, required }) => { const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null) return res }) || [] // compatible with old version - requiredVars.forEach(({ key }) => { + requiredVars.forEach(({ key, name }) => { if (hasEmptyInput) return if (!inputs?.[key]) - hasEmptyInput = true + hasEmptyInput = name }) if (hasEmptyInput) { - logError(t('appDebug.errorMessage.valueOfVarRequired')) + logError(t('appDebug.errorMessage.valueOfVarRequired', { key: hasEmptyInput })) return false } return !hasEmptyInput diff --git a/web/app/components/share/text-generation/result/index.tsx b/web/app/components/share/text-generation/result/index.tsx index 4d1a9dbe06..f53b39352b 100644 --- a/web/app/components/share/text-generation/result/index.tsx +++ b/web/app/components/share/text-generation/result/index.tsx @@ -80,21 +80,21 @@ const Result: FC = ({ if (!prompt_variables || prompt_variables?.length === 0) return true - let hasEmptyInput = false + let hasEmptyInput = '' const requiredVars = prompt_variables?.filter(({ key, name, required }) => { const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null) return res }) || [] // compatible with old version - requiredVars.forEach(({ key }) => { + requiredVars.forEach(({ key, name }) => { if (hasEmptyInput) return if (!inputs[key]) - hasEmptyInput = true + hasEmptyInput = name }) if (hasEmptyInput) { - logError(t('appDebug.errorMessage.valueOfVarRequired')) + logError(t('appDebug.errorMessage.valueOfVarRequired', { key: hasEmptyInput })) return false } return !hasEmptyInput diff --git a/web/i18n/lang/app-debug.en.ts b/web/i18n/lang/app-debug.en.ts index 0e6594a6f4..7b95418668 100644 --- a/web/i18n/lang/app-debug.en.ts +++ b/web/i18n/lang/app-debug.en.ts @@ -87,7 +87,7 @@ const translation = { }, errorMessage: { nameOfKeyRequired: 'name of the key: {{key}} required', - valueOfVarRequired: 'Variables value can not be empty', + valueOfVarRequired: '{{key}} value can not be empty', queryRequired: 'Request text is required.', waitForResponse: 'Please wait for the response to the previous message to complete.', diff --git a/web/i18n/lang/app-debug.zh.ts b/web/i18n/lang/app-debug.zh.ts index 1a813c03a0..24c37f342e 100644 --- a/web/i18n/lang/app-debug.zh.ts +++ b/web/i18n/lang/app-debug.zh.ts @@ -86,7 +86,7 @@ const translation = { }, errorMessage: { nameOfKeyRequired: '变量 {{key}} 对应的名称必填', - valueOfVarRequired: '变量值必填', + valueOfVarRequired: '{{key}}必填', queryRequired: '主要文本必填', waitForResponse: '请等待上条信息响应完成', waitForBatchResponse: '请等待批量任务完成',