Feat: 节点参数校验

This commit is contained in:
LuanY77
2025-07-31 16:33:42 +08:00
parent a23e6042b2
commit c3254275da
4 changed files with 58 additions and 4 deletions

View File

@@ -1,9 +1,12 @@
package com.yomahub.liteflow.ai.proxy.invocation;
import com.yomahub.liteflow.ai.context.ChatContext;
import com.yomahub.liteflow.ai.domain.ModelConfig;
import com.yomahub.liteflow.ai.exception.LiteFlowAIException;
import com.yomahub.liteflow.ai.parse.AnnotationParser;
import com.yomahub.liteflow.ai.parse.ProcessorContext;
import com.yomahub.liteflow.ai.parse.context.ProcessorContext;
import com.yomahub.liteflow.ai.proxy.wrap.AIProxyWrapBean;
import com.yomahub.liteflow.ai.util.SetUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.log.LFLog;
import com.yomahub.liteflow.log.LFLoggerManager;
@@ -52,6 +55,9 @@ public abstract class AbstractAIInvocationHandler<T extends AIProxyWrapBean<?>>
// 注解解析前置处理
AnnotationParser.postProcessBeforeTrigger(wrapBean.getAnnotation(), processorContext);
// 校验参数是否符合节点要求
checkValidation(processorContext);
// 执行实际的AI处理逻辑
Object result = doExecuteAIProcess(processorContext, args);
@@ -65,6 +71,29 @@ public abstract class AbstractAIInvocationHandler<T extends AIProxyWrapBean<?>>
}
}
/**
* 校验参数是否符合节点要求
*
* @param processorContext 处理器上下文
*/
protected void checkValidation(ProcessorContext<T> processorContext) {
// 校验Prompt
if (SetUtil.isNotPresent(wrapBean.getUserPrompt()) && SetUtil.isNotPresent(wrapBean.getSystemPrompt())) {
throw new LiteFlowAIException("User prompt and system prompt cannot both be empty");
}
// 校验必需参数
ModelConfig modelConfig = wrapBean.getConfig();
if (SetUtil.isNotPresent(modelConfig.getProvider())) {
throw new LiteFlowAIException("Provider cannot be empty for AI node: " + wrapBean.getNodeId());
}
if (SetUtil.isNotPresent(modelConfig.getBaseUrl())) {
throw new LiteFlowAIException("Base URL cannot be empty for AI node: " + wrapBean.getNodeId());
}
if (SetUtil.isNotPresent(modelConfig.getModel())) {
throw new LiteFlowAIException("Model cannot be empty for AI node: " + wrapBean.getNodeId());
}
}
/**
* 执行具体的AI处理逻辑
*

View File

@@ -3,7 +3,7 @@ package com.yomahub.liteflow.ai.proxy.invocation;
import com.yomahub.liteflow.ai.context.ChatContext;
import com.yomahub.liteflow.ai.exception.LiteFlowAIException;
import com.yomahub.liteflow.ai.model.ModelFactory;
import com.yomahub.liteflow.ai.parse.ProcessorContext;
import com.yomahub.liteflow.ai.parse.context.ProcessorContext;
import com.yomahub.liteflow.ai.proxy.invocation.service.AiServiceFactory;
import com.yomahub.liteflow.ai.proxy.wrap.ChatProxyWrapBean;
import com.yomahub.liteflow.core.NodeComponent;
@@ -27,6 +27,12 @@ public class ChatAIInvocationHandler extends AbstractAIInvocationHandler<ChatPro
super(wrapBean);
}
@Override
protected void checkValidation(ProcessorContext<ChatProxyWrapBean> processorContext) {
// 调用父类的校验方法
super.checkValidation(processorContext);
}
@Override
protected Object doExecuteAIProcess(ProcessorContext<ChatProxyWrapBean> processorContext, Object[] args) {
NodeComponent nodeComponent = processorContext.getNodeComponent();

View File

@@ -1,8 +1,10 @@
package com.yomahub.liteflow.ai.proxy.invocation;
import com.yomahub.liteflow.ai.exception.LiteFlowAIException;
import com.yomahub.liteflow.ai.model.ModelFactory;
import com.yomahub.liteflow.ai.parse.ProcessorContext;
import com.yomahub.liteflow.ai.parse.context.ProcessorContext;
import com.yomahub.liteflow.ai.proxy.wrap.ClassifyProxyWrapBean;
import com.yomahub.liteflow.ai.util.SetUtil;
import dev.langchain4j.model.chat.ChatModel;
/**
@@ -18,6 +20,23 @@ public class ClassifyAIInvocationHandler extends AbstractAIInvocationHandler<Cla
super(wrapBean);
}
@Override
protected void checkValidation(ProcessorContext<ClassifyProxyWrapBean> processorContext) {
// 调用父类的校验方法
super.checkValidation(processorContext);
// 校验分类类别
if (SetUtil.isNotPresent(wrapBean.getCategories())) {
throw new LiteFlowAIException("Categories cannot be empty for classification");
}
// 校验多标签分类
if (!wrapBean.isMultiLabel() && wrapBean.getCategories().size() > 1) {
throw new LiteFlowAIException("Multi-label classification is not allowed when multiLabel is false");
}
if (wrapBean.isMultiLabel() && wrapBean.getCategories().size() < 2) {
throw new LiteFlowAIException("At least two categories are required for multi-label classification");
}
}
@Override
protected Object doExecuteAIProcess(ProcessorContext<ClassifyProxyWrapBean> processorContext, Object[] args) {

View File

@@ -1,6 +1,6 @@
package com.yomahub.liteflow.ai.proxy.invocation;
import com.yomahub.liteflow.ai.parse.ProcessorContext;
import com.yomahub.liteflow.ai.parse.context.ProcessorContext;
import com.yomahub.liteflow.ai.proxy.wrap.RetrievalProxyWrapBean;
/**