Memory: Fallback zeigt Status auch fuer aktive Items (temporaer/permanent)
This commit is contained in:
parent
e091f79f0a
commit
88a7b7f313
1 changed files with 22 additions and 8 deletions
|
|
@ -292,15 +292,15 @@ _STOP_WORDS = {"ich", "bin", "ist", "der", "die", "das", "ein", "eine", "und", "
|
|||
"nicht", "auch", "noch", "schon", "nur", "aber", "wenn", "weil", "dass"}
|
||||
|
||||
|
||||
def _find_matching_candidate(user_text: str, candidates: list[dict]) -> dict | None:
|
||||
"""Findet den Kandidaten mit der besten Wort-Ueberlappung zum User-Text."""
|
||||
def _find_matching_item(user_text: str, items: list[dict]) -> dict | None:
|
||||
"""Findet das Item mit der besten Wort-Ueberlappung zum User-Text."""
|
||||
words = {w.lower().strip(".,!?") for w in user_text.split() if len(w) > 2}
|
||||
words -= _STOP_WORDS
|
||||
if not words:
|
||||
return None
|
||||
|
||||
best, best_score = None, 0
|
||||
for c in candidates:
|
||||
for c in items:
|
||||
content_words = {w.lower().strip(".,!?") for w in c["content"].split() if len(w) > 2}
|
||||
content_words -= _STOP_WORDS
|
||||
if not content_words:
|
||||
|
|
@ -446,14 +446,28 @@ async def handle_message(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
|
|||
sent = True
|
||||
|
||||
if not sent and suggest["type"] is None:
|
||||
matched = _find_matching_candidate(text, memory_client.get_candidates())
|
||||
if matched:
|
||||
log.info("Fallback-Match: Kandidat ID=%s fuer User-Text", matched["id"])
|
||||
matched_cand = _find_matching_item(text, memory_client.get_candidates())
|
||||
if matched_cand:
|
||||
log.info("Fallback-Match: Kandidat ID=%s", matched_cand["id"])
|
||||
await update.message.reply_text(
|
||||
answer[:4000] + "\n\n" + _format_candidate(matched),
|
||||
reply_markup=_memory_buttons(matched["id"]),
|
||||
answer[:4000] + "\n\n" + _format_candidate(matched_cand),
|
||||
reply_markup=_memory_buttons(matched_cand["id"]),
|
||||
)
|
||||
sent = True
|
||||
else:
|
||||
matched_active = _find_matching_item(text, memory_client.get_active_memory())
|
||||
if matched_active:
|
||||
from datetime import datetime as _dt
|
||||
mtype = matched_active.get("memory_type", "")
|
||||
exp = matched_active.get("expires_at")
|
||||
if mtype == "temporary" and exp:
|
||||
status_msg = f"\n\n🕒 Schon temporär gespeichert bis {_dt.fromtimestamp(exp).strftime('%d.%m.%Y')}."
|
||||
elif mtype == "permanent":
|
||||
status_msg = "\n\n📌 Schon dauerhaft gespeichert."
|
||||
else:
|
||||
status_msg = "\n\n✅ Bereits gespeichert."
|
||||
await update.message.reply_text(answer[:3900] + status_msg, reply_markup=KEYBOARD)
|
||||
sent = True
|
||||
|
||||
if not sent:
|
||||
await update.message.reply_text(answer[:4000], reply_markup=KEYBOARD)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue