feat: valid before run struct

This commit is contained in:
Joel 2024-03-19 10:46:28 +08:00
parent d6e655eaae
commit 90543c458c
4 changed files with 34 additions and 8 deletions

View File

@ -12,13 +12,37 @@ import { BlockEnum, InputVarType, NodeRunningStatus, VarType } from '@/app/compo
import { useStore as useAppStore } from '@/app/components/app/store'
import { singleNodeRun } from '@/service/workflow'
import Toast from '@/app/components/base/toast'
import LLMDefault from '@/app/components/workflow/nodes/llm/default'
import KnowledgeRetrievalDefault from '@/app/components/workflow/nodes/knowledge-retrieval/default'
import IfElseDefault from '@/app/components/workflow/nodes/if-else/default'
import CodeDefault from '@/app/components/workflow/nodes/code/default'
import TemplateTransformDefault from '@/app/components/workflow/nodes/template-transform/default'
import QuestionClassifyDefault from '@/app/components/workflow/nodes/question-classifier/default'
import HTTPDefault from '@/app/components/workflow/nodes/http/default'
import ToolDefault from '@/app/components/workflow/nodes/tool/default'
import VariableAssigner from '@/app/components/workflow/nodes/variable-assigner/default'
const { checkValid: checkLLMValid } = LLMDefault
const { checkValid: checkKnowledgeRetrievalValid } = KnowledgeRetrievalDefault
const { checkValid: checkIfElseValid } = IfElseDefault
const { checkValid: checkCodeValid } = CodeDefault
const { checkValid: checkTemplateTransformValid } = TemplateTransformDefault
const { checkValid: checkQuestionClassifyValid } = QuestionClassifyDefault
const { checkValid: checkHttpValid } = HTTPDefault
const { checkValid: checkToolValid } = ToolDefault
const { checkValid: checkVariableAssignerValid } = VariableAssigner
const checkValidFns: Record<BlockEnum, Function> = {
[BlockEnum.LLM]: checkLLMValid,
[BlockEnum.KnowledgeRetrieval]: checkKnowledgeRetrievalValid,
[BlockEnum.IfElse]: checkIfElseValid,
[BlockEnum.Code]: checkCodeValid,
[BlockEnum.HttpRequest]: HTTPDefault.checkValid,
[BlockEnum.TemplateTransform]: checkTemplateTransformValid,
[BlockEnum.QuestionClassifier]: checkQuestionClassifyValid,
[BlockEnum.HttpRequest]: checkHttpValid,
[BlockEnum.Tool]: checkToolValid,
[BlockEnum.VariableAssigner]: checkVariableAssignerValid,
} as any
type Params<T> = {

View File

@ -3,6 +3,8 @@ import { type NodeDefault, PromptRole } from '../../types'
import type { LLMNodeType } from './types'
import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/constants'
const i18nPrefix = 'workflow.errorMsg'
const nodeDefault: NodeDefault<LLMNodeType> = {
defaultValue: {
model: {
@ -43,15 +45,13 @@ const nodeDefault: NodeDefault<LLMNodeType> = {
const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
return nodes
},
checkValid(payload: LLMNodeType) {
let isValid = true
checkValid(payload: LLMNodeType, t: any) {
let errorMessages = ''
if (payload.type) {
isValid = true
errorMessages = ''
}
if (!errorMessages && !payload.model.provider)
errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.model`) })
return {
isValid,
isValid: !errorMessages,
errorMessage: errorMessages,
}
},

View File

@ -34,6 +34,7 @@ const translation = {
variable: 'Variable Name',
variableValue: 'Variable Value',
code: 'Code',
model: 'Model',
},
},
singleRun: {

View File

@ -34,6 +34,7 @@ const translation = {
variable: '变量名',
variableValue: '变量值',
code: '代码',
model: '模型',
},
},
singleRun: {