Skip to content

Commit

Permalink
feat :: regenerate status send on chat
Browse files Browse the repository at this point in the history
  • Loading branch information
jombidev committed Oct 22, 2024
1 parent fcd9996 commit 1c91036
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/com/teamapi/palette/entity/chat/Chat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data class Chat(
val roomId: Long,
val userId: Long,
val isAi: Boolean,

val regenScope: Boolean = false,
@Contextual
val promptId: ObjectId? = null
) {
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/teamapi/palette/response/ErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum class ErrorCode(

CHAT_FILTERED(HttpStatus.BAD_REQUEST, "부적절한 내용 감지. 내용을 수정 해 주세요."),
MESSAGE_TYPE_NOT_MATCH(HttpStatus.BAD_REQUEST, "적절하지 않은 메시지 유형: '%s'. 메시지 유형 '%s'이(가) 필요합니다."),
QNA_INVALID_NOT_FULFILLED(HttpStatus.BAD_REQUEST, "모든 질문에 대해 대답하지 않았거나, 요청을 받을 수 없는 상태입니다."),
QNA_INVALID_FULFILLED(HttpStatus.BAD_REQUEST, "이미 모든 질문에 대해 대답하였습니다."),
QNA_INVALID_CHOICES(HttpStatus.BAD_REQUEST, "적절하지 않은 선택: '%s'. %s 선택지 중 하나가 필요합니다."),
QNA_INVALID_GRID_CHOICES(HttpStatus.BAD_REQUEST, "적절하지 않은 그리드: (%s). 0~%d 선택지 중 하나가 필요합니다."),
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/com/teamapi/palette/service/RoomService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,15 @@ class RoomService(
val room = roomRepository.findById(roomId) ?: throw CustomException(ErrorCode.ROOM_NOT_FOUND)
room.validateUser(sessionHolder)

val regenScope = chatRepository.getLatestChatByRoomId(roomId)?.regenScope == true

val me = sessionHolder.me()
val qna = qnaRepository.getQnAByRoomId(roomId)!!

if (qna.qna.any { it.answer == null } || !regenScope) {
throw CustomException(ErrorCode.QNA_INVALID_NOT_FULFILLED)
}

chatEmitAdapter.emitChat(
Chat(
resource = ChatState.CHAT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,33 +93,35 @@ class GenerativeImageService(
e.printStackTrace()
guaranteed = null
}
if (guaranteed == null) {
chatEmitAdapter.emitChat(
Chat(
resource = ChatState.CHAT,
roomId = room.id!!,
userId = me,
isAi = true,
message = "이미지를 생성하는 도중 오류가 발생하였어요. ;.;"
if (guaranteed != null) {
try {
val uploaded = blobSaveAdapter.save(Base64.decode(guaranteed!!))

chatEmitAdapter.emitChat(
Chat(
resource = ChatState.IMAGE,
roomId = room.id!!,
userId = me,
isAi = true,
message = uploaded.blobUrl,
regenScope = true
)
)
)
return
return
} catch (e: Exception) {
e.printStackTrace()
}
}

try {
val uploaded = blobSaveAdapter.save(Base64.decode(guaranteed!!))

chatEmitAdapter.emitChat(
Chat(
resource = ChatState.IMAGE,
roomId = room.id!!,
userId = me,
isAi = true,
message = uploaded.blobUrl
)
chatEmitAdapter.emitChat(
Chat(
resource = ChatState.CHAT,
roomId = room.id!!,
userId = me,
isAi = true,
message = "이미지를 생성하는 도중 오류가 발생하였어요. ;.;",
regenScope = true
)
} catch (e: Exception) {
e.printStackTrace()
}
)
}
}

0 comments on commit 1c91036

Please sign in to comment.