Spaces:
Sleeping
Sleeping
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 |
-
|
| 1161 |
-
|
| 1162 |
-
|
| 1163 |
-
|
| 1164 |
-
|
| 1165 |
-
|
| 1166 |
-
|
| 1167 |
-
|
| 1168 |
-
|
| 1169 |
-
|
| 1170 |
-
|
| 1171 |
-
|
| 1172 |
-
|
| 1173 |
-
|
| 1174 |
-
|
| 1175 |
-
|
| 1176 |
-
|
| 1177 |
-
|
| 1178 |
-
|
| 1179 |
-
|
| 1180 |
-
|
| 1181 |
-
|
| 1182 |
-
|
| 1183 |
-
|
| 1184 |
-
|
| 1185 |
-
|
| 1186 |
-
except Exception:
|
| 1187 |
-
|
|
|
|
|
|
|
| 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:
|