mirror of https://github.com/langgenius/dify.git
feat: prompt editor set context status setter
This commit is contained in:
parent
672b8f14f2
commit
3e9c7dccc0
|
|
@ -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<Props> = ({
|
|||
readOnly,
|
||||
showRemove,
|
||||
onRemove,
|
||||
justVar,
|
||||
isChatModel,
|
||||
isChatApp,
|
||||
isShowContext,
|
||||
hasSetBlockStatus,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
|
@ -112,8 +117,8 @@ const Editor: FC<Props> = ({
|
|||
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<Props> = ({
|
|||
onAddExternalTool: () => { },
|
||||
}}
|
||||
historyBlock={{
|
||||
show: isShowHistory,
|
||||
show: justVar ? false : isShowHistory,
|
||||
selectable: !hasSetBlockStatus?.history,
|
||||
history: {
|
||||
user: 'Human',
|
||||
|
|
@ -135,7 +140,7 @@ const Editor: FC<Props> = ({
|
|||
onEditRole: () => { },
|
||||
}}
|
||||
queryBlock={{
|
||||
show: isShowQuery,
|
||||
show: justVar ? false : isShowQuery,
|
||||
selectable: !hasSetBlockStatus?.query,
|
||||
}}
|
||||
onChange={onChange}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ const Panel: FC<NodePanelProps<AnswerNodeType>> = ({
|
|||
</Field>
|
||||
<Split />
|
||||
<Editor
|
||||
justVar
|
||||
title={t(`${i18nPrefix}.answer`)!}
|
||||
value={inputs.answer}
|
||||
onChange={handleAnswerChange}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ type Props = {
|
|||
payload: PromptItem | PromptItem[]
|
||||
variables: string[]
|
||||
onChange: (payload: PromptItem | PromptItem[]) => void
|
||||
isShowContext: boolean
|
||||
hasSetBlockStatus: {
|
||||
context: boolean
|
||||
history: boolean
|
||||
query: boolean
|
||||
}
|
||||
|
|
@ -33,6 +35,7 @@ const ConfigPrompt: FC<Props> = ({
|
|||
payload,
|
||||
variables,
|
||||
onChange,
|
||||
isShowContext,
|
||||
hasSetBlockStatus,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
|
@ -131,6 +134,7 @@ const ConfigPrompt: FC<Props> = ({
|
|||
onRemove={handleRemove(index)}
|
||||
isChatModel={isChatModel}
|
||||
isChatApp={isChatApp}
|
||||
isShowContext={isShowContext}
|
||||
hasSetBlockStatus={hasSetBlockStatus}
|
||||
/>
|
||||
)
|
||||
|
|
@ -155,6 +159,7 @@ const ConfigPrompt: FC<Props> = ({
|
|||
readOnly={readOnly}
|
||||
isChatModel={isChatModel}
|
||||
isChatApp={isChatApp}
|
||||
isShowContext={isShowContext}
|
||||
hasSetBlockStatus={hasSetBlockStatus}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
|||
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}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
|
|
|||
Loading…
Reference in New Issue