TinyflowTest.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. package com.ruoyi;
  3. import com.agentsflex.core.chain.Chain;
  4. import com.agentsflex.core.chain.ChainEvent;
  5. import com.agentsflex.core.chain.ChainNode;
  6. import com.agentsflex.core.chain.event.ChainStartEvent;
  7. import com.agentsflex.core.chain.event.ChainStatusChangeEvent;
  8. import com.agentsflex.core.chain.event.NodeEndEvent;
  9. import com.agentsflex.core.chain.event.NodeStartEvent;
  10. import com.agentsflex.core.chain.listener.ChainEventListener;
  11. import com.agentsflex.core.chain.listener.ChainOutputListener;
  12. import com.agentsflex.llm.openai.OpenAILlm;
  13. import com.baomidou.mybatisplus.core.metadata.IPage;
  14. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  15. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  16. import com.ruoyi.interfaces.tinyflow.parser.PrintNodeParser;
  17. import com.ruoyi.interfaces.tinyflow.parser.ServiceNodeParser;
  18. import com.ruoyi.model.dpp.dal.dataobject.etl.DppEtlTaskDO;
  19. import com.ruoyi.model.etl.mapper.DppEtlTaskMapper;
  20. import dev.tinyflow.core.Tinyflow;
  21. import org.junit.jupiter.api.Test;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import javax.annotation.Resource;
  24. import java.util.HashMap;
  25. import java.util.Map;
  26. public class TinyflowTest {
  27. // static String data1 = "";
  28. //static String data1 = "{\"nodes\":[{\"id\":\"2\",\"type\":\"llmNode\",\"data\":{\"title\":\"大模型\",\"description\":\"处理大模型相关问题\",\"expand\":true,\"outputDefs\":[{\"id\":\"pyiig8ntGWZhVdVz\",\"dataType\":\"Object\",\"name\":\"param\",\"children\":[{\"id\":\"1\",\"name\":\"newParam1\",\"dataType\":\"String\"},{\"id\":\"2\",\"name\":\"newParam2\",\"dataType\":\"String\"}]}]},\"position\":{\"x\":600,\"y\":50},\"measured\":{\"width\":334,\"height\":687},\"selected\":false},{\"id\":\"3\",\"type\":\"startNode\",\"data\":{\"title\":\"开始节点\",\"description\":\"开始定义输入参数\",\"expand\":true,\"parameters\":[{\"id\":\"Q37GZ5KKvPpCD7Cs\",\"name\":\"name\"}]},\"position\":{\"x\":150,\"y\":25},\"measured\":{\"width\":306,\"height\":209},\"selected\":false},{\"id\":\"4\",\"type\":\"endNode\",\"data\":{\"title\":\"结束节点\",\"description\":\"结束定义输出参数\",\"expand\":true,\"outputDefs\":[{\"id\":\"z7fOwoTjQ7AbUJdm\",\"ref\":\"3.name\",\"name\":\"test\"}]},\"position\":{\"x\":994,\"y\":218},\"measured\":{\"width\":334,\"height\":209},\"selected\":false,\"dragging\":false}],\"edges\":[{\"markerEnd\":{\"type\":\"arrowclosed\",\"width\":20,\"height\":20},\"source\":\"3\",\"target\":\"2\",\"id\":\"xy-edge__3-2\"},{\"markerEnd\":{\"type\":\"arrowclosed\",\"width\":20,\"height\":20},\"source\":\"2\",\"target\":\"4\",\"id\":\"xy-edge__2-4\"}],\"viewport\":{\"x\":250,\"y\":100,\"zoom\":1}}";
  29. static String data1 = "{\n" +
  30. " \"nodes\": [\n" +
  31. " {\n" +
  32. " \"id\": \"1\",\n" +
  33. " \"type\": \"startNode\",\n" +
  34. " \"data\": {\n" +
  35. " \"title\": \"开始节点\",\n" +
  36. " \"description\": \"开始定义输入参数\",\n" +
  37. " \"expand\": true,\n" +
  38. " \"parameters\": [\n" +
  39. " {\n" +
  40. " \"name\": \"year\",\n" +
  41. " \"dataType\": \"String\",\n" +
  42. " \"refType\": \"input\",\n" +
  43. " \"required\": true,\n" +
  44. " \"description\": \"第一个输入参数\"\n" +
  45. " },\n" +
  46. " {\n" +
  47. " \"name\": \"inputParam2\",\n" +
  48. " \"dataType\": \"Number\",\n" +
  49. " \"refType\": \"input\",\n" +
  50. " \"required\": false,\n" +
  51. " \"description\": \"第二个输入参数\",\n" +
  52. " \"defaultValue\": 100\n" +
  53. " }\n" +
  54. " ]\n" +
  55. " },\n" +
  56. " \"position\": {\n" +
  57. " \"x\": 150,\n" +
  58. " \"y\": 25\n" +
  59. " },\n" +
  60. " \"measured\": {\n" +
  61. " \"width\": 306,\n" +
  62. " \"height\": 209\n" +
  63. " },\n" +
  64. " \"selected\": false\n" +
  65. " },\n" +
  66. " {\n" +
  67. " \"id\": \"2\",\n" +
  68. " \"data\": {\n" +
  69. " \"title\": \"服务节点\",\n" +
  70. " \"parameters\": [\n" +
  71. " {\n" +
  72. " \"name\": \"year\",\n" +
  73. " \"dataType\": \"String\",\n" +
  74. " \"ref\": \"1.year\",\n" +
  75. " \"refType\": \"ref\"\n" +
  76. " }\n" +
  77. " ],\n" +
  78. " \"service\": {\n" +
  79. " \"srvId\": \"634ae1e0ee78e00bd609b85514961373\",\n" +
  80. " \"mdid\": \"e4dc50dd-c4a9-4639-b43e-62e48314a7e0\",\n" +
  81. " \"cateCode\": \"S\",\n" +
  82. " \"name\": \"获取台风信息列表\",\n" +
  83. " \"intro\": \"获取有台风的编号及名称\",\n" +
  84. " \"serviceSource\": null,\n" +
  85. " \"serviceDept\": null,\n" +
  86. " \"manageName\": null,\n" +
  87. " \"developUnit\": null,\n" +
  88. " \"developContacter\": null,\n" +
  89. " \"maintainUnit\": null,\n" +
  90. " \"maintainContacer\": null,\n" +
  91. " \"upCycl\": null,\n" +
  92. " \"openCndtn\": null,\n" +
  93. " \"adName\": null,\n" +
  94. " \"dataField\": null,\n" +
  95. " \"dataRange\": null,\n" +
  96. " \"userId\": null,\n" +
  97. " \"status\": null,\n" +
  98. " \"note\": null,\n" +
  99. " \"type\": \"HTTP\",\n" +
  100. " \"url\": \"http://49.4.2.185:2111/RiverStrongAPI2.0/StormSurgeForecast/Typhoon/GetInfos\",\n" +
  101. " \"rqtype\": \"POST\",\n" +
  102. " \"rptype\": \"1\",\n" +
  103. " \"rpcontent\": \"{\\n \\\"data\\\": [\\n {\\n \\\"typhoonId\\\": \\\"202317\\\",\\n \\\"typhoonName\\\": \\\"杰拉华\\\",\\n \\\"test\\\": \\\"1123\\\"\\n },\\n {\\n \\\"typhoonId\\\": \\\"202316\\\",\\n \\\"typhoonName\\\": \\\"三巴\\\",\\n \\\"test\\\": \\\"1123\\\"\\n \\n }\\n ],\\n \\\"succeeded\\\": true,\\n \\\"statusCode\\\": 200,\\n \\\"remark\\\": \\\"获取该年台风信息成功\\\"\\n}\",\n" +
  104. " \"proxyAddress\": null,\n" +
  105. " \"proxyPath\": null,\n" +
  106. " \"example\": \"\",\n" +
  107. " \"cnt\": null,\n" +
  108. " \"viewNum\": 0,\n" +
  109. " \"applyNum\": null,\n" +
  110. " \"dataNum\": null,\n" +
  111. " \"tm\": null,\n" +
  112. " \"uptm\": null,\n" +
  113. " \"rlstm\": null,\n" +
  114. " \"releaseTime\": null,\n" +
  115. " \"attentionId\": null,\n" +
  116. " \"params\": [\n" +
  117. " {\n" +
  118. " \"srvId\": \"634ae1e0ee78e00bd609b85514961373\",\n" +
  119. " \"paramCode\": \"year\",\n" +
  120. " \"paramName\": \"年份\",\n" +
  121. " \"paramType\": \"int\",\n" +
  122. " \"paramValue\": \"2023\",\n" +
  123. " \"paramFormat\": null,\n" +
  124. " \"paramNote\": \"\",\n" +
  125. " \"sort\": 0,\n" +
  126. " \"paramObject\": 2023\n" +
  127. " }\n" +
  128. " ],\n" +
  129. " \"sort\": null,\n" +
  130. " \"audit\": null\n" +
  131. " }\n" +
  132. " },\n" +
  133. " \"type\": \"serviceNode\",\n" +
  134. " \"position\": {\n" +
  135. " \"x\": 600,\n" +
  136. " \"y\": 50\n" +
  137. " },\n" +
  138. " \"measured\": {\n" +
  139. " \"width\": 334,\n" +
  140. " \"height\": 687\n" +
  141. " },\n" +
  142. " \"selected\": false\n" +
  143. " },\n" +
  144. " {\n" +
  145. " \"id\": \"3\",\n" +
  146. " \"type\": \"endNode\",\n" +
  147. " \"data\": {\n" +
  148. " \"title\": \"结束节点\",\n" +
  149. " \"description\": \"结束定义输出参数\",\n" +
  150. " \"expand\": true,\n" +
  151. " \"outputDefs\": [\n" +
  152. " {\n" +
  153. " \"name\": \"data\",\n" +
  154. " \"dataType\": \"Object\",\n" +
  155. " \"ref\": \"2.result\",\n" +
  156. " \"refType\": \"ref\"\n" +
  157. " }\n" +
  158. " ]\n" +
  159. " },\n" +
  160. " \"position\": {\n" +
  161. " \"x\": 994,\n" +
  162. " \"y\": 218\n" +
  163. " },\n" +
  164. " \"measured\": {\n" +
  165. " \"width\": 334,\n" +
  166. " \"height\": 209\n" +
  167. " },\n" +
  168. " \"selected\": false,\n" +
  169. " \"dragging\": false\n" +
  170. " }\n" +
  171. " ],\n" +
  172. " \"edges\": [\n" +
  173. " {\n" +
  174. " \"markerEnd\": {\n" +
  175. " \"type\": \"arrowclosed\",\n" +
  176. " \"width\": 20,\n" +
  177. " \"height\": 20\n" +
  178. " },\n" +
  179. " \"source\": \"1\",\n" +
  180. " \"target\": \"2\",\n" +
  181. " \"id\": \"xy-edge__1-2\"\n" +
  182. " },\n" +
  183. " {\n" +
  184. " \"markerEnd\": {\n" +
  185. " \"type\": \"arrowclosed\",\n" +
  186. " \"width\": 20,\n" +
  187. " \"height\": 20\n" +
  188. " },\n" +
  189. " \"source\": \"2\",\n" +
  190. " \"target\": \"3\",\n" +
  191. " \"id\": \"xy-edge__2-3\"\n" +
  192. " }\n" +
  193. " ],\n" +
  194. " \"viewport\": {\n" +
  195. " \"x\": 250,\n" +
  196. " \"y\": 100,\n" +
  197. " \"zoom\": 1\n" +
  198. " }\n" +
  199. "}";
  200. public static void main(String[] args) {
  201. */
  202. /*System.out.println(data1);
  203. Tinyflow tinyflow = new Tinyflow(data1);
  204. tinyflow.getChainParser().addNodeParser("printNode",new PrintNodeParser());
  205. tinyflow.getChainParser().addNodeParser("serviceNode",new ServiceNodeParser());
  206. // tinyflow.setLlmProvider(id -> OpenAILlm.of(""));
  207. Map<String, Object> variables = new HashMap<>();
  208. variables.put("year", "2024");
  209. variables.put("inputParam2", 2);
  210. Chain chain = tinyflow.toChain();
  211. chain.addEventListener(new ChainEventListener() {
  212. @Override
  213. public void onEvent(ChainEvent event, Chain chain) {
  214. if (event instanceof ChainStartEvent) {
  215. }
  216. if (event instanceof ChainStatusChangeEvent) {
  217. }
  218. if (event instanceof NodeStartEvent) {
  219. }
  220. if (event instanceof NodeEndEvent) {
  221. }
  222. }
  223. });
  224. chain.addOutputListener(new ChainOutputListener() {
  225. @Override
  226. public void onOutput(Chain chain, ChainNode node, Object outputMessage) {
  227. System.out.println("outputMessage: " + outputMessage);
  228. }
  229. });
  230. Map<String, Object> result = chain.executeForResult(variables);
  231. System.out.println("result:" + result);*//*
  232. // TestService testService = new TestService();
  233. // System.out.println(testService.helloTest());
  234. }
  235. @Resource
  236. private DppEtlTaskMapper dppEtlTaskMapper ;
  237. @Test
  238. public void testSelectJoinPage() {
  239. MPJLambdaWrapper<DppEtlTaskDO> wrapper = new MPJLambdaWrapper<>();
  240. // 添加简单的查询条件
  241. wrapper.eq(DppEtlTaskDO::getDelFlag, "0");
  242. try {
  243. IPage<DppEtlTaskDO> result = dppEtlTaskMapper.selectJoinPage(
  244. new Page<>(1, 10),
  245. DppEtlTaskDO.class,
  246. wrapper
  247. );
  248. System.out.println("查询成功,结果数量:" + result.getRecords().size());
  249. } catch (Exception e) {
  250. System.out.println("查询失败:" + e.getMessage());
  251. e.printStackTrace();
  252. }
  253. }
  254. }
  255. */