Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ureca.ufit.domain.chatbot.controller;

import java.util.concurrent.CompletableFuture;

import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -50,12 +52,14 @@ public ResponseEntity<CreateChatBotReviewResponse> createChatBotReview(CreateCha
}

@Override
public ResponseEntity<CreateChatBotMessageResponse> createChatBotMessage(CustomUserDetails userDetails,
public ResponseEntity<CompletableFuture<CreateChatBotMessageResponse>> createChatBotMessage(
CustomUserDetails userDetails,
CreateChatBotMessageRequest request) {

Long userId = (userDetails != null) ? userDetails.userId() : nonUserId;

CreateChatBotMessageResponse response = chatBotMessageService.createChatBotMessage(request, userId);
CompletableFuture<CreateChatBotMessageResponse> response = chatBotMessageService.createChatBotMessage(request,
userId);
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ureca.ufit.domain.chatbot.controller;

import java.util.concurrent.CompletableFuture;

import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -107,7 +109,7 @@ public ResponseEntity<CreateChatBotReviewResponse> createChatBotReview(
content = @Content(schema = @Schema(implementation = CreateChatBotMessageResponse.class))
))
@PostMapping("/message")
public ResponseEntity<CreateChatBotMessageResponse> createChatBotMessage(
public ResponseEntity<CompletableFuture<CreateChatBotMessageResponse>> createChatBotMessage(
@Parameter(hidden = true)
@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestBody @Valid CreateChatBotMessageRequest request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.ureca.ufit.global.profanity.BanwordFilterPolicy.*;

import java.util.Set;
import java.util.concurrent.CompletableFuture;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -45,7 +46,8 @@ public CursorPageResponse<ChatMessageDto> getChatMessages(Long chatRoomId, Pagea
}

@Async
public CreateChatBotMessageResponse createChatBotMessage(CreateChatBotMessageRequest request, Long userId) {
public CompletableFuture<CreateChatBotMessageResponse> createChatBotMessage(CreateChatBotMessageRequest request,
Long userId) {

Set<BanwordFilterPolicy> policies = Set.of(NUMBERS, WHITESPACES);

Expand All @@ -58,11 +60,12 @@ public CreateChatBotMessageResponse createChatBotMessage(CreateChatBotMessageReq
CreateAIAnswerRequest createAIAnswerRequest = ChatMessageMapper.toCreateAIAnswerRequest(request, userId);

try {
return restTemplate.postForObject(
CreateChatBotMessageResponse response = restTemplate.postForObject(
fastApiUrl,
createAIAnswerRequest,
CreateChatBotMessageResponse.class
);
return CompletableFuture.completedFuture(response);

} catch (Exception e) {
throw new RestApiException(ChatBotErrorCode.LLM_TIMEOUT);
Expand Down