ai-manus/chat-server/src/main/java/com/bjtds/brichat/controller/ChatController.java

57 lines
1.7 KiB
Java
Raw Normal View History

2025-07-18 16:38:18 +08:00
package com.bjtds.brichat.controller;
import com.bjtds.brichat.entity.chat.ChatMessageSendReq;
import com.bjtds.brichat.service.ChatService;
import io.github.guoshiqiufeng.dify.chat.dto.request.ChatMessageSendRequest;
import io.github.guoshiqiufeng.dify.chat.dto.response.ChatMessageSendCompletionResponse;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import javax.annotation.Resource;
@Api(tags = "对话聊天接口")
@Slf4j
@RestController
@CrossOrigin(value = "*",maxAge = 3600)
@RequestMapping("/chat")
public class ChatController {
@Resource
private ChatService chatService;
/***
* 故障诊断对话接口
* @param
* @return
*/
@PostMapping(value = "/diagnose/completions", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<ChatMessageSendCompletionResponse> sendChatMessageStream(@RequestBody ChatMessageSendReq req) {
ChatMessageSendRequest sendRequest = new ChatMessageSendRequest();
sendRequest.setInputs(req.getInputs());
sendRequest.setConversationId(req.getConversationId());
sendRequest.setContent(req.getContent());
sendRequest.setUserId(req.getUserId());
return chatService.sendChatMessageStream(sendRequest,req.getChatType());
}
/***
* 停止对话
* @param chatType 会话类型
*/
@GetMapping("/stop")
public void stopMessagesStream( @RequestParam("chatType") Integer chatType,
@RequestParam("taskId") String taskId, @RequestParam("userId") String userId){
chatService.stopMessagesStream(chatType, taskId, userId);
}
}