|
|
|
package cn.teammodel.controller.frontend;
|
|
|
|
|
|
|
|
import cn.teammodel.common.IdRequest;
|
|
|
|
import cn.teammodel.common.R;
|
|
|
|
import cn.teammodel.model.dto.ai.ChatCompletionReqDto;
|
|
|
|
import cn.teammodel.model.dto.ai.UpdateSessionDto;
|
|
|
|
import cn.teammodel.model.entity.ai.ChatSession;
|
|
|
|
import cn.teammodel.service.ChatMessageService;
|
|
|
|
import cn.teammodel.service.ChatSessionService;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/ai")
|
|
|
|
public class AiController {
|
|
|
|
@Resource
|
|
|
|
private ChatSessionService chatSessionService;
|
|
|
|
@Resource
|
|
|
|
private ChatMessageService chatMessageService;
|
|
|
|
|
|
|
|
@PostMapping("chat/completion")
|
|
|
|
@ApiOperation("与 spark 的流式对话")
|
|
|
|
public SseEmitter chatCompletion(@RequestBody @Valid ChatCompletionReqDto chatCompletionReqDto) {
|
|
|
|
return chatMessageService.chatCompletion(chatCompletionReqDto);
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("session/my")
|
|
|
|
@ApiOperation("查询我的聊天会话")
|
|
|
|
public R<List<ChatSession>> listMySession() {
|
|
|
|
List<ChatSession> sessions = chatSessionService.listMySession();
|
|
|
|
return R.success(sessions);
|
|
|
|
}
|
|
|
|
@PostMapping("session/create")
|
|
|
|
@ApiOperation("创建聊天会话")
|
|
|
|
public R<String> createSession() {
|
|
|
|
chatSessionService.createSession();
|
|
|
|
return R.success("创建会话成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("session/remove")
|
|
|
|
@ApiOperation("删除聊天会话")
|
|
|
|
public R<String> removeSession(@RequestBody @Valid IdRequest idRequest) {
|
|
|
|
chatSessionService.deleteSession(idRequest.getId());
|
|
|
|
return R.success("删除会话成功");
|
|
|
|
}
|
|
|
|
@PostMapping("session/update")
|
|
|
|
@ApiOperation("更新聊天会话")
|
|
|
|
public R<ChatSession> updateSession(@RequestBody @Valid UpdateSessionDto updateSessionDto) {
|
|
|
|
ChatSession session = chatSessionService.updateSession(updateSessionDto);
|
|
|
|
return R.success(session);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|