gbrabbit commited on
Commit
baefff9
ยท
1 Parent(s): f3fcd6f

Auto commit at 26-2025-08 1:05:03

Browse files
lily_llm_api/services/generation_service.py CHANGED
@@ -1157,34 +1157,36 @@ def generate_sync(prompt: str, image_data_list: Optional[List[bytes]], max_lengt
1157
  print(f"๐Ÿ” [DEBUG] ์ „์ฒด ์ฒ˜๋ฆฌ ์™„๋ฃŒ - ์ด ์†Œ์š”์‹œ๊ฐ„: {total_time:.3f}์ดˆ")
1158
 
1159
  # ์ปจํ…์ŠคํŠธ ๋ˆ„์  ์ €์žฅ (์„ธ์…˜/๋ฃธ ๋‹จ์œ„)
1160
- try:
1161
- if use_context and session_id:
1162
- try:
1163
- from lily_llm_core.context_manager import context_manager
1164
- if context_manager:
1165
- # ์‚ฌ์šฉ์ž ๋ฉ”์‹œ์ง€ ์ €์žฅ (์ด๋ฏธ์ง€ ์—ฌ๋ถ€ ๋ฉ”ํƒ€ ํฌํ•จ)
1166
- context_manager.add_user_message(
1167
- prompt,
1168
- metadata={
1169
- "session_id": session_id,
1170
- "room_id": room_id,
1171
- "images_used": bool(all_image_data and len([img for img in all_image_data if img]) > 0),
1172
- "num_images": len([img for img in all_image_data if img]) if all_image_data else 0,
1173
- },
1174
- )
1175
- # ์–ด์‹œ์Šคํ„ดํŠธ ๋ฉ”์‹œ์ง€ ์ €์žฅ
1176
- context_manager.add_assistant_message(
1177
- response,
1178
- metadata={
1179
- "session_id": session_id,
1180
- "room_id": room_id,
1181
- },
1182
- )
1183
- print(f"๐Ÿ” [DEBUG] ์ปจํ…์ŠคํŠธ ์ €์žฅ ์™„๋ฃŒ (์„ธ์…˜: {session_id}, ๋ฃธ: {room_id})")
1184
- except Exception as _ctx_e:
1185
- print(f"โš ๏ธ [DEBUG] ์ปจํ…์ŠคํŠธ ์ €์žฅ ์‹คํŒจ: {_ctx_e}")
1186
- except Exception:
1187
- pass
 
 
1188
 
1189
  return {
1190
  "generated_text": response,
 
1157
  print(f"๐Ÿ” [DEBUG] ์ „์ฒด ์ฒ˜๋ฆฌ ์™„๋ฃŒ - ์ด ์†Œ์š”์‹œ๊ฐ„: {total_time:.3f}์ดˆ")
1158
 
1159
  # ์ปจํ…์ŠคํŠธ ๋ˆ„์  ์ €์žฅ (์„ธ์…˜/๋ฃธ ๋‹จ์œ„)
1160
+ # NOTE: ๋ผ์šฐํ„ฐ(generation_router.py)์—์„œ ์‚ฌ์šฉ์ž/์–ด์‹œ์Šคํ„ดํŠธ ๋ฉ”์‹œ์ง€๋ฅผ ์ €์žฅํ•˜๋ฏ€๋กœ
1161
+ # ์—ฌ๊ธฐ์„œ๋Š” ์ค‘๋ณต ์ €์žฅ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋น„ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค. (์‚ฌ์šฉ์ž ์„ ํ˜ธ์— ๋”ฐ๋ผ ์‚ญ์ œ ๋Œ€์‹  ์ฃผ์„ ์ฒ˜๋ฆฌ)
1162
+ # try:
1163
+ # if use_context and session_id:
1164
+ # try:
1165
+ # from lily_llm_core.context_manager import context_manager
1166
+ # if context_manager:
1167
+ # # ์‚ฌ์šฉ์ž ๋ฉ”์‹œ์ง€ ์ €์žฅ (์ด๋ฏธ์ง€ ์—ฌ๋ถ€ ๋ฉ”ํƒ€ ํฌํ•จ)
1168
+ # context_manager.add_user_message(
1169
+ # prompt,
1170
+ # metadata={
1171
+ # "session_id": session_id,
1172
+ # "room_id": room_id,
1173
+ # "images_used": bool(all_image_data and len([img for img in all_image_data if img]) > 0),
1174
+ # "num_images": len([img for img in all_image_data if img]) if all_image_data else 0,
1175
+ # },
1176
+ # )
1177
+ # # ์–ด์‹œ์Šคํ„ดํŠธ ๋ฉ”์‹œ์ง€ ์ €์žฅ
1178
+ # context_manager.add_assistant_message(
1179
+ # response,
1180
+ # metadata={
1181
+ # "session_id": session_id,
1182
+ # "room_id": room_id,
1183
+ # },
1184
+ # )
1185
+ # print(f"๐Ÿ” [DEBUG] ์ปจํ…์ŠคํŠธ ์ €์žฅ ์™„๋ฃŒ (์„ธ์…˜: {session_id}, ๋ฃธ: {room_id})")
1186
+ # except Exception as _ctx_e:
1187
+ # print(f"โš ๏ธ [DEBUG] ์ปจํ…์ŠคํŠธ ์ €์žฅ ์‹คํŒจ: {_ctx_e}")
1188
+ # except Exception:
1189
+ # pass
1190
 
1191
  return {
1192
  "generated_text": response,
lily_llm_core/context_manager.py CHANGED
@@ -1179,6 +1179,34 @@ class AdvancedContextManager:
1179
  topic_text = ", ".join([topic for topic, freq in top_topics])
1180
  return f"[{len(summaries)}๊ฐœ ํ„ด ์š”์•ฝ] ์ฃผ์š” ์ฃผ์ œ: {topic_text}"
1181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1182
  def _get_summary_context(self, session_id: str) -> str:
1183
  """์š”์•ฝ ์ปจํ…์ŠคํŠธ ๋ฐ˜ํ™˜ - ์‹ค๋ฌด์šฉ"""
1184
  if session_id not in self.turn_summaries:
 
1179
  topic_text = ", ".join([topic for topic, freq in top_topics])
1180
  return f"[{len(summaries)}๊ฐœ ํ„ด ์š”์•ฝ] ์ฃผ์š” ์ฃผ์ œ: {topic_text}"
1181
 
1182
+ # ---- ๊ณต๊ฐœ ํ—ฌํผ: ๋ผ์šฐํ„ฐ์—์„œ ์‚ฌ์šฉํ•  ์š”์•ฝ/ํ‚คํ† ํ”ฝ ์ œ๊ณต ----
1183
+ def get_summary_context(self, session_id: str = "default") -> str:
1184
+ """์ตœ๊ทผ ํ„ด ์š”์•ฝ์„ ํฌํ•จํ•œ ์š”์•ฝ ์ปจํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜."""
1185
+ try:
1186
+ return self._get_summary_context(session_id)
1187
+ except Exception:
1188
+ return ""
1189
+
1190
+ def get_key_topics(self, session_id: str = "default") -> List[str]:
1191
+ """์ตœ๊ทผ ํ„ด๋“ค์˜ ํ‚คํ† ํ”ฝ ์ƒ์œ„ ํ›„๋ณด๋“ค์„ ๋ฐ˜ํ™˜."""
1192
+ try:
1193
+ if session_id not in self.turn_summaries or not self.turn_summaries[session_id]:
1194
+ return []
1195
+ # ์ตœ๊ทผ 10๊ฐœ ํ„ด ์š”์•ฝ์—์„œ ํ† ํ”ฝ ์ˆ˜์ง‘ ํ›„ ๋นˆ๋„์ˆœ ์ •๋ ฌ
1196
+ topics: List[str] = []
1197
+ for ts in self.turn_summaries[session_id][-10:]:
1198
+ if ts and ts.key_topics:
1199
+ topics.extend(ts.key_topics)
1200
+ if not topics:
1201
+ return []
1202
+ freq: Dict[str, int] = {}
1203
+ for t in topics:
1204
+ freq[t] = freq.get(t, 0) + 1
1205
+ sorted_topics = sorted(freq.items(), key=lambda x: x[1], reverse=True)
1206
+ return [t for t, _ in sorted_topics[:5]]
1207
+ except Exception:
1208
+ return []
1209
+
1210
  def _get_summary_context(self, session_id: str) -> str:
1211
  """์š”์•ฝ ์ปจํ…์ŠคํŠธ ๋ฐ˜ํ™˜ - ์‹ค๋ฌด์šฉ"""
1212
  if session_id not in self.turn_summaries: