You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.4 KiB
68 lines
2.4 KiB
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);
|
|
}
|
|
|
|
@GetMapping("chat/history/{sessionId}")
|
|
@ApiOperation("查询我的聊天记录")
|
|
public R<List<ChatSession.Message>> getHistory(@PathVariable String sessionId) {
|
|
List<ChatSession.Message> history = chatSessionService.listMyHistory(sessionId);
|
|
return R.success(history);
|
|
}
|
|
@PostMapping("session/create")
|
|
@ApiOperation("创建聊天会话")
|
|
public R<String> createSession() {
|
|
String sessionId = chatSessionService.createSession();
|
|
return R.success(sessionId);
|
|
}
|
|
|
|
@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);
|
|
}
|
|
|
|
|
|
|
|
|
|
} |