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: