feat: prompt editor set context status setter

This commit is contained in:
Joel 2024-03-18 16:25:09 +08:00
parent 672b8f14f2
commit 3e9c7dccc0
5 changed files with 24 additions and 8 deletions

View File

@ -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}

View File

@ -45,6 +45,7 @@ const Panel: FC<NodePanelProps<AnswerNodeType>> = ({
</Field>
<Split />
<Editor
justVar
title={t(`${i18nPrefix}.answer`)!}
value={inputs.answer}
onChange={handleAnswerChange}

View File

@ -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>

View File

@ -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}

View File

@ -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,
}
}
})()