|
@@ -2,6 +2,7 @@ package space.anyi.springAiAlibabaLearn.controller;
|
|
|
|
|
|
|
|
import com.alibaba.cloud.ai.graph.CompiledGraph;
|
|
import com.alibaba.cloud.ai.graph.CompiledGraph;
|
|
|
import com.alibaba.cloud.ai.graph.NodeOutput;
|
|
import com.alibaba.cloud.ai.graph.NodeOutput;
|
|
|
|
|
+import com.alibaba.cloud.ai.graph.RunnableConfig;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -23,15 +24,18 @@ public class GraphController {
|
|
|
private final CompiledGraph createStanceGraph;
|
|
private final CompiledGraph createStanceGraph;
|
|
|
private final CompiledGraph conditionGraph;
|
|
private final CompiledGraph conditionGraph;
|
|
|
private final CompiledGraph loopGraph;
|
|
private final CompiledGraph loopGraph;
|
|
|
|
|
+ private final CompiledGraph saveGraph;
|
|
|
|
|
|
|
|
public GraphController(@Autowired @Qualifier("compiledGraph")CompiledGraph compiledGraph,
|
|
public GraphController(@Autowired @Qualifier("compiledGraph")CompiledGraph compiledGraph,
|
|
|
@Autowired @Qualifier("createStanceGraph")CompiledGraph createStanceGraph,
|
|
@Autowired @Qualifier("createStanceGraph")CompiledGraph createStanceGraph,
|
|
|
- @Autowired@Qualifier("conditionGraph")CompiledGraph conditionGraph,
|
|
|
|
|
- @Autowired@Qualifier("loopGraph")CompiledGraph loopGraph) {
|
|
|
|
|
|
|
+ @Autowired @Qualifier("conditionGraph")CompiledGraph conditionGraph,
|
|
|
|
|
+ @Autowired @Qualifier("loopGraph")CompiledGraph loopGraph,
|
|
|
|
|
+ @Autowired @Qualifier("saveGraph")CompiledGraph saveGraph) {
|
|
|
this.compiledGraph = compiledGraph;
|
|
this.compiledGraph = compiledGraph;
|
|
|
this.createStanceGraph = createStanceGraph;
|
|
this.createStanceGraph = createStanceGraph;
|
|
|
this.conditionGraph = conditionGraph;
|
|
this.conditionGraph = conditionGraph;
|
|
|
this.loopGraph = loopGraph;
|
|
this.loopGraph = loopGraph;
|
|
|
|
|
+ this.saveGraph = saveGraph;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/quickStart")
|
|
@GetMapping("/quickStart")
|
|
@@ -58,4 +62,17 @@ public class GraphController {
|
|
|
public Map<String, Object> loop(@RequestParam("topic")String topic){
|
|
public Map<String, Object> loop(@RequestParam("topic")String topic){
|
|
|
return loopGraph.stream(Map.of("topic", topic)).log().last().block().state().data();
|
|
return loopGraph.stream(Map.of("topic", topic)).log().last().block().state().data();
|
|
|
}
|
|
}
|
|
|
|
|
+ @GetMapping("/saveTest")
|
|
|
|
|
+ public Map<String, Object> saveTest(@RequestParam("msg")String msg,@RequestParam("id") String id){
|
|
|
|
|
+ //graph工作流的运行配置
|
|
|
|
|
+ RunnableConfig runnableConfig = RunnableConfig.builder()
|
|
|
|
|
+ .threadId(id)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ return saveGraph.stream(Map.of("msg", msg),runnableConfig)
|
|
|
|
|
+ .log()
|
|
|
|
|
+ .last()
|
|
|
|
|
+ .block()
|
|
|
|
|
+ .state()
|
|
|
|
|
+ .data();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|