Hausmeister: Filter Recap-Meta-Fragen aus LLM-History (Anti-Poisoning)
This commit is contained in:
parent
7a30793d44
commit
ef33d23158
1 changed files with 21 additions and 2 deletions
|
|
@ -392,13 +392,32 @@ def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None) -
|
||||||
{"role": "system", "content": SYSTEM_PROMPT + memory_block},
|
{"role": "system", "content": SYSTEM_PROMPT + memory_block},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
_RECAP_MARKERS = ["was haben wir", "worüber haben wir", "worüber hatten wir",
|
||||||
|
"worueber haben wir", "was hatten wir besprochen", "was war heute thema"]
|
||||||
|
|
||||||
|
def _is_recap(text):
|
||||||
|
t = text.lower()
|
||||||
|
return any(m in t for m in _RECAP_MARKERS)
|
||||||
|
|
||||||
if session_id:
|
if session_id:
|
||||||
try:
|
try:
|
||||||
import memory_client
|
import memory_client
|
||||||
history = memory_client.get_session_messages(session_id, limit=10)
|
history = memory_client.get_session_messages(session_id, limit=10)
|
||||||
|
skip_next_assistant = False
|
||||||
for msg in history:
|
for msg in history:
|
||||||
if msg.get("role") in ("user", "assistant") and msg.get("content"):
|
role = msg.get("role", "")
|
||||||
messages.append({"role": msg["role"], "content": msg["content"]})
|
content = msg.get("content", "")
|
||||||
|
if not content:
|
||||||
|
continue
|
||||||
|
if role == "user" and _is_recap(content):
|
||||||
|
skip_next_assistant = True
|
||||||
|
continue
|
||||||
|
if role == "assistant" and skip_next_assistant:
|
||||||
|
skip_next_assistant = False
|
||||||
|
continue
|
||||||
|
skip_next_assistant = False
|
||||||
|
if role in ("user", "assistant"):
|
||||||
|
messages.append({"role": role, "content": content})
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue