perf(emotion-e1): keep expression context out of system prompt
这个提交存在于:
父节点
05a200be8e
当前提交
80ab1764f1
共有 3 个文件被更改,包括 72 次插入 和 3 次删除
14
main.py
14
main.py
|
|
@ -6484,9 +6484,10 @@ wakeup_type={_single_line(wakeup.get('type'), 40)} score={_single_line(wakeup.ge
|
|||
*,
|
||||
priority: int = 50,
|
||||
source: str = "",
|
||||
force_dynamic: bool = False,
|
||||
) -> bool:
|
||||
position = self._normalize_passive_injection_position(getattr(self, "passive_injection_position", "prompt"))
|
||||
if position == "system_prompt":
|
||||
if position == "system_prompt" and not force_dynamic:
|
||||
return False
|
||||
content = str(text or "").strip()
|
||||
if not content:
|
||||
|
|
@ -9630,8 +9631,15 @@ wakeup_type={_single_line(wakeup.get('type'), 40)} score={_single_line(wakeup.ge
|
|||
except Exception:
|
||||
pass
|
||||
instruction = expression_decision_prompt(expression_projection)
|
||||
if instruction and hasattr(req, "system_prompt"):
|
||||
req.system_prompt = f"{str(getattr(req, 'system_prompt', '') or '').rstrip()}\n\n[Companion expression]\n{instruction}"
|
||||
if instruction:
|
||||
self._append_turn_prompt_fragment_by_position(
|
||||
req,
|
||||
"<!-- private_companion_expression_decision_v1 -->",
|
||||
f"[Companion expression]\n{instruction}",
|
||||
priority=5,
|
||||
source="expression_decision",
|
||||
force_dynamic=True,
|
||||
)
|
||||
|
||||
@filter.on_llm_request(priority=-22000)
|
||||
async def prepare_p5_memory_attestation(self, event: AstrMessageEvent, req: ProviderRequest, *args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ class ReplyTemperatureTests(unittest.TestCase):
|
|||
self.assertEqual([], legacy_calls)
|
||||
self.assertIn("_private_companion_expression_decision", source)
|
||||
self.assertNotIn("_private_companion_reply_temperature", source)
|
||||
self.assertIn("private_companion_expression_decision_v1", source)
|
||||
helper = next(
|
||||
node for node in ast.walk(tree)
|
||||
if isinstance(node, ast.FunctionDef) and node.name == "_bounded_expression_state_signals"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
|
||||
class EmotionE1PromptCacheTests(unittest.TestCase):
|
||||
def test_expression_decision_is_a_forced_dynamic_fragment(self) -> None:
|
||||
source = (ROOT / "main.py").read_text(encoding="utf-8")
|
||||
tree = ast.parse(source)
|
||||
gate = next(
|
||||
node
|
||||
for node in ast.walk(tree)
|
||||
if isinstance(node, ast.AsyncFunctionDef)
|
||||
and node.name == "enforce_p4_live_confinement_before_enrichment"
|
||||
)
|
||||
calls = [
|
||||
node
|
||||
for node in ast.walk(gate)
|
||||
if isinstance(node, ast.Call)
|
||||
and isinstance(node.func, ast.Attribute)
|
||||
and node.func.attr == "_append_turn_prompt_fragment_by_position"
|
||||
]
|
||||
self.assertEqual(1, len(calls))
|
||||
keywords = {item.arg: item.value for item in calls[0].keywords if item.arg}
|
||||
self.assertIsInstance(keywords.get("force_dynamic"), ast.Constant)
|
||||
self.assertTrue(keywords["force_dynamic"].value)
|
||||
|
||||
assignments = [
|
||||
node
|
||||
for node in ast.walk(gate)
|
||||
if isinstance(node, (ast.Assign, ast.AnnAssign, ast.AugAssign))
|
||||
and "system_prompt" in ast.unparse(node)
|
||||
and "Companion expression" in ast.unparse(node)
|
||||
]
|
||||
self.assertEqual([], assignments)
|
||||
|
||||
def test_forced_dynamic_fragments_ignore_system_prompt_preference(self) -> None:
|
||||
source = (ROOT / "main.py").read_text(encoding="utf-8")
|
||||
tree = ast.parse(source)
|
||||
helper = next(
|
||||
node
|
||||
for node in ast.walk(tree)
|
||||
if isinstance(node, ast.FunctionDef)
|
||||
and node.name == "_append_turn_prompt_fragment_by_position"
|
||||
)
|
||||
rendered = ast.unparse(helper)
|
||||
self.assertIn("force_dynamic", rendered)
|
||||
self.assertIn("and (not force_dynamic)", rendered)
|
||||
self.assertIn("prefer_extra_user_content=True", rendered)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
正在加载…
添加表格
在新工单中引用