| | |
| | | import com.vincent.rsf.server.ai.service.AiChatService; |
| | | import com.vincent.rsf.server.system.controller.BaseController; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; |
| | | |
| | | import java.util.UUID; |
| | | |
| | | @RestController |
| | | @Slf4j |
| | | @RequiredArgsConstructor |
| | | public class AiChatController extends BaseController { |
| | | |
| | |
| | | @PreAuthorize("isAuthenticated()") |
| | | @PostMapping(value = "/ai/chat/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) |
| | | public SseEmitter stream(@RequestBody AiChatRequest request) { |
| | | String requestId = StringUtils.hasText(request.getRequestId()) |
| | | ? request.getRequestId().trim() |
| | | : UUID.randomUUID().toString().replace("-", ""); |
| | | request.setRequestId(requestId); |
| | | log.info("AI chat request accepted, requestId={}, userId={}, tenantId={}, sessionId={}", |
| | | requestId, getLoginUserId(), getTenantId(), request.getSessionId()); |
| | | return aiChatService.stream(request, getLoginUserId(), getTenantId()); |
| | | } |
| | | } |