Optimisation performance (30t/s --> 50t/s) & adaptation parsing json --> llama.cpp & Fix système mémoire
This commit is contained in:
parent
e27b60e60c
commit
0ba47f8363
19 changed files with 457 additions and 123 deletions
|
|
@ -408,6 +408,41 @@ async def build_context_for_model(
|
|||
return joined
|
||||
|
||||
|
||||
async def get_structured_history(
|
||||
user_id: int | str,
|
||||
max_recent: int = 12,
|
||||
guild_id: str | None = None,
|
||||
) -> tuple[str, List[Dict[str, str]]]:
|
||||
"""Retourne le résumé global et l'historique structuré (utile pour l'API Chat)."""
|
||||
data = await load_user_memory_async(user_id, guild_id)
|
||||
resume = data.get("resume_global", "")
|
||||
|
||||
recent = data.get("historique_recent", [])
|
||||
recent_tail = recent[-max_recent:] if recent else []
|
||||
|
||||
structured = []
|
||||
import datetime
|
||||
for m in recent_tail:
|
||||
um = m.get("user_message", "").strip()
|
||||
bm = m.get("bot_message", "").strip()
|
||||
ts = m.get("timestamp")
|
||||
|
||||
time_prefix = ""
|
||||
if ts:
|
||||
try:
|
||||
time_str = datetime.datetime.fromtimestamp(float(ts)).strftime("%H:%M:%S")
|
||||
time_prefix = f"[{time_str}] "
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
if um:
|
||||
structured.append({"role": "user", "content": f"{time_prefix}{um}"})
|
||||
if bm:
|
||||
structured.append({"role": "assistant", "content": f"{time_prefix}{bm}"})
|
||||
|
||||
return resume, structured
|
||||
|
||||
|
||||
async def purge_old_memories(days: int = 30) -> int:
|
||||
"""
|
||||
Supprime les fichiers de mémoire plus vieux que X jours pour conformité RGPD.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue