mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 20:17:29 +08:00
feat: get input vars
This commit is contained in:
parent
c20685e669
commit
e03367a188
@ -1,3 +1,5 @@
|
|||||||
|
import type { ValueSelector } from '../../workflow/types'
|
||||||
|
|
||||||
export const CONTEXT_PLACEHOLDER_TEXT = '{{#context#}}'
|
export const CONTEXT_PLACEHOLDER_TEXT = '{{#context#}}'
|
||||||
export const HISTORY_PLACEHOLDER_TEXT = '{{#histories#}}'
|
export const HISTORY_PLACEHOLDER_TEXT = '{{#histories#}}'
|
||||||
export const QUERY_PLACEHOLDER_TEXT = '{{#query#}}'
|
export const QUERY_PLACEHOLDER_TEXT = '{{#query#}}'
|
||||||
@ -22,3 +24,25 @@ export const checkHasQueryBlock = (text: string) => {
|
|||||||
return false
|
return false
|
||||||
return text.includes(QUERY_PLACEHOLDER_TEXT)
|
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 []
|
||||||
|
}
|
||||||
|
|||||||
@ -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 TypeSelector from '@/app/components/workflow/nodes/_base/components/selector'
|
||||||
import TooltipPlus from '@/app/components/base/tooltip-plus'
|
import TooltipPlus from '@/app/components/base/tooltip-plus'
|
||||||
import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
|
import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
|
||||||
|
|
||||||
const i18nPrefix = 'workflow.nodes.llm'
|
const i18nPrefix = 'workflow.nodes.llm'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -105,6 +104,8 @@ const ConfigPrompt: FC<Props> = ({
|
|||||||
onChange(newPrompt)
|
onChange(newPrompt)
|
||||||
}, [onChange, payload])
|
}, [onChange, payload])
|
||||||
|
|
||||||
|
// console.log(getInputVars((payload as PromptItem).text))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{(isChatModel && Array.isArray(payload))
|
{(isChatModel && Array.isArray(payload))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user