feat: 대화 컨텍스트 압축본 전송 및 채팅 메시지·대댓글 연동 - #14
Draft
soyeonLee126 wants to merge 19 commits into
Draft
Conversation
…ging # Conflicts: # .github/workflows/ci.yml # data/build.gradle.kts # data/src/main/java/com/gamss/android/data/di/NetworkModule.kt # data/src/main/java/com/gamss/android/data/di/RepositoryModule.kt # domain/build.gradle.kts # domain/src/main/kotlin/com/gamss/android/domain/card/GenerateCardInputUseCase.kt # domain/src/main/kotlin/com/gamss/android/domain/emotion/ClassifyUserEmotionUseCase.kt # domain/src/main/kotlin/com/gamss/android/domain/summary/SummarizeDiaryUseCase.kt
서버 error.code 가 보존되어 이미 종료된 방과 이미 만들어진 카드를 HTTP 상태 대신 코드로 구분한다.
feature/chat-card 브랜치에 보존했다. 이 브랜치는 메시지 전송과 컨텍스트 압축본 전송에 집중한다.
압축본 = 첫 발화 원문 + 확정 청크 요약들 + 최근 3턴 원문. 청크는 512 토큰을 채울 때 한 번만 요약하고 캐시해 같은 텍스트를 다시 요약하지 않는다. 토큰 측정은 절단 없는 토크나이저를 따로 쓴다.
요약기 입력 한계(512 토큰)를 넘긴 뒤 요약해 청크마다 마지막 발화가 절단되던 문제를 넘기기 전에 확정하도록 바꿨다. 요약이 실패하면 청크를 원문으로 확정해 재시도가 누적되지 않게 했고, 상한 초과 시 첫 발화와 최근 발화를 남기고 오래된 청크부터 버린다. 압축 실패가 전송·조회를 막지 않도록 요약·토큰 계산 실패를 격리하고 취소만 다시 던진다. orbit intent 가 네트워크 응답 스레드에서 재개되므로 상태 변이를 Mutex 로 직렬화하고, 온디바이스 요약이 화면 갱신을 막지 않게 압축 갱신을 reduce 뒤로 옮겼다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
작업 개요
대화가 길어져도 서버가 캐릭터 답장을 만들 수 있도록, 클라이언트가 대화 컨텍스트 압축본을 만들어
메시지 전송에 함께 보낸다. 이 PR의 목적은 그 압축본(
currentConversationSummary) 전송을 실제로태워 보는 것이고, 압축본을 만들려면 대화 자체가 필요해서 채팅 전송·대댓글 경로도 함께 들어 있다.
압축본은 서버에 저장되지 않고 답장 생성 컨텍스트로만 쓰인다. 상한은 2000자다.
압축 전략은 다음과 같다.
대화 종료와 감정 카드 생성은 diff가 커져서 별도 PR로 분리했다(
feature/chat-card).작업 유형
변경 사항
압축본 (이 PR의 핵심)
ConversationSummaryStore: 대화가 진행되는 동안 압축본을 증분으로 만든다. 청크 요약을 캐시해 같은 텍스트를 두 번 요약하지 않는다UtteranceTokenCounter포트와KobartTokenCounter구현: 청크 경계를 재려면 절단 없는 토크나이저가 필요해 요약용 인스턴스와 별도로 둔다SaveMessageRequest.currentConversationSummary추가.encodeDefaults = false라 없으면 필드가 아예 빠진다(conversationId생략 = 새 채팅방)채팅 전송·대댓글
POST /api/conversations/messages,GET /api/conversations/{id}/messages연동ConversationRepository,SendMessageUseCase,GetMessagesUseCase)과 채팅방 화면(Orbit MVI)debug 전용 게이팅
:feature:chat을debugImplementation으로 두고src/debug·src/release에 같은 이름의 진입점을 둬서 release 소스셋에는 화면이 아예 포함되지 않는다기타
local.properties에DEV_BASE_URL/PROD_BASE_URL이 없으면 빌드를 실패시킨다AppResult.of가 코루틴 취소를 삼키던 문제 수정관련 이슈
관련 작업 (Notion)
스크린샷 / 동작 화면
체크리스트
develop으로 설정되어 있다feat:,fix:등)을 따른다테스트
단위 테스트 70개 통과, detekt 통과.
실기기(SM-S911N) 검증. 새 방에서 3번 전송하며 요청 본문을 그대로 확인했다.
{"content":"today was rough at work"}{"content":"...","conversationId":33,"currentConversationSummary":"today was rough at work"}{"content":"...","conversationId":33,"currentConversationSummary":"today was rough at work the team lead dumped extra work on me"}conversationId와 압축본이 본문에서 빠지고, 2차부터 압축본이 누적된다리뷰 요청 사항
압축 전략을 중점적으로 봐주면 좋겠다.
아직 확인이 필요한 것