From 317600c3bc7aafe5645663bc7ea719ae26b80b57 Mon Sep 17 00:00:00 2001 From: chenqianhe <1278095698@qq.com> Date: Thu, 15 Aug 2024 13:53:07 +0800 Subject: [PATCH 1/2] fix: make optional var nullable --- app/components/index.tsx | 10 ++++++---- app/components/welcome/index.tsx | 15 ++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/components/index.tsx b/app/components/index.tsx index 4591462..3e756f0 100644 --- a/app/components/index.tsx +++ b/app/components/index.tsx @@ -276,11 +276,13 @@ const Main: FC = () => { if (!currInputs || !promptConfig?.prompt_variables) return true - const inputLens = Object.values(currInputs).length - const promptVariablesLens = promptConfig.prompt_variables.length + let emptyRequiredInput = false + promptConfig.prompt_variables.forEach((item) => { + if (item.required && !currInputs[item.key]) + emptyRequiredInput = true + }) - const emptyInput = inputLens < promptVariablesLens || Object.values(currInputs).find(v => !v) - if (emptyInput) { + if (emptyRequiredInput) { logError(t('app.errorMessage.valueOfVarRequired')) return false } diff --git a/app/components/welcome/index.tsx b/app/components/welcome/index.tsx index a746fef..d42b6fc 100644 --- a/app/components/welcome/index.tsx +++ b/app/components/welcome/index.tsx @@ -129,10 +129,12 @@ const Welcome: FC = ({ } const canChat = () => { - const inputLens = Object.values(inputs).length - const promptVariablesLens = promptConfig.prompt_variables.length - const emptyInput = inputLens < promptVariablesLens || Object.values(inputs).filter(v => v === '').length > 0 - if (emptyInput) { + let emptyRequiredInput = false + promptConfig.prompt_variables.forEach((item) => { + if (item.required && !inputs[item.key]) + emptyRequiredInput = true + }) + if (emptyRequiredInput) { logError(t('app.errorMessage.valueOfVarRequired')) return false } @@ -142,7 +144,10 @@ const Welcome: FC = ({ const handleChat = () => { if (!canChat()) return - + Object.keys(inputs).forEach((key) => { + if (!inputs[key]) + delete inputs[key] + }) onStartChat(inputs) } From f57be6bda922cf9cb9f8e275259e8bfe95e15ea9 Mon Sep 17 00:00:00 2001 From: chenqianhe <1278095698@qq.com> Date: Thu, 15 Aug 2024 13:57:39 +0800 Subject: [PATCH 2/2] fix: fix var name --- app/components/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/index.tsx b/app/components/index.tsx index 3e756f0..fbc44af 100644 --- a/app/components/index.tsx +++ b/app/components/index.tsx @@ -199,7 +199,7 @@ const Main: FC = () => { if (calculatedIntroduction && calculatedPromptVariables) calculatedIntroduction = replaceVarWithValues(calculatedIntroduction, promptConfig?.prompt_variables || [], calculatedPromptVariables) - const openstatement = { + const openStatement = { id: `${Date.now()}`, content: calculatedIntroduction, isAnswer: true,