feat: 查询flowise执行结果

This commit is contained in:
stream 2025-12-09 17:30:08 +08:00
parent 5cc438f84d
commit 2f852ead1f
4 changed files with 33 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -29,6 +30,12 @@ public class TeFlowiseController extends BaseController {
return AjaxResult.ok(flowiseActionService.start(request));
}
@ApiOperation("根据chatId查询执行结果")
@GetMapping("/{chatId}")
public AjaxResult query(@PathVariable String chatId) {
return AjaxResult.ok(flowiseActionService.query(chatId));
}
@ApiOperation("终止flowise")
@GetMapping("/abort")
public AjaxResult abort() {

View File

@ -125,4 +125,5 @@ flowise:
tts: 192.168.0.222:8080/tts/
start: http://192.168.0.134:3000/api/v1/prediction/f99329e9-b33d-437d-90ed-69eaa8a05418
abort: http://192.168.0.134:3000/api/v1/chatmessage/abort/f99329e9-b33d-437d-90ed-69eaa8a05418/
query: http://192.168.0.134:3000/api/v1/executions/
api-key: pg61JW6W_GXyqmqSoURJ4mlSRrCMRzGLBJli_w3BFkg

View File

@ -125,4 +125,5 @@ flowise:
tts: 192.168.0.222:8080/tts/
start: http://192.168.0.134:3000/api/v1/prediction/f99329e9-b33d-437d-90ed-69eaa8a05418
abort: http://192.168.0.134:3000/api/v1/chatmessage/abort/f99329e9-b33d-437d-90ed-69eaa8a05418/
query: http://192.168.0.134:3000/api/v1/executions/
api-key: pg61JW6W_GXyqmqSoURJ4mlSRrCMRzGLBJli_w3BFkg

View File

@ -1,6 +1,8 @@
package com.cmvr.test.service;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.cmvr.common.exception.GlobalException;
import com.cmvr.common.utils.http.CallAPIUtil;
@ -35,6 +37,9 @@ public class FlowiseActionService {
@Value("${flowise.tts}")
private String flowiseTts;
@Value("${flowise.query}")
private String flowiseQuery;
@Value("${flowise.start}")
private String flowiseStart;
@ -52,6 +57,8 @@ public class FlowiseActionService {
private String chatId = null;
public String start(FlowiseStartRequestVO request) {
log.info("flowise start");
abort();
synchronized (lock) {
if (chatId != null) {
throw new GlobalException("Flow is already running: " + chatId);
@ -68,6 +75,7 @@ public class FlowiseActionService {
try {
HttpRequest.post(flowiseStart)
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + flowiseApiKey)
.body(body.toJSONString())
.timeout(0)
.execute()
@ -76,7 +84,6 @@ public class FlowiseActionService {
throw new GlobalException("flowise 流程执行失败: ", e.getMessage());
}
});
return chatId;
}
}
@ -90,7 +97,7 @@ public class FlowiseActionService {
synchronized (lock) {
if (chatId == null) {
throw new GlobalException( "No flow running.");
return "No flow running.";
}
String id = chatId;
@ -107,6 +114,7 @@ public class FlowiseActionService {
}
public String command(FlowiseActionRequestVO request) {
log.info("command start");
String action = request.getAction();
FlowiseActionEnum actionEnum = FlowiseActionEnum.fromAction(action);
String terminalId = "4ed1246c465b97975f96c9ef8371a3bd";
@ -134,12 +142,25 @@ public class FlowiseActionService {
}
public String chat(FlowiseChatRequestVO requestVO) {
log.info("chat start");
Map<String, String> body = new HashMap<>();
body.put("text", requestVO.getText());
body.put("voice", "x4_yezi");
CallAPIUtil.doPostJson(flowiseTts + "play", null, body);
return "ok";
}
public JSONObject query(String chatId) {
String body = HttpRequest.get(flowiseQuery + chatId)
.header("Authorization", "Bearer " + flowiseApiKey)
.execute()
.body();
JSONObject root = JSON.parseObject(body);
String execStr = root.getString("executionData");
JSONArray execJson = JSON.parseArray(execStr);
root.put("executionData", execJson);
return root;
}
}