Unverified Commit 08aa3678 authored by Joel's avatar Joel Committed by GitHub

feat: add context missing warning (#1384)

Co-authored-by: 's avatarStyleZhang <jasonapring2015@outlook.com>
parent ff527a01
...@@ -18,6 +18,7 @@ import PromptEditor from '@/app/components/base/prompt-editor' ...@@ -18,6 +18,7 @@ import PromptEditor from '@/app/components/base/prompt-editor'
import ConfigContext from '@/context/debug-configuration' import ConfigContext from '@/context/debug-configuration'
import { getNewVar, getVars } from '@/utils/var' import { getNewVar, getVars } from '@/utils/var'
import { AppType } from '@/types/app' import { AppType } from '@/types/app'
import { AlertCircle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback'
type Props = { type Props = {
type: PromptRole type: PromptRole
...@@ -28,6 +29,8 @@ type Props = { ...@@ -28,6 +29,8 @@ type Props = {
canDelete: boolean canDelete: boolean
onDelete: () => void onDelete: () => void
promptVariables: PromptVariable[] promptVariables: PromptVariable[]
isContextMissing: boolean
onHideContextMissingTip: () => void
} }
const AdvancedPromptInput: FC<Props> = ({ const AdvancedPromptInput: FC<Props> = ({
...@@ -39,6 +42,8 @@ const AdvancedPromptInput: FC<Props> = ({ ...@@ -39,6 +42,8 @@ const AdvancedPromptInput: FC<Props> = ({
canDelete, canDelete,
onDelete, onDelete,
promptVariables, promptVariables,
isContextMissing,
onHideContextMissingTip,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
...@@ -91,50 +96,71 @@ const AdvancedPromptInput: FC<Props> = ({ ...@@ -91,50 +96,71 @@ const AdvancedPromptInput: FC<Props> = ({
} }
const editorHeight = isChatMode ? 'h-[200px]' : 'h-[508px]' const editorHeight = isChatMode ? 'h-[200px]' : 'h-[508px]'
const contextMissing = (
<div
className='flex justify-between items-center h-11 pt-2 pr-3 pb-1 pl-4 rounded-tl-xl rounded-tr-xl'
style={{
background: 'linear-gradient(180deg, #FEF0C7 0%, rgba(254, 240, 199, 0) 100%)',
}}
>
<div className='flex items-center pr-2' >
<AlertCircle className='mr-1 w-4 h-4 text-[#F79009]'/>
<div className='leading-[18px] text-[13px] font-medium text-[#DC6803]'>{t('appDebug.promptMode.contextMissing')}</div>
</div>
<div
className='flex items-center h-6 px-2 rounded-md bg-[#fff] border border-gray-200 shadow-xs text-xs font-medium text-primary-600 cursor-pointer'
onClick={onHideContextMissingTip}
>{t('common.operation.ok')}</div>
</div>
)
return ( return (
<div className={`relative ${s.gradientBorder}`}> <div className={`relative ${!isContextMissing ? s.gradientBorder : s.warningBorder}`}>
<div className='rounded-xl bg-white'> <div className='rounded-xl bg-white'>
<div className={cn(s.boxHeader, 'flex justify-between items-center h-11 pt-2 pr-3 pb-1 pl-4 rounded-tl-xl rounded-tr-xl bg-white hover:shadow-xs')}> {isContextMissing
{isChatMode ? contextMissing
? ( : (
<MessageTypeSelector value={type} onChange={onTypeChange} /> <div className={cn(s.boxHeader, 'flex justify-between items-center h-11 pt-2 pr-3 pb-1 pl-4 rounded-tl-xl rounded-tr-xl bg-white hover:shadow-xs')}>
) {isChatMode
: ( ? (
<div className='flex items-center space-x-1'> <MessageTypeSelector value={type} onChange={onTypeChange} />
)
: (
<div className='flex items-center space-x-1'>
<div className='text-sm font-semibold uppercase text-indigo-800'>{t('appDebug.pageTitle.line1')} <div className='text-sm font-semibold uppercase text-indigo-800'>{t('appDebug.pageTitle.line1')}
</div> </div>
<Tooltip <Tooltip
htmlContent={<div className='w-[180px]'> htmlContent={<div className='w-[180px]'>
{t('appDebug.promptTip')} {t('appDebug.promptTip')}
</div>} </div>}
selector='config-prompt-tooltip'> selector='config-prompt-tooltip'>
<HelpCircle className='w-[14px] h-[14px] text-indigo-400' /> <HelpCircle className='w-[14px] h-[14px] text-indigo-400' />
</Tooltip> </Tooltip>
</div>)} </div>)}
<div className={cn(s.optionWrap, 'items-center space-x-1')}> <div className={cn(s.optionWrap, 'items-center space-x-1')}>
{canDelete && ( {canDelete && (
<Trash03 onClick={onDelete} className='h-6 w-6 p-1 text-gray-500 cursor-pointer' /> <Trash03 onClick={onDelete} className='h-6 w-6 p-1 text-gray-500 cursor-pointer' />
)} )}
{!isCopied {!isCopied
? ( ? (
<Clipboard className='h-6 w-6 p-1 text-gray-500 cursor-pointer' onClick={() => { <Clipboard className='h-6 w-6 p-1 text-gray-500 cursor-pointer' onClick={() => {
copy(value) copy(value)
setIsCopied(true) setIsCopied(true)
}} /> }} />
) )
: ( : (
<ClipboardCheck className='h-6 w-6 p-1 text-gray-500' /> <ClipboardCheck className='h-6 w-6 p-1 text-gray-500' />
)} )}
</div>
</div>
)}
</div>
</div>
<div className={cn(editorHeight, 'px-4 min-h-[102px] overflow-y-auto text-sm text-gray-700')}> <div className={cn(editorHeight, 'px-4 min-h-[102px] overflow-y-auto text-sm text-gray-700')}>
<PromptEditor <PromptEditor
className={editorHeight} className={editorHeight}
value={value} value={value}
contextBlock={{ contextBlock={{
show: true,
selectable: !hasSetBlockStatus.context, selectable: !hasSetBlockStatus.context,
datasets: dataSets.map(item => ({ datasets: dataSets.map(item => ({
id: item.id, id: item.id,
......
...@@ -34,6 +34,8 @@ const Prompt: FC<IPromptProps> = ({ ...@@ -34,6 +34,8 @@ const Prompt: FC<IPromptProps> = ({
currentAdvancedPrompt, currentAdvancedPrompt,
setCurrentAdvancedPrompt, setCurrentAdvancedPrompt,
modelModeType, modelModeType,
dataSets,
hasSetBlockStatus,
} = useContext(ConfigContext) } = useContext(ConfigContext)
const handleMessageTypeChange = (index: number, role: PromptRole) => { const handleMessageTypeChange = (index: number, role: PromptRole) => {
...@@ -84,6 +86,9 @@ const Prompt: FC<IPromptProps> = ({ ...@@ -84,6 +86,9 @@ const Prompt: FC<IPromptProps> = ({
setCurrentAdvancedPrompt(newPrompt) setCurrentAdvancedPrompt(newPrompt)
} }
const isContextMissing = dataSets.length > 0 && !hasSetBlockStatus.context
const [isHideContextMissTip, setIsHideContextMissTip] = React.useState(false)
if (!isAdvancedMode) { if (!isAdvancedMode) {
return ( return (
<SimplePromptInput <SimplePromptInput
...@@ -112,6 +117,8 @@ const Prompt: FC<IPromptProps> = ({ ...@@ -112,6 +117,8 @@ const Prompt: FC<IPromptProps> = ({
onDelete={() => handlePromptDelete(index)} onDelete={() => handlePromptDelete(index)}
onChange={value => handleValueChange(value, index)} onChange={value => handleValueChange(value, index)}
promptVariables={promptVariables} promptVariables={promptVariables}
isContextMissing={isContextMissing && !isHideContextMissTip}
onHideContextMissingTip={() => setIsHideContextMissTip(true)}
/> />
)) ))
) )
...@@ -125,6 +132,8 @@ const Prompt: FC<IPromptProps> = ({ ...@@ -125,6 +132,8 @@ const Prompt: FC<IPromptProps> = ({
onDelete={() => handlePromptDelete(0)} onDelete={() => handlePromptDelete(0)}
onChange={value => handleValueChange(value)} onChange={value => handleValueChange(value)}
promptVariables={promptVariables} promptVariables={promptVariables}
isContextMissing={isContextMissing && !isHideContextMissTip}
onHideContextMissingTip={() => setIsHideContextMissTip(true)}
/> />
) )
} }
......
...@@ -113,6 +113,7 @@ const Prompt: FC<ISimplePromptInput> = ({ ...@@ -113,6 +113,7 @@ const Prompt: FC<ISimplePromptInput> = ({
className='min-h-[210px]' className='min-h-[210px]'
value={promptTemplate} value={promptTemplate}
contextBlock={{ contextBlock={{
show: false,
selectable: !hasSetBlockStatus.context, selectable: !hasSetBlockStatus.context,
datasets: dataSets.map(item => ({ datasets: dataSets.map(item => ({
id: item.id, id: item.id,
......
...@@ -14,6 +14,11 @@ ...@@ -14,6 +14,11 @@
box-sizing: border-box; box-sizing: border-box;
} }
.warningBorder {
border: 2px solid #F79009;
border-radius: 12px;
}
.optionWrap { .optionWrap {
display: none; display: none;
} }
......
...@@ -49,6 +49,7 @@ export type PromptEditorProps = { ...@@ -49,6 +49,7 @@ export type PromptEditorProps = {
onChange?: (text: string) => void onChange?: (text: string) => void
onBlur?: () => void onBlur?: () => void
contextBlock?: { contextBlock?: {
show?: boolean
selectable?: boolean selectable?: boolean
datasets: Dataset[] datasets: Dataset[]
onInsert?: () => void onInsert?: () => void
...@@ -82,6 +83,7 @@ const PromptEditor: FC<PromptEditorProps> = ({ ...@@ -82,6 +83,7 @@ const PromptEditor: FC<PromptEditorProps> = ({
onChange, onChange,
onBlur, onBlur,
contextBlock = { contextBlock = {
show: true,
selectable: true, selectable: true,
datasets: [], datasets: [],
onAddContext: () => {}, onAddContext: () => {},
...@@ -158,23 +160,30 @@ const PromptEditor: FC<PromptEditorProps> = ({ ...@@ -158,23 +160,30 @@ const PromptEditor: FC<PromptEditorProps> = ({
/> />
<ComponentPicker <ComponentPicker
contextDisabled={!contextBlock.selectable} contextDisabled={!contextBlock.selectable}
contextShow={contextBlock.show}
historyDisabled={!historyBlock.selectable} historyDisabled={!historyBlock.selectable}
historyShow={historyBlock.show} historyShow={historyBlock.show}
queryDisabled={!queryBlock.selectable} queryDisabled={!queryBlock.selectable}
queryShow={queryBlock.show} queryShow={queryBlock.show}
/> />
<VariablePicker items={variableBlock.variables} /> <VariablePicker items={variableBlock.variables} />
<ContextBlock {
datasets={contextBlock.datasets} contextBlock.show && (
onAddContext={contextBlock.onAddContext} <>
onInsert={contextBlock.onInsert} <ContextBlock
onDelete={contextBlock.onDelete} datasets={contextBlock.datasets}
/> onAddContext={contextBlock.onAddContext}
<ContextBlockReplacementBlock onInsert={contextBlock.onInsert}
datasets={contextBlock.datasets} onDelete={contextBlock.onDelete}
onAddContext={contextBlock.onAddContext} />
onInsert={contextBlock.onInsert} <ContextBlockReplacementBlock
/> datasets={contextBlock.datasets}
onAddContext={contextBlock.onAddContext}
onInsert={contextBlock.onInsert}
/>
</>
)
}
<VariableBlock /> <VariableBlock />
{ {
historyBlock.show && ( historyBlock.show && (
......
...@@ -93,6 +93,7 @@ type ComponentPickerProps = { ...@@ -93,6 +93,7 @@ type ComponentPickerProps = {
contextDisabled?: boolean contextDisabled?: boolean
historyDisabled?: boolean historyDisabled?: boolean
queryDisabled?: boolean queryDisabled?: boolean
contextShow?: boolean
historyShow?: boolean historyShow?: boolean
queryShow?: boolean queryShow?: boolean
} }
...@@ -100,6 +101,7 @@ const ComponentPicker: FC<ComponentPickerProps> = ({ ...@@ -100,6 +101,7 @@ const ComponentPicker: FC<ComponentPickerProps> = ({
contextDisabled, contextDisabled,
historyDisabled, historyDisabled,
queryDisabled, queryDisabled,
contextShow,
historyShow, historyShow,
queryShow, queryShow,
}) => { }) => {
...@@ -111,16 +113,20 @@ const ComponentPicker: FC<ComponentPickerProps> = ({ ...@@ -111,16 +113,20 @@ const ComponentPicker: FC<ComponentPickerProps> = ({
}) })
const options = [ const options = [
new ComponentPickerOption(t('common.promptEditor.context.item.title'), { ...contextShow
desc: t('common.promptEditor.context.item.desc'), ? [
icon: <File05 className='w-4 h-4 text-[#6938EF]' />, new ComponentPickerOption(t('common.promptEditor.context.item.title'), {
onSelect: () => { desc: t('common.promptEditor.context.item.desc'),
if (contextDisabled) icon: <File05 className='w-4 h-4 text-[#6938EF]' />,
return onSelect: () => {
editor.dispatchCommand(INSERT_CONTEXT_BLOCK_COMMAND, undefined) if (contextDisabled)
}, return
disabled: contextDisabled, editor.dispatchCommand(INSERT_CONTEXT_BLOCK_COMMAND, undefined)
}), },
disabled: contextDisabled,
}),
]
: [],
new ComponentPickerOption(t('common.promptEditor.variable.item.title'), { new ComponentPickerOption(t('common.promptEditor.variable.item.title'), {
desc: t('common.promptEditor.variable.item.desc'), desc: t('common.promptEditor.variable.item.desc'),
icon: <Variable className='w-4 h-4 text-[#2970FF]' />, icon: <Variable className='w-4 h-4 text-[#2970FF]' />,
......
...@@ -16,6 +16,7 @@ const translation = { ...@@ -16,6 +16,7 @@ const translation = {
operation: { operation: {
addMessage: 'Add Message', addMessage: 'Add Message',
}, },
contextMissing: 'Context component missed, the effectiveness of the prompt may not be good.',
}, },
operation: { operation: {
applyConfig: 'Publish', applyConfig: 'Publish',
......
...@@ -16,6 +16,7 @@ const translation = { ...@@ -16,6 +16,7 @@ const translation = {
operation: { operation: {
addMessage: '添加消息', addMessage: '添加消息',
}, },
contextMissing: '上下文内容块缺失,提示词的有效性可能不好。',
}, },
operation: { operation: {
applyConfig: '发布', applyConfig: '发布',
......
...@@ -136,7 +136,7 @@ const translation = { ...@@ -136,7 +136,7 @@ const translation = {
owner: '所有者', owner: '所有者',
admin: '管理员', admin: '管理员',
adminTip: '能够建立应用程序和管理团队设置', adminTip: '能够建立应用程序和管理团队设置',
normal: '正常人', normal: '成员',
normalTip: '只能使用应用程序,不能建立应用程序', normalTip: '只能使用应用程序,不能建立应用程序',
inviteTeamMember: '添加团队成员', inviteTeamMember: '添加团队成员',
inviteTeamMemberTip: '对方在登录后可以访问你的团队数据。', inviteTeamMemberTip: '对方在登录后可以访问你的团队数据。',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment