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