feat: get input vars

This commit is contained in:
Joel 2024-04-01 10:38:12 +08:00
parent c20685e669
commit e03367a188
2 changed files with 26 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import type { ValueSelector } from '../../workflow/types'
export const CONTEXT_PLACEHOLDER_TEXT = '{{#context#}}'
export const HISTORY_PLACEHOLDER_TEXT = '{{#histories#}}'
export const QUERY_PLACEHOLDER_TEXT = '{{#query#}}'
@ -22,3 +24,25 @@ export const checkHasQueryBlock = (text: string) => {
return false
return text.includes(QUERY_PLACEHOLDER_TEXT)
}
/*
* {{#1711617514996.name#}} => [1711617514996, name]
* {{#1711617514996.sys.query#}} => [sys, query]
*/
export const getInputVars = (text: string): ValueSelector[] => {
const allVars = text.match(/{{#([^#]*)#}}/g)
if (allVars && allVars?.length > 0) {
// {{#context#}}, {{#query#}} is not input vars
const inputVars = allVars
.filter(item => item.includes('.'))
.map((item) => {
const valueSelector = item.replace('{{#', '').replace('#}}', '').split('.')
if (valueSelector[1] === 'sys' && /^\d+$/.test(valueSelector[0]))
return valueSelector.slice(1)
return valueSelector
})
return inputVars
}
return []
}

View File

@ -11,7 +11,6 @@ import AddButton from '@/app/components/workflow/nodes/_base/components/add-butt
import TypeSelector from '@/app/components/workflow/nodes/_base/components/selector'
import TooltipPlus from '@/app/components/base/tooltip-plus'
import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
const i18nPrefix = 'workflow.nodes.llm'
type Props = {
@ -105,6 +104,8 @@ const ConfigPrompt: FC<Props> = ({
onChange(newPrompt)
}, [onChange, payload])
// console.log(getInputVars((payload as PromptItem).text))
return (
<div>
{(isChatModel && Array.isArray(payload))