diff --git a/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx b/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx index 480f2ed924..41e5365b0b 100644 --- a/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx +++ b/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx @@ -21,9 +21,12 @@ type Props = { readOnly?: boolean showRemove?: boolean onRemove?: () => void - isChatModel: boolean - isChatApp: boolean - hasSetBlockStatus: { + justVar?: boolean + isChatModel?: boolean + isChatApp?: boolean + isShowContext?: boolean + hasSetBlockStatus?: { + context: boolean history: boolean query: boolean } @@ -37,8 +40,10 @@ const Editor: FC = ({ readOnly, showRemove, onRemove, + justVar, isChatModel, isChatApp, + isShowContext, hasSetBlockStatus, }) => { const { t } = useTranslation() @@ -112,8 +117,8 @@ const Editor: FC = ({ style={isExpand ? { height: editorExpandHeight - 5 } : {}} value={value} contextBlock={{ - show: false, - selectable: true, + show: justVar ? false : isShowContext, + selectable: !hasSetBlockStatus?.context, datasets: [], onAddContext: () => { }, }} @@ -126,7 +131,7 @@ const Editor: FC = ({ onAddExternalTool: () => { }, }} historyBlock={{ - show: isShowHistory, + show: justVar ? false : isShowHistory, selectable: !hasSetBlockStatus?.history, history: { user: 'Human', @@ -135,7 +140,7 @@ const Editor: FC = ({ onEditRole: () => { }, }} queryBlock={{ - show: isShowQuery, + show: justVar ? false : isShowQuery, selectable: !hasSetBlockStatus?.query, }} onChange={onChange} diff --git a/web/app/components/workflow/nodes/answer/panel.tsx b/web/app/components/workflow/nodes/answer/panel.tsx index 29c704c753..e2bf44cc0a 100644 --- a/web/app/components/workflow/nodes/answer/panel.tsx +++ b/web/app/components/workflow/nodes/answer/panel.tsx @@ -45,6 +45,7 @@ const Panel: FC> = ({ void + isShowContext: boolean hasSetBlockStatus: { + context: boolean history: boolean query: boolean } @@ -33,6 +35,7 @@ const ConfigPrompt: FC = ({ payload, variables, onChange, + isShowContext, hasSetBlockStatus, }) => { const { t } = useTranslation() @@ -131,6 +134,7 @@ const ConfigPrompt: FC = ({ onRemove={handleRemove(index)} isChatModel={isChatModel} isChatApp={isChatApp} + isShowContext={isShowContext} hasSetBlockStatus={hasSetBlockStatus} /> ) @@ -155,6 +159,7 @@ const ConfigPrompt: FC = ({ readOnly={readOnly} isChatModel={isChatModel} isChatApp={isChatApp} + isShowContext={isShowContext} hasSetBlockStatus={hasSetBlockStatus} /> diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx index 8e859b7ef4..015db68bf6 100644 --- a/web/app/components/workflow/nodes/llm/panel.tsx +++ b/web/app/components/workflow/nodes/llm/panel.tsx @@ -167,6 +167,7 @@ const Panel: FC> = ({ readOnly={readOnly} isChatModel={isChatModel} isChatApp={isChatMode} + isShowContext={inputs.context?.variable_selector?.length > 0} payload={inputs.prompt_template} variables={inputs.variables.map(item => item.variable)} onChange={handlePromptChange} diff --git a/web/app/components/workflow/nodes/llm/use-config.ts b/web/app/components/workflow/nodes/llm/use-config.ts index 6a65588ee5..8600f97d78 100644 --- a/web/app/components/workflow/nodes/llm/use-config.ts +++ b/web/app/components/workflow/nodes/llm/use-config.ts @@ -13,7 +13,7 @@ import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-cr import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run' import type { PromptItem } from '@/models/debug' import { RETRIEVAL_OUTPUT_STRUCT } from '@/app/components/workflow/constants' -import { checkHasHistoryBlock, checkHasQueryBlock } from '@/app/components/base/prompt-editor/constants' +import { checkHasContextBlock, checkHasHistoryBlock, checkHasQueryBlock } from '@/app/components/base/prompt-editor/constants' const useConfig = (id: string, payload: LLMNodeType) => { const isChatMode = useIsChatMode() @@ -33,22 +33,26 @@ const useConfig = (id: string, payload: LLMNodeType) => { const hasSetBlockStatus = (() => { const promptTemplate = inputs.prompt_template + const hasSetContext = isChatModel ? (promptTemplate as PromptItem[]).some(item => checkHasContextBlock(item.text)) : checkHasContextBlock((promptTemplate as PromptItem).text) if (!isChatMode) { return { history: false, query: false, + context: hasSetContext, } } if (isChatModel) { return { history: false, query: (promptTemplate as PromptItem[]).some(item => checkHasQueryBlock(item.text)), + context: hasSetContext, } } else { return { history: checkHasHistoryBlock((promptTemplate as PromptItem).text), query: checkHasQueryBlock((promptTemplate as PromptItem).text), + context: hasSetContext, } } })()