|
|
@@ -1,9 +1,12 @@
|
|
|
package com.ruoyi.uniapp.controller;
|
|
|
|
|
|
+import com.ruoyi.common.core.domain.R;
|
|
|
import com.ruoyi.common.core.enums.dify.ResponseMode;
|
|
|
import com.ruoyi.common.core.model.chat.ChatMessage;
|
|
|
import com.ruoyi.common.core.callback.ChatStreamCallback;
|
|
|
import com.ruoyi.common.core.event.*;
|
|
|
+import com.ruoyi.common.core.model.chat.SuggestedQuestionsResponse;
|
|
|
+import com.ruoyi.common.core.model.common.SimpleResponse;
|
|
|
import com.ruoyi.uniapp.utils.DifyChatClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
@@ -28,6 +31,37 @@ public class ChatController {
|
|
|
public ChatMessageResponse sendMessage(@RequestBody ChatMessage message) throws IOException {
|
|
|
return chatClient.sendChatMessage(message);
|
|
|
}*/
|
|
|
+ /*
|
|
|
+ * 获取下一轮建议问题列表
|
|
|
+ */
|
|
|
+ @GetMapping("/suggested")
|
|
|
+ public R suggestedStream(@RequestParam String messageId, @RequestParam String user){
|
|
|
+ if (messageId == null && user == null){
|
|
|
+ return R.fail("参数异常,请检查消息ID或用户ID");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ SuggestedQuestionsResponse suggestedQuestions = chatClient.getSuggestedQuestions(messageId, user);
|
|
|
+ return R.ok(suggestedQuestions.getData());
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 停止会话响应
|
|
|
+ */
|
|
|
+ @PostMapping("/stop")
|
|
|
+ public R stopStream(@RequestBody ChatMessage message){
|
|
|
+ if (message.getTaskId() == null && message.getUser() == null){
|
|
|
+ return R.fail("参数异常,请检查任务ID或用户ID");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ SimpleResponse simpleResponse = chatClient.stopChatMessage(message.getTaskId(), message.getUser());
|
|
|
+ return R.ok(simpleResponse.getResult());
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 发送流式聊天消息
|
|
|
@@ -41,8 +75,8 @@ public class ChatController {
|
|
|
|
|
|
// 创建SSE发射器,设置超时时间为2分钟
|
|
|
SseEmitter emitter = new SseEmitter(120000L);
|
|
|
- String emitterId = message.getUser() + "_" + System.currentTimeMillis();
|
|
|
- message.setUser(emitterId);
|
|
|
+// String emitterId = message.getUser() + "_" + System.currentTimeMillis();
|
|
|
+// message.setUser(emitterId); userId前端传递
|
|
|
|
|
|
try {
|
|
|
// 发送流式消息
|