Skip to content

Commit eea34fa

Browse files
author
yuhojae
committed
feat : 가상친구 대화 온도 로직 변경
1 parent 9cb60ff commit eea34fa

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

api/src/main/java/com/mbtips/common/exception/handler/GlobalExceptionHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public ApiResponse<Void> exceptionsHandler(MethodArgumentNotValidException e) {
5050
return ApiResponse.fail(CommonException.INVALID_REQUEST_ERROR);
5151
}
5252

53-
/**
54-
* VirtualFriendNotFoundException 구현 변경
55-
*/
53+
5654

5755
}

api/src/main/java/com/mbtips/domain/addition/service/AdditionService.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.mbtips.domain.addition.service;
22

33
import com.mbtips.clova.dto.Message;
4+
import com.mbtips.common.exception.CustomException;
5+
import com.mbtips.common.exception.enums.CommonException;
46
import com.mbtips.common.mbtiinfo.MbtiTraits;
57
import com.mbtips.common.mbtiinfo.MbtiType;
68
import com.mbtips.domain.conversation.service.ConversationService;
@@ -39,17 +41,25 @@ public String requestConversationTips(Long virtualFriendId) {
3941
}
4042

4143
public String requestTemperature(Long conversationId) {
42-
Conversation conversation = conversationService.findById(conversationId);
44+
4345
List<GetMessageResponseDto> messages = messageService.getMessagesOfConversationId(conversationId);
4446

45-
String[] messageList = {
46-
"사용자: 안녕하세요, 오늘 기분이 어떠세요?",
47-
"AI: 안녕하세요, 오늘 기분이 활기차고 즐거워요.",
48-
"사용자: 오늘 특별한 계획이 있으세요?",
49-
"AI: 네, 친구와 함께 신나는 시간을 보낼 예정입니다."
50-
};
51-
String requestConversation = String.join(", ", messageList);
52-
String prompt = requestConversation + "현재까지의 대화 온도 측정해서 0~100 사이의 숫자로만 대답해줘 냉정하게 판단해주고, 숫자로만 대답해.";
47+
StringBuilder messageBuilder = new StringBuilder();
48+
49+
if(messages.size() <= 5) throw new CustomException(CommonException.TOO_FEW_CONVERSATIONS);
50+
for(int i = messages.size() - 6; i < messages.size(); i++){
51+
if(messages.get(i).userId() != null) {
52+
messageBuilder.append("사용자 : ");
53+
messageBuilder.append(messages.get(i).messageContent());
54+
}
55+
if(messages.get(i).virtualFriendId() != null) {
56+
messageBuilder.append("가상 친구 : ");
57+
messageBuilder.append(messages.get(i).messageContent());
58+
}
59+
if(i != messages.size() -1 ) messageBuilder.append(", ");
60+
}
61+
log.debug("대화 내역 : {}", messageBuilder.toString());
62+
String prompt = messageBuilder + "현재까지의 대화 온도 측정해서 0~100 사이의 숫자로만 대답해줘 냉정하게 판단해주고, 숫자로만 대답해.";
5363
log.debug("prompt : {}", prompt);
5464
String temperatureResponse = messageManager.messageRequest(prompt);
5565
String result = temperatureResponse.replaceAll("[^0-9]", "");

core/src/main/java/com/mbtips/common/exception/enums/CommonException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public enum CommonException implements ExceptionInterface {
99
INVALID_REQUEST_ERROR(400, "잘못된 요청입니다."),
1010
LOGIN_EXPIRATION(403, "로그인이 만료되었습니다."),
1111
INTERNAL_SERVER_ERROR(500, "서버 오류입니다."),
12-
JSON_PROCESS_ERROR(501, "JSON 변형 도중 오류가 발생했습니다.")
13-
12+
JSON_PROCESS_ERROR(501, "JSON 변형 도중 오류가 발생했습니다."),
13+
TOO_FEW_CONVERSATIONS(40001, "대화의 개수가 부족합니다.(5회 이상)")
1414
;
1515

1616
private final int code;

0 commit comments

Comments
 (0)