Skip to content
Merged

work #346

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
Expand Up @@ -61,13 +61,7 @@ public class ChatBotService {
// ๋ฉค๋ฒ„ ์กฐํšŒ -> ๋ฒกํ„ฐ ๊ฒ€์ƒ‰ -> ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ -> LLM ํ˜ธ์ถœ (์ŠคํŠธ๋ฆผ) -> Kafka ์ด๋ฒคํŠธ ๋ฐœํ–‰ -> ์‘๋‹ต ๋ฐ˜ํ™˜
@Transactional
public Flux<ChatResponse> sendMessage(Long memberId, ChatRequest chatRequestDto, Long roomId) {

// Mono.fromCallable()๊ณผ subscribeOn()์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ธ”๋กœํ‚น ์ž‘์—…์„ ๋ณ„๋„ ์Šค๋ ˆ๋“œ์—์„œ ์‹คํ–‰
// boundedElastic ์Šค์ผ€์ค„๋Ÿฌ๋Š” ๋ธ”๋กœํ‚น I/O ์ž‘์—…์— ์ตœ์ ํ™”๋œ ์Šค๋ ˆ๋“œ ํ’€ ์‚ฌ์šฉ
return Mono.fromCallable(() -> {
// ๋ฉค๋ฒ„ ์กฐํšŒ (๋ธ”๋กœํ‚น)
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new IllegalArgumentException("์กด์žฌํ•˜์ง€ ์•Š๋Š” ํšŒ์›์ž…๋‹ˆ๋‹ค."));

// ๋ฒกํ„ฐ ๊ฒ€์ƒ‰ (ํŒ๋ก€, ๋ฒ•๋ น) (๋ธ”๋กœํ‚น)
List<Document> similarCaseDocuments = qdrantService.searchDocument(chatRequestDto.getMessage(), "type", "ํŒ๋ก€");
Expand All @@ -77,7 +71,7 @@ public Flux<ChatResponse> sendMessage(Long memberId, ChatRequest chatRequestDto,
String lawContext = formatting(similarLawDocuments);

// ์ฑ„ํŒ…๋ฐฉ ์กฐํšŒ ๋˜๋Š” ์ƒ์„ฑ (๋ธ”๋กœํ‚น)
History history = getOrCreateRoom(member, roomId);
History history = getOrCreateRoom(memberId, roomId);

// ๋ฉ”์‹œ์ง€ ๊ธฐ์–ต ๊ด€๋ฆฌ (User ๋ฉ”์‹œ์ง€ ์ถ”๊ฐ€)
ChatMemory chatMemory = saveChatMemory(chatRequestDto, history);
Expand Down Expand Up @@ -167,11 +161,11 @@ private Prompt getPrompt(String caseContext, String lawContext, ChatMemory chatM
return new Prompt(List.of(systemMessage, userMessage));
}

private History getOrCreateRoom(Member member, Long roomId) {
private History getOrCreateRoom(Long memberId, Long roomId) {
if (roomId != null) {
return historyService.getHistory(roomId);
} else {
return historyRepository.save(History.builder().memberId(member.getMemberId()).build());
return historyRepository.save(History.builder().memberId(memberId).build());
}
}

Expand Down