diff --git a/web/app/components/base/prompt-editor/constants.tsx b/web/app/components/base/prompt-editor/constants.tsx index 64144b17a9..c24a265684 100644 --- a/web/app/components/base/prompt-editor/constants.tsx +++ b/web/app/components/base/prompt-editor/constants.tsx @@ -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 [] +} diff --git a/web/app/components/workflow/nodes/llm/components/config-prompt.tsx b/web/app/components/workflow/nodes/llm/components/config-prompt.tsx index 5b49e9b778..06f87f75e7 100644 --- a/web/app/components/workflow/nodes/llm/components/config-prompt.tsx +++ b/web/app/components/workflow/nodes/llm/components/config-prompt.tsx @@ -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 = ({ onChange(newPrompt) }, [onChange, payload]) + // console.log(getInputVars((payload as PromptItem).text)) + return (
{(isChatModel && Array.isArray(payload))