feat(ai-web): 尝试解析流程图

This commit is contained in:
v-zhangjc9
2025-06-25 17:55:05 +08:00
parent 6f7f7cea67
commit f6bd7e52e1
7 changed files with 212 additions and 0 deletions

View File

@@ -155,6 +155,11 @@
<artifactId>liteflow-spring-boot-starter</artifactId> <artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.13.2</version> <version>2.13.2</version>
</dependency> </dependency>
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-el-builder</artifactId>
<version>2.13.2</version>
</dependency>
<dependency> <dependency>
<groupId>org.noear</groupId> <groupId>org.noear</groupId>
<artifactId>solon-ai</artifactId> <artifactId>solon-ai</artifactId>

View File

@@ -62,6 +62,10 @@
<groupId>com.yomahub</groupId> <groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId> <artifactId>liteflow-spring-boot-starter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-el-builder</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.ai</groupId> <groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-tika-document-reader</artifactId> <artifactId>spring-ai-tika-document-reader</artifactId>

View File

@@ -0,0 +1,10 @@
package com.lanyuanxiaoyao.service.ai.web.flow;
import com.yomahub.liteflow.core.NodeComponent;
/**
* @author lanyuanxiaoyao
* @version 20250625
*/
public abstract class BaseNode extends NodeComponent {
}

View File

@@ -0,0 +1,12 @@
package com.lanyuanxiaoyao.service.ai.web.flow;
/**
* @author lanyuanxiaoyao
* @version 20250625
*/
public class EndNode extends BaseNode {
@Override
public void process() throws Exception {
}
}

View File

@@ -0,0 +1,157 @@
package com.lanyuanxiaoyao.service.ai.web.flow;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
import com.yomahub.liteflow.builder.el.ELBus;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.NodeTypeEnum;
import java.util.List;
import java.util.Map;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
/**
* @author lanyuanxiaoyao
* @version 20250625
*/
@Slf4j
public class LiteFlowService {
public LiteFlowService() {
createNode("start-amis-node", NodeTypeEnum.COMMON, StartNode.class);
createNode("end-amis-node", NodeTypeEnum.COMMON, EndNode.class);
createNode("llm-amis-node", NodeTypeEnum.COMMON, LlmNode.class);
}
private static void createNode(String name, NodeTypeEnum type, Class<? extends NodeComponent> clazz) {
LiteFlowNodeBuilder.createNode()
.setId(name)
.setName(name)
.setType(type)
.setClazz(clazz)
.build();
}
@Data
public static class FlowData {
private List<Node> nodes;
private List<Edge> edges;
private Map<String, Object> data;
@Data
public static class Node {
private String id;
private String type;
}
@Data
public static class Edge {
private String id;
private String source;
private String target;
}
}
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// language=JSON
String source = """
{
"nodes": [
{
"id": "BMFP3Eov94",
"type": "start-amis-node",
"position": {
"x": 10,
"y": 100
},
"data": {},
"measured": {
"width": 256,
"height": 83
},
"selected": false
},
{
"id": "PYK8LjduQ1",
"type": "end-amis-node",
"position": {
"x": 654,
"y": 332
},
"data": {},
"measured": {
"width": 256,
"height": 83
},
"selected": false,
"dragging": false
},
{
"id": "nCm-ij5I6o",
"type": "llm-amis-node",
"position": {
"x": 318,
"y": 208
},
"data": {},
"measured": {
"width": 256,
"height": 83
},
"selected": true,
"dragging": false
}
],
"edges": [
{
"source": "BMFP3Eov94",
"target": "nCm-ij5I6o",
"id": "xy-edge__BMFP3Eov94-nCm-ij5I6o"
},
{
"source": "nCm-ij5I6o",
"target": "PYK8LjduQ1",
"id": "xy-edge__nCm-ij5I6o-PYK8LjduQ1"
}
],
"data": {
"BMFP3Eov94": {
"inputs": {
"name": {
"type": "text"
},
"description": {
"type": "text",
"description": "文件描述"
}
}
},
"nCm-ij5I6o": {
"model": "qwen3",
"outputs": {
"text": {
"type": "string"
}
},
"systemPrompt": "你是个沙雕"
}
}
}
""";
FlowData root = mapper.readValue(StrUtil.trim(source), FlowData.class);
log.info("{}", root);
log.info(
"\n{}",
ELBus.ser(
"start-amis-node",
ELBus.ser("start-amis-node", "end-amis-node"),
"end-amis-node"
).toEL(true)
);
}
}

View File

@@ -0,0 +1,12 @@
package com.lanyuanxiaoyao.service.ai.web.flow;
/**
* @author lanyuanxiaoyao
* @version 20250625
*/
public class LlmNode extends BaseNode {
@Override
public void process() throws Exception {
}
}

View File

@@ -0,0 +1,12 @@
package com.lanyuanxiaoyao.service.ai.web.flow;
/**
* @author lanyuanxiaoyao
* @version 20250625
*/
public class StartNode extends BaseNode {
@Override
public void process() throws Exception {
}
}