diff --git a/troubleshooting/20251002_emotion_system_implementation.md b/troubleshooting/20251002_emotion_system_implementation.md index 040326f..61d5ffe 100644 --- a/troubleshooting/20251002_emotion_system_implementation.md +++ b/troubleshooting/20251002_emotion_system_implementation.md @@ -72,17 +72,27 @@ done - rb8001/app/llm/emotion_llm.py (analyze_user_emotion, generate_response_with_emotion) ### 미구현 항목 -- rb8001/app/core/emotion/inference.py (파일 없음) -- ONNX 모델 파일 (없음) -- 토크나이저 초기화 (없음) +- rb8001/app/core/emotion/emotion_classifier.py (rb10508_micro에서 복사 필요) +- ONNX 모델 마운트 (docker-compose.yml 볼륨 설정 없음) - emotion_readings 테이블 (없음) - /v1/emotion/* API 엔드포인트 (없음) +### ONNX 모델 현황 +- **모델 위치** (51124 서버): /home/admin/ivada_project/onnx_models/aihub-7emotions/ +- **모델 파일**: model.onnx (442MB), BERT 기반 7클래스 감정 분류 +- **레이블**: fear, surprise, anger, sadness, neutral, happiness, disgust +- **토크나이저**: vocab.txt, tokenizer.json 포함 +- **학습 코드** (51124): /home/admin/ivada_project/training_emotion/train_korean_emotion.py +- **문제**: rb8001 컨테이너에 볼륨 마운트 안 됨 + ## 데이터 모델 설계 ### emotion_readings 테이블 필수 컬럼: -- user_id (UUID) +- user_id (UUID) - 사용자 감정 +- company_id (UUID) - 회사별 집계용 +- robeing_id (VARCHAR) - 로빙의 감정 상태 (예: 'rb8001') +- emotion_type (VARCHAR) - 'user' | 'robeing' - created_at (TIMESTAMPTZ) - probs (JSONB) - entropy (FLOAT) @@ -95,6 +105,8 @@ done 저장 위치: - robeing_metrics DB (별도 DB 권장) - TimescaleDB 하이퍼테이블 적용 +- 51123 서버에서 CREATE TABLE 및 create_hypertable() 직접 실행 +- 인덱스: (user_id, created_at), (company_id, created_at), (robeing_id, created_at) ### TimescaleDB 참조 - 설치/활성화: DOCS/troubleshooting/250714_system_metrics_implementation.md @@ -119,7 +131,7 @@ done ## 통합 포인트 ### 감정 분석 삽입 -- rb8001/app/llm/emotion_llm.py:25 - inference.py 호출로 대체 +- rb8001/app/llm/emotion_llm.py:25 - emotion_classifier.py 호출로 대체 - rb8001/app/core/emotion/base.py:46, 51 - 실제 분석 로직으로 교체 ### LLM 톤 조절 @@ -127,7 +139,8 @@ done - 감정 기반 프롬프트 조절 로직 추가 ### 저장 계층 -- 신규 DB 클라이언트 (robeing_metrics) +- DB 접근: rb8001/app/state/database.py 활용 또는 신규 emotion DB 클라이언트 파일 생성 +- robeing_metrics DB 연결 (51123 서버에서 CREATE TABLE 직접 실행) - 비동기 저장 큐 고려 ### 권한 @@ -170,12 +183,15 @@ done ## 작업 순서 -1. 추론 모듈 추가: rb8001/app/core/emotion/inference.py -2. EmotionAwareLLM 연결: rb8001/app/llm/emotion_llm.py:25 -3. LLMService 톤 조절: rb8001/app/llm/llm_service.py:133 -4. DB 스키마 준비: robeing_metrics DB (별도) -5. API 라우트 추가: rb8001/main.py -6. 집계 쿼리 구현: time_bucket 기반 +1. Docker 볼륨 마운트: rb8001 docker-compose.yml에 `../onnx_models:/code/onnx_models:ro` 추가 +2. 의존성 추가: rb8001/requirements.txt에 `onnxruntime==1.18.1`, `transformers==4.45.2` 추가 +3. 추론 모듈 복사: rb10508_micro/app/core/emotion/emotion_classifier.py → rb8001/app/core/emotion/ +4. EmotionAwareLLM 연결: rb8001/app/llm/emotion_llm.py:25 +5. LLMService 톤 조절: rb8001/app/llm/llm_service.py:133 +6. DB 스키마 준비: 51123 서버에서 robeing_metrics DB에 emotion_readings 테이블 생성 +7. DB 클라이언트: rb8001/app/state/database.py 활용 또는 신규 파일 생성 +8. API 라우터 생성: rb8001/app/router/emotion_endpoint.py 생성 후 main.py에 include +9. 집계 쿼리 구현: time_bucket 기반 ## 모니터링/성능 @@ -185,6 +201,11 @@ done ### 저장 압력 - TTL/압축은 TimescaleDB 정책으로 설정 +## 개발 원칙 +- 한 파일 최대 500줄 제한 +- 기능별 파일 분리 (라우터, 서비스, 모델) +- main.py는 라우터 include만, 직접 엔드포인트 정의 금지 + ## 리스크/롤백 ### 모델 미가용