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
44 changes: 28 additions & 16 deletions backend/src/main/java/com/ai/lawyer/domain/chatbot/dto/ChatDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.springframework.ai.document.Document;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Schema(description = "채팅 관련 DTO")
public class ChatDto {
Expand Down Expand Up @@ -42,11 +40,10 @@ public static class ChatResponse {
@Schema(description = "AI 챗봇의 응답 메시지", example = "네, 관련 법령과 판례를 바탕으로 답변해 드리겠습니다.")
private String message;

@Schema(description = "응답 생성에 참고한 유사 판례 정보 목록")
private List<Document> similarCases;
private ChatPrecedentDto precedent;

private ChatLawDto law;

@Schema(description = "응답 생성에 참고한 유사 법령 정보 목록")
private List<Document> similarLaws;
}

@Getter
Expand All @@ -73,6 +70,14 @@ public static ChatPrecedentDto from(ChatPrecedent cp) {
.caseName(cp.getCaseName())
.build();
}

public static ChatPrecedentDto from(Document doc) {
return ChatPrecedentDto.builder()
.precedentContent(doc.getText())
.caseNumber(doc.getMetadata().get("caseNumber").toString())
.caseName(doc.getMetadata().get("caseName").toString())
.build();
}
}

@Data
Expand All @@ -93,6 +98,13 @@ public static ChatLawDto from(ChatLaw cl) {
.lawName(cl.getLawName())
.build();
}

public static ChatLawDto from(Document doc) {
return ChatLawDto.builder()
.content(doc.getText())
.lawName(doc.getMetadata().get("lawName").toString())
.build();
}
}

@Getter
Expand All @@ -109,31 +121,31 @@ public static class ChatHistoryDto {
@Schema(description = "메시지 내용", example = "안녕하세요~~")
private String message;

private List<ChatPrecedentDto> precedents;
private ChatPrecedentDto precedent;

private List<ChatLawDto> laws;
private ChatLawDto law;

@Schema(description = "생성 시간")
private LocalDateTime createdAt;

public static ChatHistoryDto from(Chat chat) {

List<ChatPrecedentDto> precedentDtos = new ArrayList<>();
for (ChatPrecedent cp : chat.getChatPrecedents()) {
precedentDtos.add(ChatPrecedentDto.from(cp));
ChatPrecedentDto precedentDto = null;
if (chat.getChatPrecedents() != null && !chat.getChatPrecedents().isEmpty()) {
precedentDto = ChatPrecedentDto.from(chat.getChatPrecedents().get(0));
}

List<ChatLawDto> lawDtos = new ArrayList<>();
for (ChatLaw cl : chat.getChatLaws()) {
lawDtos.add(ChatLawDto.from(cl));
ChatLawDto lawDto = null;
if (chat.getChatLaws() != null && !chat.getChatLaws().isEmpty()) {
lawDto = ChatLawDto.from(chat.getChatLaws().get(0));
}

return ChatHistoryDto.builder()
.type(chat.getType().toString())
.message(chat.getMessage())
.createdAt(chat.getCreatedAt())
.precedents(precedentDtos)
.laws(lawDtos)
.precedent(precedentDto)
.law(lawDto)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ai.lawyer.domain.chatbot.service;

import com.ai.lawyer.domain.chatbot.dto.ChatDto.ChatLawDto;
import com.ai.lawyer.domain.chatbot.dto.ChatDto.ChatPrecedentDto;
import com.ai.lawyer.domain.chatbot.dto.ChatDto.ChatRequest;
import com.ai.lawyer.domain.chatbot.dto.ChatDto.ChatResponse;
import com.ai.lawyer.domain.chatbot.dto.ExtractionDto.KeywordExtractionDto;
Expand Down Expand Up @@ -93,12 +95,25 @@ public Flux<ChatResponse> sendMessage(Long memberId, ChatRequest chatChatRequest
}

private ChatResponse ChatResponse(History history, String fullResponse, List<Document> cases, List<Document> laws) {

ChatPrecedentDto precedentDto = null;
if (cases != null && !cases.isEmpty()) {
Document firstCase = cases.get(0);
precedentDto = ChatPrecedentDto.from(firstCase);
}

ChatLawDto lawDto = null;
if (laws != null && !laws.isEmpty()) {
Document firstLaw = laws.get(0);
lawDto = ChatLawDto.from(firstLaw);
}

return ChatResponse.builder()
.roomId(history.getHistoryId())
.title(history.getTitle())
.message(fullResponse)
.similarCases(cases)
.similarLaws(laws)
.precedent(precedentDto)
.law(lawDto)
.build();
}

Expand Down