Skip to content

Commit 73ee202

Browse files
committed
fix[chat]: 지저분한 코드 수정
1 parent f43978f commit 73ee202

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

backend/src/main/java/com/ai/lawyer/domain/chatbot/controller/ChatBotController.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ public class ChatBotController {
2323
@Operation(summary = "01. 새로운 채팅", description = "첫 메시지 전송으로 새로운 채팅방을 생성하고 챗봇과 대화를 시작")
2424
@PostMapping(value = "/message")
2525
public Flux<ChatResponse> postNewMessage(@RequestBody ChatRequest chatRequest) {
26-
// SecurityContext에서 memberId를 미리 추출 (컨트롤러 진입 시점)
26+
2727
Long memberId = AuthUtil.getAuthenticatedMemberId();
28-
if (memberId == null) {
29-
throw new IllegalStateException("인증된 사용자가 아닙니다.");
30-
}
28+
3129
log.info("새로운 채팅 요청: memberId={}", memberId);
3230

33-
// memberId를 Flux에 전달 (SecurityContext 전파 문제 방지)
3431
return chatBotService.sendMessage(memberId, chatRequest, null);
3532
}
3633

@@ -39,11 +36,11 @@ public Flux<ChatResponse> postNewMessage(@RequestBody ChatRequest chatRequest) {
3936
public Flux<ChatResponse> postMessage(
4037
@RequestBody ChatRequest chatRequest,
4138
@PathVariable(value = "roomId", required = false) Long roomId) {
42-
// SecurityContext에서 memberId를 미리 추출 (컨트롤러 진입 시점)
39+
4340
Long memberId = AuthUtil.getAuthenticatedMemberId();
41+
4442
log.info("기존 채팅 요청: memberId={}, roomId={}", memberId, roomId);
4543

46-
// memberId를 Flux에 전달 (SecurityContext 전파 문제 방지)
4744
return chatBotService.sendMessage(memberId, chatRequest, roomId);
4845
}
4946

backend/src/main/java/com/ai/lawyer/domain/chatbot/service/ChatBotService.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,22 @@ public class ChatBotService {
5757
@Transactional
5858
public Flux<ChatResponse> sendMessage(Long memberId, ChatRequest chatRequestDto, Long roomId) {
5959

60-
// 벡터 검색 (판례, 법령) (블로킹)
60+
// 벡터 검색 (판례, 법령)
6161
List<Document> similarCaseDocuments = qdrantService.searchDocument(chatRequestDto.getMessage(), "type", "판례");
6262
List<Document> similarLawDocuments = qdrantService.searchDocument(chatRequestDto.getMessage(), "type", "법령");
6363

6464
String caseContext = formatting(similarCaseDocuments);
6565
String lawContext = formatting(similarLawDocuments);
6666

67-
// 채팅방 조회 또는 생성 (블로킹)
67+
// 채팅방 조회 또는 생성
6868
History history = getOrCreateRoom(memberId, roomId);
6969

70-
// 메시지 기억 관리 (User 메시지 추가)
70+
// 메시지 기억 관리
7171
ChatMemory chatMemory = saveChatMemory(chatRequestDto, history);
7272

7373
// 프롬프트 생성
7474
Prompt prompt = getPrompt(caseContext, lawContext, chatMemory, history);
7575

76-
// 준비된 데이터를 담은 컨텍스트 객체 반환
77-
//return new PreparedChatContext(prompt, history, similarCaseDocuments, similarLawDocuments);
78-
7976
return chatClient.prompt(prompt)
8077
.stream()
8178
.content()
@@ -176,23 +173,4 @@ private ChatResponse handleError(History history) {
176173
.build();
177174
}
178175

179-
/**
180-
* 블로킹 작업에서 준비된 데이터를 담는 컨텍스트 클래스
181-
* 리액티브 체인에서 데이터를 전달하기 위한 내부 클래스
182-
*/
183-
private static class PreparedChatContext {
184-
final Prompt prompt;
185-
final History history;
186-
final List<Document> similarCaseDocuments;
187-
final List<Document> similarLawDocuments;
188-
189-
PreparedChatContext(Prompt prompt, History history,
190-
List<Document> similarCaseDocuments,
191-
List<Document> similarLawDocuments) {
192-
this.prompt = prompt;
193-
this.history = history;
194-
this.similarCaseDocuments = similarCaseDocuments;
195-
this.similarLawDocuments = similarLawDocuments;
196-
}
197-
}
198176
}

0 commit comments

Comments
 (0)