From 08aa367892a25d47bb655eaeccb5e6cb7d1c6bac Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 19 Oct 2023 17:52:14 +0800 Subject: [PATCH] feat: add context missing warning (#1384) Co-authored-by: StyleZhang --- .../config-prompt/advanced-prompt-input.tsx | 96 ++++++++++++------- .../app/configuration/config-prompt/index.tsx | 9 ++ .../config-prompt/simple-prompt-input.tsx | 1 + .../config-prompt/style.module.css | 5 + .../components/base/prompt-editor/index.tsx | 31 +++--- .../plugins/component-picker.tsx | 26 +++-- web/i18n/lang/app-debug.en.ts | 1 + web/i18n/lang/app-debug.zh.ts | 1 + web/i18n/lang/common.zh.ts | 2 +- 9 files changed, 115 insertions(+), 57 deletions(-) diff --git a/web/app/components/app/configuration/config-prompt/advanced-prompt-input.tsx b/web/app/components/app/configuration/config-prompt/advanced-prompt-input.tsx index 972cbf62fa..6c32746abb 100644 --- a/web/app/components/app/configuration/config-prompt/advanced-prompt-input.tsx +++ b/web/app/components/app/configuration/config-prompt/advanced-prompt-input.tsx @@ -18,6 +18,7 @@ import PromptEditor from '@/app/components/base/prompt-editor' import ConfigContext from '@/context/debug-configuration' import { getNewVar, getVars } from '@/utils/var' import { AppType } from '@/types/app' +import { AlertCircle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback' type Props = { type: PromptRole @@ -28,6 +29,8 @@ type Props = { canDelete: boolean onDelete: () => void promptVariables: PromptVariable[] + isContextMissing: boolean + onHideContextMissingTip: () => void } const AdvancedPromptInput: FC = ({ @@ -39,6 +42,8 @@ const AdvancedPromptInput: FC = ({ canDelete, onDelete, promptVariables, + isContextMissing, + onHideContextMissingTip, }) => { const { t } = useTranslation() @@ -91,50 +96,71 @@ const AdvancedPromptInput: FC = ({ } const editorHeight = isChatMode ? 'h-[200px]' : 'h-[508px]' - + const contextMissing = ( +
+
+ +
{t('appDebug.promptMode.contextMissing')}
+
+
{t('common.operation.ok')}
+
+ ) return ( -
+
-
- {isChatMode - ? ( - - ) - : ( -
+ {isContextMissing + ? contextMissing + : ( +
+ {isChatMode + ? ( + + ) + : ( +
-
{t('appDebug.pageTitle.line1')} -
- - {t('appDebug.promptTip')} -
} - selector='config-prompt-tooltip'> - - -
)} -
- {canDelete && ( - - )} - {!isCopied - ? ( - { - copy(value) - setIsCopied(true) - }} /> - ) - : ( - - )} +
{t('appDebug.pageTitle.line1')} +
+ + {t('appDebug.promptTip')} +
} + selector='config-prompt-tooltip'> + + +
)} +
+ {canDelete && ( + + )} + {!isCopied + ? ( + { + copy(value) + setIsCopied(true) + }} /> + ) + : ( + + )} +
+
+ )} -
-
({ id: item.id, diff --git a/web/app/components/app/configuration/config-prompt/index.tsx b/web/app/components/app/configuration/config-prompt/index.tsx index cfcd1ec05b..8c789ae58b 100644 --- a/web/app/components/app/configuration/config-prompt/index.tsx +++ b/web/app/components/app/configuration/config-prompt/index.tsx @@ -34,6 +34,8 @@ const Prompt: FC = ({ currentAdvancedPrompt, setCurrentAdvancedPrompt, modelModeType, + dataSets, + hasSetBlockStatus, } = useContext(ConfigContext) const handleMessageTypeChange = (index: number, role: PromptRole) => { @@ -84,6 +86,9 @@ const Prompt: FC = ({ setCurrentAdvancedPrompt(newPrompt) } + const isContextMissing = dataSets.length > 0 && !hasSetBlockStatus.context + const [isHideContextMissTip, setIsHideContextMissTip] = React.useState(false) + if (!isAdvancedMode) { return ( = ({ onDelete={() => handlePromptDelete(index)} onChange={value => handleValueChange(value, index)} promptVariables={promptVariables} + isContextMissing={isContextMissing && !isHideContextMissTip} + onHideContextMissingTip={() => setIsHideContextMissTip(true)} /> )) ) @@ -125,6 +132,8 @@ const Prompt: FC = ({ onDelete={() => handlePromptDelete(0)} onChange={value => handleValueChange(value)} promptVariables={promptVariables} + isContextMissing={isContextMissing && !isHideContextMissTip} + onHideContextMissingTip={() => setIsHideContextMissTip(true)} /> ) } diff --git a/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx b/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx index 10a7377502..e61b26d127 100644 --- a/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx +++ b/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx @@ -113,6 +113,7 @@ const Prompt: FC = ({ className='min-h-[210px]' value={promptTemplate} contextBlock={{ + show: false, selectable: !hasSetBlockStatus.context, datasets: dataSets.map(item => ({ id: item.id, diff --git a/web/app/components/app/configuration/config-prompt/style.module.css b/web/app/components/app/configuration/config-prompt/style.module.css index 2c9f0022ae..66785620b3 100644 --- a/web/app/components/app/configuration/config-prompt/style.module.css +++ b/web/app/components/app/configuration/config-prompt/style.module.css @@ -14,6 +14,11 @@ box-sizing: border-box; } +.warningBorder { + border: 2px solid #F79009; + border-radius: 12px; +} + .optionWrap { display: none; } diff --git a/web/app/components/base/prompt-editor/index.tsx b/web/app/components/base/prompt-editor/index.tsx index 72f35393cf..9255d78af2 100644 --- a/web/app/components/base/prompt-editor/index.tsx +++ b/web/app/components/base/prompt-editor/index.tsx @@ -49,6 +49,7 @@ export type PromptEditorProps = { onChange?: (text: string) => void onBlur?: () => void contextBlock?: { + show?: boolean selectable?: boolean datasets: Dataset[] onInsert?: () => void @@ -82,6 +83,7 @@ const PromptEditor: FC = ({ onChange, onBlur, contextBlock = { + show: true, selectable: true, datasets: [], onAddContext: () => {}, @@ -158,23 +160,30 @@ const PromptEditor: FC = ({ /> - - + { + contextBlock.show && ( + <> + + + + ) + } { historyBlock.show && ( diff --git a/web/app/components/base/prompt-editor/plugins/component-picker.tsx b/web/app/components/base/prompt-editor/plugins/component-picker.tsx index 8d514eb28b..29da4d9f0a 100644 --- a/web/app/components/base/prompt-editor/plugins/component-picker.tsx +++ b/web/app/components/base/prompt-editor/plugins/component-picker.tsx @@ -93,6 +93,7 @@ type ComponentPickerProps = { contextDisabled?: boolean historyDisabled?: boolean queryDisabled?: boolean + contextShow?: boolean historyShow?: boolean queryShow?: boolean } @@ -100,6 +101,7 @@ const ComponentPicker: FC = ({ contextDisabled, historyDisabled, queryDisabled, + contextShow, historyShow, queryShow, }) => { @@ -111,16 +113,20 @@ const ComponentPicker: FC = ({ }) const options = [ - new ComponentPickerOption(t('common.promptEditor.context.item.title'), { - desc: t('common.promptEditor.context.item.desc'), - icon: , - onSelect: () => { - if (contextDisabled) - return - editor.dispatchCommand(INSERT_CONTEXT_BLOCK_COMMAND, undefined) - }, - disabled: contextDisabled, - }), + ...contextShow + ? [ + new ComponentPickerOption(t('common.promptEditor.context.item.title'), { + desc: t('common.promptEditor.context.item.desc'), + icon: , + onSelect: () => { + if (contextDisabled) + return + editor.dispatchCommand(INSERT_CONTEXT_BLOCK_COMMAND, undefined) + }, + disabled: contextDisabled, + }), + ] + : [], new ComponentPickerOption(t('common.promptEditor.variable.item.title'), { desc: t('common.promptEditor.variable.item.desc'), icon: , diff --git a/web/i18n/lang/app-debug.en.ts b/web/i18n/lang/app-debug.en.ts index ac88c32175..63c8d76917 100644 --- a/web/i18n/lang/app-debug.en.ts +++ b/web/i18n/lang/app-debug.en.ts @@ -16,6 +16,7 @@ const translation = { operation: { addMessage: 'Add Message', }, + contextMissing: 'Context component missed, the effectiveness of the prompt may not be good.', }, operation: { applyConfig: 'Publish', diff --git a/web/i18n/lang/app-debug.zh.ts b/web/i18n/lang/app-debug.zh.ts index 31bad3d7a7..2f6ea41f07 100644 --- a/web/i18n/lang/app-debug.zh.ts +++ b/web/i18n/lang/app-debug.zh.ts @@ -16,6 +16,7 @@ const translation = { operation: { addMessage: '添加消息', }, + contextMissing: '上下文内容块缺失,提示词的有效性可能不好。', }, operation: { applyConfig: '发布', diff --git a/web/i18n/lang/common.zh.ts b/web/i18n/lang/common.zh.ts index 65353b178a..72905b9996 100644 --- a/web/i18n/lang/common.zh.ts +++ b/web/i18n/lang/common.zh.ts @@ -136,7 +136,7 @@ const translation = { owner: '所有者', admin: '管理员', adminTip: '能够建立应用程序和管理团队设置', - normal: '正常人', + normal: '成员', normalTip: '只能使用应用程序,不能建立应用程序', inviteTeamMember: '添加团队成员', inviteTeamMemberTip: '对方在登录后可以访问你的团队数据。',