Fix: AI summary language synchronization and bug documentation

This commit is contained in:
leeyj
2026-04-18 02:39:57 +09:00
parent cf6ab74cec
commit fc00b22b42
4 changed files with 46 additions and 10 deletions
+10 -6
View File
@@ -26,7 +26,9 @@ def analyze_memo(title, content, lang='en'):
if lang == 'ko': if lang == 'ko':
prompt = f""" prompt = f"""
은 메모 분석 전문가입니다. 아래 메모의 제목과 내용을 읽고 다음 작업을 수행하세요: 은 메모 분석 전문가입니다. 아래 메모의 제목과 내용을 읽고 다음 작업을 수행하세요.
**반드시 모든 응답(요약 및 태그)은 한국어로 작성해야 합니다.**
1. 내용을 1~2문장으로 아주 간결하게 요약할 것. 1. 내용을 1~2문장으로 아주 간결하게 요약할 것.
2. 내용과 관련된 핵심 키워드를 태그 형태로 3~5개 추출할 것. 2. 내용과 관련된 핵심 키워드를 태그 형태로 3~5개 추출할 것.
@@ -35,13 +37,15 @@ def analyze_memo(title, content, lang='en'):
출력 형식(JSON): 출력 형식(JSON):
{{ {{
"summary": "요약 내용", "summary": "한국어 요약 내용",
"tags": ["태그1", "태그2", "태그3"] "tags": ["한국어태그1", "한국어태그2", "한국어태그3"]
}} }}
""" """
else: else:
prompt = f""" prompt = f"""
You are a memo analysis expert. Read the title and content below and perform the following: You are a memo analysis expert. Read the title and content below and perform the following.
**All responses (summary and tags) must be in English.**
1. Summarize the content very concisely in 1-2 sentences. 1. Summarize the content very concisely in 1-2 sentences.
2. Extract 3-5 key keywords as tags. 2. Extract 3-5 key keywords as tags.
@@ -50,8 +54,8 @@ def analyze_memo(title, content, lang='en'):
Output Format (JSON): Output Format (JSON):
{{ {{
"summary": "Summary text", "summary": "English summary text",
"tags": ["Tag1", "Tag2", "Tag3"] "tags": ["EnglishTag1", "EnglishTag2", "EnglishTag3"]
}} }}
""" """
+5 -3
View File
@@ -15,15 +15,17 @@ def analyze_memo_route(memo_id):
c.execute('SELECT title, content, is_encrypted FROM memos WHERE id = ?', (memo_id,)) c.execute('SELECT title, content, is_encrypted FROM memos WHERE id = ?', (memo_id,))
memo = c.fetchone() memo = c.fetchone()
lang = request.args.get('lang', 'ko')
if not memo: if not memo:
return jsonify({'error': _t('label_no_results')}), 404 return jsonify({'error': _t('label_no_results', lang=lang)}), 404
if memo['is_encrypted']: if memo['is_encrypted']:
return jsonify({'error': _t('msg_encrypted_locked')}), 403 return jsonify({'error': _t('msg_encrypted_locked', lang=lang)}), 403
current_app.logger.info(f"AI Analysis Started: ID {memo_id}, Title: '{memo['title']}'") current_app.logger.info(f"AI Analysis Started: ID {memo_id}, Title: '{memo['title']}'")
lang = current_app.config.get('lang', 'en') # 💡 쿼리 파라미터에서 현재 언어 설정을 가져옵니다. (기본값 ko)
lang = request.args.get('lang', 'ko')
summary, ai_tags = analyze_memo(memo['title'], memo['content'], lang=lang) summary, ai_tags = analyze_memo(memo['title'], memo['content'], lang=lang)
try: try:
@@ -0,0 +1,27 @@
# 버그 조치 보고서: AI 요약 언어 불일치 (2026-04-18)
## 1. 버그 내용
- **현상**: 사용자가 UI 언어를 한국어로 설정했음에도 불구하고, AI 분석(요약 및 태그 추출) 결과가 영문으로 출력됨.
- **원인**:
- 백엔드(`/api/memos/<id>/analyze`)에서 언어 설정을 서버 전역 설정(`app.config['lang']`)에만 의존함.
- 사용자가 UI에서 언어를 변경해도 이 변경사항이 서버 구성에 실시간으로 반영되지 않아 기본값인 'en'으로 동작함.
## 2. 조치 사항
### 프론트엔드 수정 (`static/js/api.js`)
- `API.triggerAI(id)` 함수에서 `I18nManager.currentLang`을 확인하여 요청 쿼리 파라미터에 `lang`을 추가함.
- 예: `POST /api/memos/123/analyze?lang=ko`
### 백엔드 라우트 수정 (`app/routes/ai.py`)
- `analyze_memo_route`에서 `request.args.get('lang')`을 통해 클라이언트의 현재 언어 설정을 수신하도록 변경.
- 수신된 `lang` 정보를 기반으로 AI 분석 엔진에 언어 지침을 전달함.
- 에러 메시지 또한 `_t(key, lang=lang)`을 사용하여 적절한 언어로 반환되도록 개선.
### AI 엔진 프롬프트 최적화 (`app/ai.py`)
- 한국어(`ko`) 요청 시 **"반드시 모든 응답은 한국어로 작성해야 합니다"**라는 명시적 지침을 프롬프트에 추가하여 모델의 출력 언어를 강제함.
## 3. 결과 및 확인
- UI 언어 설정에 따라 AI의 요약 결과가 정확히 해당 언어로 생성됨을 확인.
- 만약 언어 정보가 전달되지 않을 경우 한국어('ko')를 기본값으로 사용하도록 폴백 로직 적용.
## 4. 향후 주의사항
- 새로운 AI 기능(전체 요약, 추천 시스템 등) 추가 시에도 클라이언트의 `lang` 파라미터를 반드시 연동할 것.
+4 -1
View File
@@ -2,6 +2,8 @@
* 백엔드 API와의 통신을 관리하는 모듈 * 백엔드 API와의 통신을 관리하는 모듈
*/ */
import { I18nManager } from './utils/I18nManager.js';
export const API = { export const API = {
async request(url, options = {}) { async request(url, options = {}) {
const res = await fetch(url, options); const res = await fetch(url, options);
@@ -61,7 +63,8 @@ export const API = {
}, },
async triggerAI(id) { async triggerAI(id) {
return await this.request(`/api/memos/${id}/analyze`, { method: 'POST' }); const lang = I18nManager.currentLang || 'ko';
return await this.request(`/api/memos/${id}/analyze?lang=${lang}`, { method: 'POST' });
}, },
async fetchAssets() { async fetchAssets() {