refactor(xxm): use [YOU] prefix for TUI context (align with Hermes)
This commit is contained in:
@@ -393,6 +393,19 @@ class SessionBridge:
|
|||||||
except Exception:
|
except Exception:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def _format_tui_context(self, raw_ctx: str) -> str:
|
||||||
|
"""Mark bot's own TUI messages with [YOU] so LLM recognises itself."""
|
||||||
|
lines = []
|
||||||
|
for line in raw_ctx.split("\n"):
|
||||||
|
line = line.strip()
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
if "小小莫" in line:
|
||||||
|
lines.append(f"[YOU] {line}")
|
||||||
|
else:
|
||||||
|
lines.append(line)
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
def _append_to_log(self, role: str, content: str, source: str = "bridge"):
|
def _append_to_log(self, role: str, content: str, source: str = "bridge"):
|
||||||
try:
|
try:
|
||||||
entry = json.dumps(
|
entry = json.dumps(
|
||||||
@@ -693,12 +706,7 @@ class SessionBridge:
|
|||||||
from session_router import extract_session_context
|
from session_router import extract_session_context
|
||||||
tui_ctx = extract_session_context(tui_sid, limit=50)
|
tui_ctx = extract_session_context(tui_sid, limit=50)
|
||||||
if tui_ctx:
|
if tui_ctx:
|
||||||
sys_prompt += (
|
sys_prompt += f"\n\n{self._format_tui_context(tui_ctx)}"
|
||||||
"\n\n【你的 TUI 工作台最近对话】"
|
|
||||||
f"\n(老莫在 TUI 和你讨论这些时,转发了群聊消息,"
|
|
||||||
f"请结合下面的 TUI 对话理解他在群里的意图。"
|
|
||||||
f"群聊和 TUI 是同一个人,两份上下文关联看)\n{tui_ctx}"
|
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user