mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-11 03:46:52 +08:00
feat: llm support jinja fe (#4260)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { BlockEnum } from '../../types'
|
||||
import { type NodeDefault, PromptRole } from '../../types'
|
||||
import { BlockEnum, EditionType } from '../../types'
|
||||
import { type NodeDefault, type PromptItem, PromptRole } from '../../types'
|
||||
import type { LLMNodeType } from './types'
|
||||
import type { PromptItem } from '@/models/debug'
|
||||
import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/constants'
|
||||
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
@@ -16,7 +15,6 @@ const nodeDefault: NodeDefault<LLMNodeType> = {
|
||||
temperature: 0.7,
|
||||
},
|
||||
},
|
||||
variables: [],
|
||||
prompt_template: [{
|
||||
role: PromptRole.system,
|
||||
text: '',
|
||||
@@ -57,6 +55,23 @@ const nodeDefault: NodeDefault<LLMNodeType> = {
|
||||
if (isChatModel && !!payload.memory.query_prompt_template && !payload.memory.query_prompt_template.includes('{{#sys.query#}}'))
|
||||
errorMessages = t('workflow.nodes.llm.sysQueryInUser')
|
||||
}
|
||||
|
||||
if (!errorMessages) {
|
||||
const isChatModel = payload.model.mode === 'chat'
|
||||
const isShowVars = (() => {
|
||||
if (isChatModel)
|
||||
return (payload.prompt_template as PromptItem[]).some(item => item.edition_type === EditionType.jinja2)
|
||||
return (payload.prompt_template as PromptItem).edition_type === EditionType.jinja2
|
||||
})()
|
||||
if (isShowVars && payload.prompt_config?.jinja2_variables) {
|
||||
payload.prompt_config?.jinja2_variables.forEach((i) => {
|
||||
if (!errorMessages && !i.variable)
|
||||
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.variable`) })
|
||||
if (!errorMessages && !i.value_selector.length)
|
||||
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.variableValue`) })
|
||||
})
|
||||
}
|
||||
}
|
||||
return {
|
||||
isValid: !errorMessages,
|
||||
errorMessage: errorMessages,
|
||||
|
||||
Reference in New Issue
Block a user