mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-08-28 05:25:04 +00:00
fix(prompt): default omitted conditional flags to false (#424)
Always apply conditional-line filtering so tagged prompt lines are removed unless the corresponding boolean flag is explicitly true. Add regressions for omitted flags with and without format variables. Test: pytest tests/unit/test_prompt_handler.py -q
This commit is contained in:
parent
23d4c96c15
commit
6503e1271c
2 changed files with 9 additions and 5 deletions
|
|
@ -116,8 +116,7 @@ class PromptHandler:
|
|||
flags = {k: v for k, v in kwargs.items() if isinstance(v, bool)}
|
||||
formats = {k: v for k, v in kwargs.items() if not isinstance(v, bool)}
|
||||
|
||||
if flags:
|
||||
prompt = self._apply_flag_filter(prompt, flags)
|
||||
prompt = self._apply_flag_filter(prompt, flags)
|
||||
|
||||
return prompt.format(**formats).strip() if formats else prompt
|
||||
|
||||
|
|
|
|||
|
|
@ -182,13 +182,18 @@ def test_flag_filter_removes_non_matching():
|
|||
def test_flag_filter_default_false():
|
||||
ph = PromptHandler()
|
||||
ph.load_prompt_dict({"p": "[debug] debug info\nbase"})
|
||||
# When no flags are passed at all, _apply_flag_filter is not called,
|
||||
# so flagged lines are kept as-is (including the tag text after regex sub).
|
||||
result = ph.prompt_format("p", debug=False)
|
||||
result = ph.prompt_format("p")
|
||||
assert "debug info" not in result
|
||||
assert "base" in result
|
||||
|
||||
|
||||
def test_flag_filter_defaults_false_with_format_variables():
|
||||
ph = PromptHandler()
|
||||
ph.load_prompt_dict({"p": "[debug] debug {name}\nhello {name}"})
|
||||
result = ph.prompt_format("p", name="Alice")
|
||||
assert result == "hello Alice"
|
||||
|
||||
|
||||
def test_flag_filter_unflagged_lines_always_kept():
|
||||
ph = PromptHandler()
|
||||
ph.load_prompt_dict({"p": "line1\nline2\nline3"})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue