From 8c785e268bbcc2cfb4b1bc113d3e0256a49cd8f7 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Sun, 1 Sep 2024 11:24:54 +0800 Subject: [PATCH] completion debug & preview --- .../app/configuration/debug/index.tsx | 93 +++--- .../prompt-value-panel/index.tsx | 276 ++++++++---------- .../configuration/prompt-value-panel/utils.ts | 13 + web/app/components/base/chat/chat/hooks.ts | 2 +- .../new-feature-panel/feature-bar.tsx | 13 +- .../workflow/panel/debug-and-preview/hooks.ts | 2 +- web/i18n/en-US/app-debug.ts | 1 + web/i18n/zh-Hans/app-debug.ts | 1 + web/types/app.ts | 2 +- 9 files changed, 206 insertions(+), 197 deletions(-) create mode 100644 web/app/components/app/configuration/prompt-value-panel/utils.ts diff --git a/web/app/components/app/configuration/debug/index.tsx b/web/app/components/app/configuration/debug/index.tsx index a46ef24e64..3d40ff23c0 100644 --- a/web/app/components/app/configuration/debug/index.tsx +++ b/web/app/components/app/configuration/debug/index.tsx @@ -8,6 +8,7 @@ import { useBoolean } from 'ahooks' import { RiAddLine, RiEqualizer2Line, + RiSparklingFill, } from '@remixicon/react' import { useContext } from 'use-context-selector' import { useShallow } from 'zustand/react/shallow' @@ -47,6 +48,7 @@ import { useProviderContext } from '@/context/provider-context' import AgentLogModal from '@/app/components/base/agent-log-modal' import PromptLogModal from '@/app/components/base/prompt-log-modal' import { useStore as useAppStore } from '@/app/components/app/store' +import { useFeatures } from '@/app/components/base/features/hooks' type IDebug = { isAPIKeySet: boolean @@ -82,8 +84,8 @@ const Debug: FC = ({ speechToTextConfig, textToSpeechConfig, citationConfig, - moderationConfig, - moreLikeThisConfig, + // moderationConfig, + // moreLikeThisConfig, formattingChanged, setFormattingChanged, dataSets, @@ -200,6 +202,7 @@ const Debug: FC = ({ const [completionRes, setCompletionRes] = useState('') const [messageId, setMessageId] = useState(null) + const features = useFeatures(s => s.features) const sendTextCompletion = async () => { if (isResponding) { @@ -230,36 +233,33 @@ const Debug: FC = ({ completion_prompt_config: {}, user_input_form: promptVariablesToUserInputsForm(modelConfig.configs.prompt_variables), dataset_query_variable: contextVar || '', - opening_statement: introduction, - suggested_questions_after_answer: suggestedQuestionsAfterAnswerConfig, - speech_to_text: speechToTextConfig, - retriever_resource: citationConfig, - sensitive_word_avoidance: moderationConfig, - more_like_this: moreLikeThisConfig, - model: { - provider: modelConfig.provider, - name: modelConfig.model_id, - mode: modelConfig.mode, - completion_params: completionParams as any, - }, - text_to_speech: { - enabled: false, - voice: '', - language: '', - }, - agent_mode: { - enabled: false, - tools: [], - }, dataset_configs: { ...datasetConfigs, datasets: { datasets: [...postDatasets], } as any, }, + agent_mode: { + enabled: false, + tools: [], + }, + model: { + provider: modelConfig.provider, + name: modelConfig.model_id, + mode: modelConfig.mode, + completion_params: completionParams as any, + }, + more_like_this: features.moreLikeThis as any, + sensitive_word_avoidance: features.moderation as any, + text_to_speech: features.text2speech as any, + // ##TODO## file_upload file_upload: { image: visionConfig, }, + opening_statement: introduction, + suggested_questions_after_answer: suggestedQuestionsAfterAnswerConfig, + speech_to_text: speechToTextConfig, + retriever_resource: citationConfig, } if (isAdvancedMode) { @@ -449,7 +449,6 @@ const Debug: FC = ({ )} - {/* ##TODO## new style of completion */} {mode === AppType.completion && ( = ({ )} {/* Text Generation */} {mode === AppType.completion && ( -
- + <> {(completionRes || isResponding) && ( - { }} - supportAnnotation - appId={appId} - varList={varList} - siteInfo={null} - /> + <> +
+
+ { }} + supportAnnotation + appId={appId} + varList={varList} + siteInfo={null} + /> +
+ )} -
+ {!completionRes && !isResponding && ( +
+ +
{t('appDebug.noResult')}
+
+ )} + )} {mode === AppType.completion && showPromptLogModal && ( = ({ return key && key?.trim() && name && name?.trim() }) - const promptVariableObj = (() => { + const promptVariableObj = useMemo(() => { const obj: Record = {} promptVariables.forEach((input) => { obj[input.key] = true }) return obj - })() + }, [promptVariables]) - const canNotRun = (() => { + const canNotRun = useMemo(() => { if (mode !== AppType.completion) return true @@ -62,19 +64,8 @@ const PromptValuePanel: FC = ({ } else { return !modelConfig.configs.prompt_template } - })() - const renderRunButton = () => { - return ( - - ) - } + }, [chatPromptConfig.prompt, completionPromptConfig.prompt?.text, isAdvancedMode, mode, modelConfig.configs.prompt_template, modelModeType]) + const handleInputValueChange = (key: string, value: string) => { if (!(key in promptVariableObj)) return @@ -95,142 +86,129 @@ const PromptValuePanel: FC = ({ setInputs(newInputs) } + const setShowAppConfigureFeaturesModal = useAppStore(s => s.setShowAppConfigureFeaturesModal) + return ( -
-
-
-
setUserInputFieldCollapse(!userInputFieldCollapse)}> - { - userInputFieldCollapse - ? - : - } -
{t('appDebug.inputs.userInputField')}
+ <> +
+
+
setUserInputFieldCollapse(!userInputFieldCollapse)}> +
{t('appDebug.inputs.userInputField')}
+ {userInputFieldCollapse && } + {!userInputFieldCollapse && }
- {appType === AppType.completion && promptVariables.length > 0 && !userInputFieldCollapse && ( -
{t('appDebug.inputs.completionVarTip')}
+ {!userInputFieldCollapse && ( +
{t('appDebug.inputs.completionVarTip')}
)}
- {!userInputFieldCollapse && ( - <> - { - promptVariables.length > 0 - ? ( -
- {promptVariables.map(({ key, name, type, options, max_length, required }) => ( -
-
{name || key}
- {type === 'select' && ( - { handleInputValueChange(key, e.target.value) }} - maxLength={max_length || DEFAULT_VALUE_MAX_LEN} - /> - )} - {type === 'paragraph' && ( -