diff --git a/plans/250831_rb8001_postgresql_context_integration.md b/plans/250831_rb8001_postgresql_context_integration.md index b6ce98f..caab5a6 100644 --- a/plans/250831_rb8001_postgresql_context_integration.md +++ b/plans/250831_rb8001_postgresql_context_integration.md @@ -35,14 +35,25 @@ - 함수명: `get_recent_conversations(user_id, limit=10)` - 쿼리: `SELECT message, response, timestamp FROM conversation_logs WHERE user_id = %s ORDER BY timestamp DESC` -### 3.2 해결 방안 (2가지 중 선택) -- **방안 1**: main.py 엔드포인트들이 `router.handle_message()` 호출하도록 변경 - - 장점: 한 곳에서 최근 대화 조회 관리 - - 단점: 큰 구조 변경 필요 -- **방안 2**: 각 엔드포인트(`/api/message`, `/api/slack/events`)에서 직접 최근 대화 조회 - - 장점: 기존 구조 유지 - - 단점: 중복 코드 발생 -- **gemini_handler.py**: 어느 방안이든 context['recent_conversations'] 활용 필요 +### 3.2 해결 방안 (단계적 접근) +- **즉시 적용 (Option 2)**: `_call_internal_llm()` 내부에서 최근 대화 조회 + ```python + # router.py _call_internal_llm() 내부 + if not context.get("recent_conversations"): + context["recent_conversations"] = await get_recent_conversations(user_id) + ``` + - 장점: 한 곳 수정으로 모든 경로 해결 + - 단점: 책임 분리 원칙 위반 + +- **장기 개선 (Option 2.5)**: main.py 엔드포인트에서 context 준비 후 전달 + ```python + # main.py 각 엔드포인트 + recent_conversations = await get_recent_conversations(user_id) + context = {"recent_conversations": recent_conversations} + await router._call_internal_llm(..., context=context) + ``` + - 장점: 깔끔한 책임 분리, 기존 context 파라미터 활용 + - TODO 주석 추가: "리팩토링 - context는 호출하는 쪽에서 준비" ## 4. 주의사항