feat(ai-web): 尝试解析流程图
This commit is contained in:
@@ -155,6 +155,11 @@
|
||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||
<version>2.13.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-el-builder</artifactId>
|
||||
<version>2.13.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.noear</groupId>
|
||||
<artifactId>solon-ai</artifactId>
|
||||
|
||||
@@ -62,6 +62,10 @@
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-el-builder</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-tika-document-reader</artifactId>
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user