Skip to content

Commit c74dc3b

Browse files
committed
Merge branch 'develop' into feat/oauth
2 parents bb648f3 + 2b87b55 commit c74dc3b

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ChatBotService {
3737

3838
private final QdrantService qdrantService;
3939
private final HistoryService historyService;
40+
private final KeywordService keywordService;
4041

4142
private final ChatRepository chatRepository;
4243
private final HistoryRepository historyRepository;
@@ -91,14 +92,6 @@ public Flux<ChatResponse> sendMessage(Long memberId, ChatRequest chatChatRequest
9192
.onErrorResume(throwable -> Flux.just(handleError(history))); // 에러 발생 시 에러 핸들링 -> 재전송 유도
9293
}
9394

94-
// 키워드 추출 메서드
95-
public <T> T keywordExtract(String content, String promptTemplate, Class<T> classType) {
96-
String prompt = promptTemplate + content;
97-
return chatClient.prompt(new Prompt(new UserMessage(prompt)))
98-
.call()
99-
.entity(classType);
100-
}
101-
10295
private ChatResponse ChatResponse(History history, String fullResponse, List<Document> cases, List<Document> laws) {
10396
return ChatResponse.builder()
10497
.roomId(history.getHistoryId())
@@ -161,7 +154,7 @@ private void handlerTasks(ChatRequest chatDto, History history, String fullRespo
161154
}
162155

163156
private void extractAndUpdateKeywordRanks(String message) {
164-
KeywordExtractionDto keywordResponse = keywordExtract(message, keywordExtraction, KeywordExtractionDto.class);
157+
KeywordExtractionDto keywordResponse = keywordService.keywordExtract(message, keywordExtraction, KeywordExtractionDto.class);
165158

166159
KeywordRank keywordRank = keywordRankRepository.findByKeyword(keywordResponse.getKeyword());
167160

@@ -180,7 +173,7 @@ private void extractAndUpdateKeywordRanks(String message) {
180173

181174
private void setHistoryTitle(ChatRequest chatDto, History history, String fullResponse) {
182175
String targetText = fullResponse.contains("해당 질문은 법률") ? chatDto.getMessage() : fullResponse;
183-
TitleExtractionDto titleDto = keywordExtract(targetText, titleExtraction, TitleExtractionDto.class);
176+
TitleExtractionDto titleDto = keywordService.keywordExtract(targetText, titleExtraction, TitleExtractionDto.class);
184177
history.setTitle(titleDto.getTitle());
185178
historyRepository.save(history);
186179
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import com.ai.lawyer.domain.chatbot.entity.KeywordRank;
44
import com.ai.lawyer.domain.chatbot.repository.KeywordRankRepository;
55
import lombok.RequiredArgsConstructor;
6+
import org.springframework.ai.chat.client.ChatClient;
7+
import org.springframework.ai.chat.messages.UserMessage;
8+
import org.springframework.ai.chat.prompt.Prompt;
69
import org.springframework.stereotype.Service;
710

811
import java.util.List;
@@ -11,10 +14,20 @@
1114
@RequiredArgsConstructor
1215
public class KeywordService {
1316

17+
private final ChatClient chatClient;
18+
1419
private final KeywordRankRepository keywordRepository;
1520

1621
public List<KeywordRank> getTop5KeywordRanks() {
1722
return keywordRepository.findTop5ByOrderByScoreDesc();
1823
}
1924

25+
// 키워드 추출 메서드
26+
public <T> T keywordExtract(String content, String promptTemplate, Class<T> classType) {
27+
String prompt = promptTemplate + content;
28+
return chatClient.prompt(new Prompt(new UserMessage(prompt)))
29+
.call()
30+
.entity(classType);
31+
}
32+
2033
}

backend/src/main/resources/system-prompt.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,34 @@ custom:
2626
2727
title-extraction: "다음 문장의 핵심을 요약하여 간결한 제목을 만들어줘: "
2828
keyword-extraction: |
29-
1. 오직 가장 중요하고 대표적인 키워드 **하나**만 추출해야 합니다.
30-
2. 절대로 콤마(,)로 구분된 여러 키워드를 하나의 문자열로 합쳐서 만들면 안 됩니다.
31-
3. 응답은 반드시 아래 JSON 형식에 맞춰 'keywords' 리스트에 **단 하나의 문자열**만 포함해야 합니다.
29+
당신은 키워드 추출기입니다. 반드시 아래 지침을 절대적으로 따라야 합니다.
30+
31+
1. 오직 **가장 중요하고 대표적인 키워드 하나만** 추출해야 합니다.
32+
2. 여러 개의 키워드를 추출하거나, 콤마(,)나 공백으로 구분된 여러 단어를 하나의 문자열로 합치는 것은 금지입니다.
33+
3. 반드시 JSON 형식으로만 답변해야 하며, 'keyword' 리스트에는 문자열이 단 하나만 포함되어야 합니다.
34+
4. 예시 외의 설명, 추가 텍스트, 주석은 절대 출력하지 마세요. JSON만 출력하세요.
3235
3336
---
34-
**예시 1:**
35-
- 입력 문장: 아파트 층간소음 문제로 다투던 중 이웃을 폭행하여 상해를 입혔습니다.
36-
- 올바른 JSON 응답:
37-
{
38-
"keywords": ["폭행"]
39-
}
40-
- 잘못된 JSON 응답:
41-
{
42-
"keywords": ["층간소음, 폭행, 상해"]
43-
}
37+
올바른 예시:
38+
입력: "아파트 층간소음 문제로 다투던 중 이웃을 폭행하여 상해를 입혔습니다."
39+
출력:
40+
[
41+
{
42+
"id": 1,
43+
"keyword": "폭행"
44+
"socre": 1
45+
}
46+
]
47+
48+
잘못된 예시:
49+
[
50+
{
51+
"id": 1,
52+
"keyword": "폭행, 상해, 층간소음, 이웃"
53+
"socre": 1
54+
}
55+
]
4456
---
4557
46-
이제 아래 문장에서 위의 규칙을 엄격히 준수하여 핵심 키워드 **단 하나**를 추출해주세요:
47-
""";
58+
이제 아래 문장에서 규칙을 엄격히 준수하여 JSON만 출력하세요:
59+
"""

0 commit comments

Comments
 (0)