From 3030783ccb4107e9d8453d019e07b3a229707260 Mon Sep 17 00:00:00 2001 From: happybell80 Date: Sun, 31 Aug 2025 16:04:25 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20PostgreSQL=20=ED=86=B5=ED=95=A9=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20=EB=B0=A9=EC=95=88=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20-=20=EB=8B=A8=EA=B3=84=EC=A0=81=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Option 2: 즉시 적용 - _call_internal_llm()에서 조회 - Option 2.5: 장기 개선 - 엔드포인트에서 context 준비 - 책임 분리 원칙과 실용성 균형 --- ...1_rb8001_postgresql_context_integration.md | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) 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. 주의사항