test: coze workflow test

This commit is contained in:
LuanY77
2025-09-08 14:15:19 +08:00
parent 29c2141990
commit 85f8401c1e
14 changed files with 128 additions and 6 deletions

View File

@@ -23,6 +23,7 @@ import java.util.Optional;
* @since TODO
*/
@Deprecated
public abstract class AbstractProtocolTransformer implements ProtocolTransformer {
private static final String FINISHED_DATA = "finished";

View File

@@ -4,6 +4,7 @@ import com.yomahub.liteflow.ai.annotation.AIComponent;
import com.yomahub.liteflow.ai.proxy.handler.WorkflowComponentHandler;
import com.yomahub.liteflow.ai.proxy.wrap.AIProxyWrapBean;
import com.yomahub.liteflow.ai.workflow.coze.annotation.CozeWorkflowRun;
import com.yomahub.liteflow.ai.workflow.coze.invocation.CozeWorkflowRunInvocationHandler;
import com.yomahub.liteflow.ai.workflow.coze.wrap.CozeWorkflowRunProxyWrapBean;
import java.lang.reflect.InvocationHandler;
@@ -29,6 +30,6 @@ public class CozeWorkflowRunComponentHandler extends WorkflowComponentHandler<Co
@Override
protected InvocationHandler getInvocationHandler(AIProxyWrapBean<CozeWorkflowRun> wrapBean) {
return null;
return new CozeWorkflowRunInvocationHandler((CozeWorkflowRunProxyWrapBean) wrapBean);
}
}

View File

@@ -44,7 +44,7 @@ public class CozeWorkflowChatInvocationHandler extends AbstractAIInvocationHandl
.auth(new TokenAuth(property.getApiKey()))
.baseURL(
StrUtil.isBlank(property.getBaseUrl()) ?
Consts.COZE_COM_BASE_URL :
Consts.COZE_CN_BASE_URL :
property.getBaseUrl()
)
.build();

View File

@@ -45,7 +45,7 @@ public class CozeWorkflowRunInvocationHandler extends AbstractAIInvocationHandle
.auth(new TokenAuth(property.getApiKey()))
.baseURL(
StrUtil.isBlank(property.getBaseUrl()) ?
Consts.COZE_COM_BASE_URL :
Consts.COZE_CN_BASE_URL :
property.getBaseUrl()
)
.build();
@@ -94,4 +94,9 @@ public class CozeWorkflowRunInvocationHandler extends AbstractAIInvocationHandle
return runs.create(builder.build());
}
}
@Override
protected void checkValidation(ProcessorContext<?> processorContext) {
// 空实现
}
}

View File

@@ -11,7 +11,7 @@
"type": "java.lang.String",
"description": "apiUrl for coze service.",
"sourceType": "com.yomahub.liteflow.ai.workflow.coze.config.CozeWorkflowProperty",
"defaultValue": "https://api.coze.com"
"defaultValue": "https://api.coze.cn"
}
]
}

View File

@@ -45,6 +45,11 @@
<artifactId>liteflow-ai-workflow-dashscope</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-ai-workflow-coze</artifactId>
<version>${revision}</version>
</dependency>
<!-- model end -->
</dependencies>

View File

@@ -0,0 +1,31 @@
package com.yomahub.liteflow.test.ai.workflow.coze;
import com.yomahub.liteflow.ai.context.ChatContext;
import com.yomahub.liteflow.ai.util.SpringUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.test.ai.workflow.coze.cmp.WorkFlowContext;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import javax.annotation.Resource;
@TestPropertySource(properties = {"spring.config.location=classpath:workflow/coze/application.yaml"})
@SpringBootTest(classes = {CozeWorkflowTest.class, SpringUtil.class})
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.ai.workflow.coze.cmp"})
public class CozeWorkflowTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testCozeWorkflow() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", null, ChatContext.class, WorkFlowContext.class);
Assertions.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,15 @@
package com.yomahub.liteflow.test.ai.workflow.coze.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() throws Exception {
WorkFlowContext context = this.getContextBean(WorkFlowContext.class);
context.setInput("What is the capital of France?");
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,14 @@
package com.yomahub.liteflow.test.ai.workflow.coze.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("b")
public class BCmp extends NodeComponent {
@Override
public void process() throws Exception {
WorkFlowContext context = this.getContextBean(WorkFlowContext.class);
System.out.println("BCmp executed! The result is: " + context.getResult().getData());
}
}

View File

@@ -0,0 +1,10 @@
package com.yomahub.liteflow.test.ai.workflow.coze.cmp;
import com.coze.openapi.client.workflows.run.RunWorkflowResp;
import lombok.Data;
@Data
public class WorkFlowContext {
private String input;
private RunWorkflowResp result;
}

View File

@@ -0,0 +1,23 @@
package com.yomahub.liteflow.test.ai.workflow.coze.cmp;
import com.yomahub.liteflow.ai.annotation.AIComponent;
import com.yomahub.liteflow.ai.annotation.model.io.AIOutput;
import com.yomahub.liteflow.ai.util.KeyValue;
import com.yomahub.liteflow.ai.workflow.coze.annotation.CozeWorkflowRun;
@AIComponent(
nodeId = "cozeWorkflowNode",
nodeName = "Coze-Workflow"
)
@CozeWorkflowRun(
workflowId = "7547589243724939314",
parameters = {
@KeyValue(key = "input", value = "{{input}}")
},
appId = "7547538064139485230"
)
@AIOutput(
methodExpress = "setResult"
)
public interface WorkflowCmp {
}

View File

@@ -15,10 +15,10 @@ import org.springframework.test.context.TestPropertySource;
import javax.annotation.Resource;
@TestPropertySource(properties = {"spring.config.location=classpath:workflow/dashscope/application.yaml"})
@SpringBootTest(classes = {WorkflowTest.class, SpringUtil.class})
@SpringBootTest(classes = {DashScopeWorkflowTest.class, SpringUtil.class})
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.ai.workflow.dashscope.cmp"})
public class WorkflowTest {
public class DashScopeWorkflowTest {
@Resource
private FlowExecutor flowExecutor;

View File

@@ -0,0 +1,9 @@
liteflow:
rule-source: workflow/coze/flow.el.xml
ai:
base-packages:
- com.yomahub.liteflow.test.ai.workflow.coze.cmp
enable: true
workflow:
coze:
apiKey:

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
<flow>
<chain name="chain1">
THEN(a, cozeWorkflowNode, b);
</chain>
</flow>