refactor: 修改接口

11111
winter 8 months ago
parent 5d33226f94
commit b7126f7bd8

@ -23,7 +23,7 @@ import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@RestController @RestController
@RequestMapping("/ai/api") @RequestMapping("/ai")
@Api(tags = "AI 能力") @Api(tags = "AI 能力")
public class AiController { public class AiController {
@Resource @Resource
@ -33,12 +33,17 @@ public class AiController {
@Resource @Resource
private ChatAppService chatAppService; private ChatAppService chatAppService;
@PostMapping("chat/completion") @PostMapping("api/chat/completion")
@ApiOperation("与 spark 的流式对话") @ApiOperation("与 spark 的流式对话")
public SseEmitter chatCompletion(@RequestBody @Valid ChatCompletionReqDto chatCompletionReqDto) { public SseEmitter chatCompletionToApi(@RequestBody @Valid ChatCompletionReqDto chatCompletionReqDto) {
String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject(); String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject();
return chatMessageService.chatCompletion(chatCompletionReqDto, userId); return chatMessageService.chatCompletion(chatCompletionReqDto, userId);
} }
@PostMapping("chat/completion")
@ApiOperation("与 spark 的流式对话")
public SseEmitter chatCompletion(@RequestBody @Valid ChatCompletionReqDto chatCompletionReqDto) {
return chatMessageService.chatCompletion(chatCompletionReqDto, null);
}
// @PostMapping("chat/test/completion") // @PostMapping("chat/test/completion")
@ApiOperation("与 spark 的流式对话") @ApiOperation("与 spark 的流式对话")
@ -74,7 +79,7 @@ public class AiController {
return sseEmitter; return sseEmitter;
} }
@GetMapping("session/my") @GetMapping("api/session/my")
@ApiOperation("查询我的聊天会话") @ApiOperation("查询我的聊天会话")
public R<List<ChatSession>> listMySession() { public R<List<ChatSession>> listMySession() {
String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject(); String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject();
@ -82,14 +87,14 @@ public class AiController {
return R.success(sessions); return R.success(sessions);
} }
@GetMapping("chat/history/{sessionId}") @GetMapping("api/chat/history/{sessionId}")
@ApiOperation("查询我的聊天记录") @ApiOperation("查询我的聊天记录")
public R<List<ChatSession.Message>> getHistory(@PathVariable String sessionId) { public R<List<ChatSession.Message>> getHistory(@PathVariable String sessionId) {
String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject(); String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject();
List<ChatSession.Message> history = chatSessionService.listHistory(sessionId, userId); List<ChatSession.Message> history = chatSessionService.listHistory(sessionId, userId);
return R.success(history); return R.success(history);
} }
@PostMapping("session/create") @PostMapping("api/session/create")
@ApiOperation("创建聊天会话") @ApiOperation("创建聊天会话")
public R<String> createSession() { public R<String> createSession() {
String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject(); String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject();
@ -99,14 +104,14 @@ public class AiController {
return R.success(sessionId); return R.success(sessionId);
} }
@PostMapping("session/remove") @PostMapping("api/session/remove")
@ApiOperation("删除聊天会话") @ApiOperation("删除聊天会话")
public R<String> removeSession(@RequestBody @Valid IdRequest idRequest) { public R<String> removeSession(@RequestBody @Valid IdRequest idRequest) {
String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject(); String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject();
chatSessionService.deleteSession(idRequest.getId(), userId); chatSessionService.deleteSession(idRequest.getId(), userId);
return R.success("删除会话成功"); return R.success("删除会话成功");
} }
@PostMapping("session/update") @PostMapping("api/session/update")
@ApiOperation("更新聊天会话") @ApiOperation("更新聊天会话")
public R<ChatSession> updateSession(@RequestBody @Valid UpdateSessionDto updateSessionDto) { public R<ChatSession> updateSession(@RequestBody @Valid UpdateSessionDto updateSessionDto) {
String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject(); String userId = ((TmdUserDetail) SecurityUtil.getAuthentication().getPrincipal()).getClaims().getSubject();

Loading…
Cancel
Save