File tree Expand file tree Collapse file tree
src/main/java/com/example/customschatbotbe/domain/chatbot Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import com .example .customschatbotbe .domain .chatbot .dto .request .ChatRequest ;
55import com .example .customschatbotbe .domain .chatbot .dto .response .ChatResponse ;
66import com .example .customschatbotbe .global .exception .response .ApiResponse ;
7+ import jakarta .servlet .http .HttpServletRequest ;
78import lombok .RequiredArgsConstructor ;
89import org .springframework .http .ResponseEntity ;
910import org .springframework .web .bind .annotation .PostMapping ;
@@ -21,8 +22,9 @@ public class ChatBotController {
2122 private final ChatBotService chatBotService ;
2223
2324 @ PostMapping
24- public Mono <ResponseEntity <ApiResponse <ChatResponse >>> chat (@ RequestBody ChatRequest chatRequest ) {
25- return chatBotService .generateReply (chatRequest )
25+ public Mono <ResponseEntity <ApiResponse <ChatResponse >>> chat (@ RequestBody ChatRequest chatRequest , HttpServletRequest httpServletRequest ) {
26+ String sessionId = httpServletRequest .getSession ().getId ();
27+ return chatBotService .generateReply (chatRequest , sessionId )
2628 .map (chatResponse -> ResponseEntity .ok (ApiResponse .success (SUCCESS , chatResponse )));
2729 }
2830}
Original file line number Diff line number Diff line change 1+ package com .example .customschatbotbe .domain .chatbot .dto .request ;
2+
3+ import lombok .Builder ;
4+ import lombok .Getter ;
5+ import lombok .Setter ;
6+
7+ @ Getter
8+ @ Setter
9+ @ Builder
10+ public class AiChatRequest {
11+ private String message ;
12+ private String sessionId ;
13+ }
Original file line number Diff line number Diff line change 11package com .example .customschatbotbe .domain .chatbot .service ;
22
3+ import com .example .customschatbotbe .domain .chatbot .dto .request .AiChatRequest ;
34import com .example .customschatbotbe .domain .chatbot .dto .request .ChatRequest ;
45import com .example .customschatbotbe .domain .chatbot .dto .response .ChatResponse ;
56import com .example .customschatbotbe .global .exception .BusinessException ;
1415public class ChatBotService {
1516 private final WebClient webClient ;
1617
17- public Mono <ChatResponse > generateReply (ChatRequest chatRequest ){
18+ public Mono <ChatResponse > generateReply (ChatRequest chatRequest , String sessionId ){
1819 try {
1920 return webClient .post ()
2021 .uri ("/predict" )
21- .bodyValue (chatRequest )
22+ .bodyValue (AiChatRequest .builder ()
23+ .message (chatRequest .getMessage ())
24+ .sessionId (sessionId )
25+ .build ())
2226 .retrieve ()
2327 .bodyToMono (ChatResponse .class );
2428 } catch (Exception e ) {
You can’t perform that action at this time.
0 commit comments