@@ -20,13 +20,26 @@ const transformStyleController = async (req, res, next) => {
2020 console . log ( '🟣 AI Style 요청 받음:' , req . body ) ;
2121
2222 // 검증된 데이터 추출 (미들웨어에서 이미 검증 완료)
23- const { words, endingCards, refresh = false } = req . body ;
23+ const { words, endingCards, tone , refresh = false } = req . body ;
2424 const userId = req . user ?. userId ; // 인증된 사용자 ID (학습 데이터 가중치 적용용)
2525
26+ // tone 우선 + endingCards 합성 정규화
27+ let normalizedEndingCards = Array . isArray ( endingCards ) ? [ ...endingCards ] : [ ] ;
28+
29+ if ( tone ) {
30+ // endingCards 안에 존댓말/반말이 들어와도 tone이 우선이므로 제거
31+ normalizedEndingCards = normalizedEndingCards . filter (
32+ ( card ) => card !== '존댓말' && card !== '반말'
33+ ) ;
34+
35+ const toneCard = tone === 'HONORIFIC' ? '존댓말' : '반말' ;
36+ normalizedEndingCards . unshift ( toneCard ) ;
37+ }
38+
2639 // 캐시 조회 (refresh가 false일 때만)
27- if ( ! refresh && words . length > 0 && endingCards . length > 0 ) {
40+ if ( ! refresh && words . length > 0 && normalizedEndingCards . length > 0 ) {
2841 const cacheContext = { previousMessages : [ ] } ;
29- const cacheKey = generateCacheKey ( words , cacheContext , 'styles' , endingCards ) ;
42+ const cacheKey = generateCacheKey ( words , cacheContext , 'styles' , normalizedEndingCards ) ;
3043 const cached = await getFromCache ( cacheKey ) ;
3144
3245 if ( cached ?. sentences ) {
@@ -54,12 +67,12 @@ const transformStyleController = async (req, res, next) => {
5467
5568 // AI 문장 추천 호출 (userId 전달하여 학습 데이터 가중치 적용)
5669 console . log ( '🤖 FastAPI 호출:' , { words, endingCards, refresh, userId } ) ;
57- const result = await transformSentenceStyle ( words , endingCards , refresh , userId ) ;
70+ const result = await transformSentenceStyle ( words , normalizedEndingCards , refresh , userId ) ;
5871
5972 // 캐시 저장 (원본 sentences만 저장, 사용자별 가중치 미적용)
60- if ( words . length > 0 && endingCards . length > 0 ) {
73+ if ( words . length > 0 && normalizedEndingCards . length > 0 ) {
6174 const cacheContext = { previousMessages : [ ] } ;
62- const cacheKey = generateCacheKey ( words , cacheContext , 'styles' , endingCards ) ;
75+ const cacheKey = generateCacheKey ( words , cacheContext , 'styles' , normalizedEndingCards ) ;
6376 await saveToCache ( cacheKey , {
6477 words : result . words ,
6578 endingCards : result . endingCards ,
0 commit comments