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:
|