Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

116 feat chat logic 2 #118

Merged
merged 3 commits into from
Oct 16, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import javax.validation.Valid;

import static seoultech.capstone.menjil.global.exception.ErrorIntValue.INTERNAL_SERVER_ERROR;
import static seoultech.capstone.menjil.global.exception.ErrorIntValue.TIME_INPUT_INVALID;

@Slf4j
Expand Down Expand Up @@ -52,10 +51,11 @@ public void enter(@DestinationVariable("roomId") String roomId,
handleClientQuestion(roomId, messageRequest);
break;
case AI_SELECT:
case AI_SUMMARY:
case AI_SUMMARY_ANSWER:
// 2. Send Client's Chat Message
sendSuccessResponse(roomId, SuccessCode.MESSAGE_SEND_SUCCESS, (MessageResponse) result);
break;
case AI_ANSWER:

default:
sendMessageTypeErrorResponse(roomId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
public Object saveAndSendClientChatMessage(MessageRequest messageRequest) {
// MessageRequest의 time format 검증
Optional<LocalDateTime> dateTimeOptional = parseDateTime(messageRequest.getTime());

if (dateTimeOptional.isEmpty()) {
return TIME_INPUT_INVALID.getValue(); // or handle the error differently
}
Expand All @@ -79,6 +78,7 @@
return MessageResponse.fromChatMessageEntity(clientChatMessage);
}

// TODO: 추후 사용되지 않으면 지울 것
public int saveChatMessage(MessageRequest messageRequest) {
// MessageRequest time format 검증
Optional<LocalDateTime> dateTimeOptional = parseDateTime(messageRequest.getTime());
Expand All @@ -102,6 +102,7 @@
return SUCCESS.getValue();
}

// TODO: 추후 사용되지 않으면 지울 것
public MessageResponse sendClientMessage(MessageRequest messageRequest) {
Optional<LocalDateTime> dateTimeOptional = parseDateTime(messageRequest.getTime());

Expand Down Expand Up @@ -249,14 +250,32 @@
List<AwsLambdaResponse> awsLambdaResponses) {
String awsMessage = "먼저, " + messageRequest.getSenderNickname()
+ "님의 질문과 유사한 질문에서 시작된 대화를 살펴 보실래요?\n"
+ "더 신속하게, 다양한 해답을 얻을 수 있을거에요";

+ "더 신속하게, 다양한 해답을 얻을 수 있을거에요!\n"
+ messageRequest.getSenderNickname() + "님이 입력한 질문과 유사한 질문의 개수는 " + awsLambdaResponses.size() +

Check warning on line 254 in src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java#L254

Added line #L254 was not covered by tests
"개 입니다.";
String message4th = "AI 챗봇을 종료하고 멘토 답변 기다리기";

LocalDateTime now = getCurrentTimeWithNanos();

if (awsLambdaResponses.size() == 0) {
awsLambdaResponses.add(AwsLambdaResponse.of(null,
messageRequest.getSenderNickname()

Check warning on line 261 in src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java#L260-L261

Added lines #L260 - L261 were not covered by tests
+ "님의 질문과 유사도가 높은 대화 목록이 존재하지 않습니다", null, null));
awsLambdaResponses.add(AwsLambdaResponse.of(null,

Check warning on line 263 in src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java#L263

Added line #L263 was not covered by tests
null, null, null));
awsLambdaResponses.add(AwsLambdaResponse.of(null,

Check warning on line 265 in src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java#L265

Added line #L265 was not covered by tests
null, null, null));
} else if (awsLambdaResponses.size() == 1) {
awsLambdaResponses.add(AwsLambdaResponse.of(null,

Check warning on line 268 in src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java#L268

Added line #L268 was not covered by tests
null, null, null));
awsLambdaResponses.add(AwsLambdaResponse.of(null,

Check warning on line 270 in src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java#L270

Added line #L270 was not covered by tests
null, null, null));
} else if (awsLambdaResponses.size() == 2) {
awsLambdaResponses.add(AwsLambdaResponse.of(null,

Check warning on line 273 in src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java#L273

Added line #L273 was not covered by tests
null, null, null));
}
// 아래는 공통
// add 4th response
awsLambdaResponses.add(AwsLambdaResponse.of(
awsLambdaResponses.add(AwsLambdaResponse.of(null,

Check warning on line 278 in src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seoultech/capstone/menjil/domain/chat/application/MessageService.java#L278

Added line #L278 was not covered by tests
message4th, null, null));

ChatMessage awsLambdaResponseMessage = ChatMessage.builder()
Expand All @@ -270,15 +289,15 @@
.build();

// TODO: 추후 디자인에 따라 이 부분 변동 가능성 있음.
if (similarMessageDoesNotExists(awsLambdaResponses)) {
/*String similarDoesNotExists = messageRequest.getSenderNickname()
/*if (similarMessageDoesNotExists(awsLambdaResponses)) {
*//*String similarDoesNotExists = messageRequest.getSenderNickname()
+ "님의 질문과 유사도가 높은 대화 목록이 존재하지 않습니다";
awsLambdaResponseMessage.setLambdaMessage(similarDoesNotExists);*/
awsLambdaResponseMessage.setLambdaMessageList(AwsLambdaResponse.of(
awsLambdaResponseMessage.setLambdaMessage(similarDoesNotExists);*//*
awsLambdaResponseMessage.setLambdaMessageList(AwsLambdaResponse.of(null,
messageRequest.getSenderNickname()
+ "님의 질문과 유사도가 높은 대화 목록이 존재하지 않습니다", null, null)
);
}
}*/
return awsLambdaResponseMessage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum MessageType {
*/
ENTER,
C_QUESTION,
AI_QUESTION_RESPONSE, AI_SUMMARY_LIST, AI_SELECT, AI_ANSWER,
AI_QUESTION_RESPONSE, AI_SUMMARY_LIST, AI_SELECT, AI_SUMMARY, AI_SUMMARY_ANSWER,
TALK,
TYPE_NOT_EXISTS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
@NoArgsConstructor
@AllArgsConstructor
public class AwsLambdaResponse {

@JsonProperty(value = "question_id")
private String question_id; // use underbar because mongodb saved type and return value is different

@JsonProperty(value = "question_summary")
private String question_summary; // use underbar because mongodb saved type and return value is different

Expand All @@ -18,7 +22,8 @@ public class AwsLambdaResponse {
@JsonProperty(value = "similarity_percent")
private Double similarity_percent; // use underbar because mongodb saved type and return value is different

public static AwsLambdaResponse of(String question_summary, String answer, Double similarity_percent) {
return new AwsLambdaResponse(question_summary, answer, similarity_percent);
public static AwsLambdaResponse of(String question_id, String question_summary,
String answer, Double similarity_percent) {
return new AwsLambdaResponse(question_id, question_summary, answer, similarity_percent);
}
}