zhou zhou
16 小时以前 eb49fb9a98d6dd4e4361daf4eac4f9313236b8e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.vincent.rsf.server.ai.controller;
 
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.server.ai.dto.AiChatRequest;
import com.vincent.rsf.server.ai.service.AiChatService;
import com.vincent.rsf.server.system.controller.BaseController;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
 
@RestController
@RequiredArgsConstructor
public class AiChatController extends BaseController {
 
    private final AiChatService aiChatService;
 
    @PreAuthorize("isAuthenticated()")
    @GetMapping("/ai/chat/runtime")
    public R runtime(@RequestParam(required = false) String promptCode,
                     @RequestParam(required = false) Long sessionId) {
        return R.ok().add(aiChatService.getRuntime(promptCode, sessionId, getLoginUserId(), getTenantId()));
    }
 
    @PreAuthorize("isAuthenticated()")
    @GetMapping("/ai/chat/sessions")
    public R sessions(@RequestParam(required = false) String promptCode) {
        return R.ok().add(aiChatService.listSessions(promptCode, getLoginUserId(), getTenantId()));
    }
 
    @PreAuthorize("isAuthenticated()")
    @PostMapping("/ai/chat/session/remove/{sessionId}")
    public R removeSession(@PathVariable Long sessionId) {
        aiChatService.removeSession(sessionId, getLoginUserId(), getTenantId());
        return R.ok("Delete Success").add(sessionId);
    }
 
    @PreAuthorize("isAuthenticated()")
    @PostMapping(value = "/ai/chat/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter stream(@RequestBody AiChatRequest request) {
        return aiChatService.stream(request, getLoginUserId(), getTenantId());
    }
}