feat: query prompt template support in chatflow (#3791)

Co-authored-by: Joel <iamjoel007@gmail.com>
This commit is contained in:
takatost
2024-04-25 18:01:53 +08:00
committed by GitHub
parent 80b9507e7a
commit 12435774ca
12 changed files with 113 additions and 18 deletions

View File

@@ -146,6 +146,7 @@ const Editor: FC<Props> = ({
<PromptEditor
instanceId={instanceId}
compact
className='min-h-[56px]'
style={isExpand ? { height: editorExpandHeight - 5 } : {}}
value={value}
contextBlock={{

View File

@@ -272,10 +272,12 @@ export const getNodeUsedVars = (node: Node): ValueSelector[] => {
const payload = (data as LLMNodeType)
const isChatModel = payload.model?.mode === 'chat'
let prompts: string[] = []
if (isChatModel)
if (isChatModel) {
prompts = (payload.prompt_template as PromptItem[])?.map(p => p.text) || []
else
prompts = [(payload.prompt_template as PromptItem).text]
if (payload.memory?.query_prompt_template)
prompts.push(payload.memory.query_prompt_template)
}
else { prompts = [(payload.prompt_template as PromptItem).text] }
const inputVars: ValueSelector[] = matchNotSystemVars(prompts)
const contextVar = (data as LLMNodeType).context?.variable_selector ? [(data as LLMNodeType).context?.variable_selector] : []
@@ -375,6 +377,8 @@ export const updateNodeVars = (oldNode: Node, oldVarSelector: ValueSelector, new
text: replaceOldVarInText(prompt.text, oldVarSelector, newVarSelector),
}
})
if (payload.memory?.query_prompt_template)
payload.memory.query_prompt_template = replaceOldVarInText(payload.memory.query_prompt_template, oldVarSelector, newVarSelector)
}
else {
payload.prompt_template = {