fix: flowise

This commit is contained in:
stream 2025-12-08 15:51:26 +08:00
parent 8876b4e70f
commit c702f091b5
4 changed files with 39 additions and 35 deletions

View File

@ -3,6 +3,8 @@ package com.cmvr.web.controller.test;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.test.model.vo.FlowiseActionRequestVO;
import com.cmvr.test.model.vo.FlowiseChatRequestVO;
import com.cmvr.test.model.vo.FlowiseStartRequestVO;
import com.cmvr.test.service.FlowiseActionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -11,7 +13,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "测试--flowise服务")
@ -24,8 +25,8 @@ public class TeFlowiseController extends BaseController {
@ApiOperation("调用flowise")
@PostMapping("/start")
public AjaxResult start(String question) {
return AjaxResult.ok(flowiseActionService.start(question));
public AjaxResult start(@RequestBody FlowiseStartRequestVO request) {
return AjaxResult.ok(flowiseActionService.start(request));
}
@ApiOperation("终止flowise")
@ -42,7 +43,7 @@ public class TeFlowiseController extends BaseController {
@ApiOperation("闲聊")
@GetMapping("/chat")
public AjaxResult chat(@RequestParam("text") String text) {
return AjaxResult.ok(flowiseActionService.chat(text));
public AjaxResult chat(@RequestBody FlowiseChatRequestVO request) {
return AjaxResult.ok(flowiseActionService.chat(request));
}
}

View File

@ -0,0 +1,9 @@
package com.cmvr.test.model.vo;
import lombok.Data;
@Data
public class FlowiseChatRequestVO {
private String text;
}

View File

@ -0,0 +1,9 @@
package com.cmvr.test.model.vo;
import lombok.Data;
@Data
public class FlowiseStartRequestVO {
private String question;
}

View File

@ -5,10 +5,11 @@ import com.alibaba.fastjson2.JSONObject;
import com.cmvr.common.exception.GlobalException;
import com.cmvr.common.utils.http.CallAPIUtil;
import com.cmvr.common.utils.uuid.IdUtils;
import com.cmvr.edge.client.model.EdgeCommonVO;
import com.cmvr.edge.client.service.EdgeBioHeadService;
import com.cmvr.test.enums.FlowiseActionEnum;
import com.cmvr.test.model.vo.FlowiseActionRequestVO;
import com.cmvr.test.model.vo.FlowiseChatRequestVO;
import com.cmvr.test.model.vo.FlowiseStartRequestVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@ -41,23 +42,20 @@ public class FlowiseActionService {
@Resource(name = "threadPoolTaskExecutor")
private final ThreadPoolTaskExecutor executor;
private final String terminalId = "4ed1246c465b97975f96c9ef8371a3bd";
private final String bioId = "bio_head";
private final Object lock = new Object();
private String chatId = null;
public String start(String question) {
public String start(FlowiseStartRequestVO request) {
synchronized (lock) {
if (chatId != null) {
return "Flow is already running: " + chatId;
throw new GlobalException("Flow is already running: " + chatId);
}
chatId = IdUtils.fastUUID();
JSONObject body = new JSONObject();
body.put("question", question);
body.put("question", request.getQuestion());
body.put("chatId", chatId);
body.put("streaming", true);
@ -70,7 +68,7 @@ public class FlowiseActionService {
.execute()
.body();
} catch (Exception e) {
throw new GlobalException("flowise 流程执行失败: ", e.getMessage());
throw new GlobalException("flowise 流程执行失败: ", e.getMessage());
}
});
@ -79,15 +77,11 @@ public class FlowiseActionService {
}
public String abort() {
EdgeCommonVO edgeCommonVO = new EdgeCommonVO();
edgeCommonVO.setDeviceId(bioId);
edgeCommonVO.setTerminalId(terminalId);
edgeBioHeadService.speakStop(edgeCommonVO);
CallAPIUtil.doPostJson(flowiseTts + "stop", null, null);
synchronized (lock) {
if (chatId == null) {
return "No flow running.";
throw new GlobalException( "No flow running.");
}
String id = chatId;
@ -106,6 +100,8 @@ public class FlowiseActionService {
public String command(FlowiseActionRequestVO request) {
String action = request.getAction();
FlowiseActionEnum actionEnum = FlowiseActionEnum.fromAction(action);
String terminalId = "4ed1246c465b97975f96c9ef8371a3bd";
String bioId = "bio_head";
switch (actionEnum) {
// ==== 表情 ====
case SMILE:
@ -128,24 +124,13 @@ public class FlowiseActionService {
}
}
public String chat(String text) {
// 播放前调用张嘴
EdgeCommonVO edgeCommonVO = new EdgeCommonVO();
edgeCommonVO.setDeviceId(bioId);
edgeCommonVO.setTerminalId(terminalId);
try {
Map<String, String> body = new HashMap<>();
body.put("text", text);
body.put("voice", "x4_yezi");
public String chat(FlowiseChatRequestVO requestVO) {
Map<String, String> body = new HashMap<>();
body.put("text", requestVO.getText());
body.put("voice", "x4_yezi");
// edgeBioHeadService.speakStart(edgeCommonVO);
CallAPIUtil.doPostJson(flowiseTts + "play", null, body);
} finally {
// 播放完成调用闭嘴
// edgeBioHeadService.speakStop(edgeCommonVO);
}
CallAPIUtil.doPostJson(flowiseTts + "play", null, body);
return "ok";
}
}
}