refactor(auto-resource): remove legacy image prompt aliases

This commit is contained in:
wang-qisen 2026-09-21 18:47:06 +08:00
parent 1c374f83be
commit 2819df39f8
4 changed files with 9 additions and 35 deletions

View file

@ -78,8 +78,8 @@ description or transcription under `## Caption`, not an empty caption or a JSON
processing steps and keep its existing value when updating the card.
Customize image instructions with `prompt_dict.resource_instructions` (`resource_instructions_zh` for Chinese).
Existing `user_message` / `user_message_zh` settings still work; the new name takes precedence when both are set for the
same language. Shared create/update templates insert these instructions at `{resource_instructions}`; older templates
Rename existing `user_message` / `user_message_zh` settings accordingly.
Shared create/update templates insert these instructions at `{resource_instructions}`; older templates
without the placeholder receive them at the end.
Set `include_images=false` on an `auto_resource` call or as a Job default to skip **all** image events, including

View file

@ -70,7 +70,7 @@ Agent 写入一张 caption 卡片并链接原图。卡片正文以 `![[resource/
`status` 留给后续流程填写,更新卡片时保留原值。
自定义图片提示词使用 `prompt_dict.resource_instructions`,中文使用 `resource_instructions_zh`;旧配置中的
`user_message` / `user_message_zh` 仍可使用,同一语言同时配置新旧名称时以新名称为准。公共创建或更新模板通过
`user_message` / `user_message_zh` 需相应改名。公共创建或更新模板通过
`{resource_instructions}` 插入图片要求;旧模板没有该占位符时,图片要求会追加到末尾。
在 `auto_resource` 调用或 Job 默认值中设置 `include_images=false`,会跳过图片的**全部事件,包括删除**。

View file

@ -214,18 +214,6 @@ class AutoImageResourceStep(BaseAutoResourceStep):
{"agent_wrapper", "max_image_bytes", "max_image_pixels", "prompt_dict"},
)
def __init__(self, *args, **kwargs):
prompt_dict = kwargs.get("prompt_dict")
if prompt_dict:
prompts = dict(prompt_dict)
for name, value in prompt_dict.items():
if (name == "user_message" or name.startswith("user_message_")) and not name.startswith(
("user_message_create", "user_message_update"),
):
prompts.setdefault(name.replace("user_message", "resource_instructions", 1), value)
kwargs["prompt_dict"] = prompts
super().__init__(*args, **kwargs)
def _max_image_bytes(self) -> int:
"""Return the image read limit from Step or Job context."""
value = self.kwargs.get("max_image_bytes")

View file

@ -812,9 +812,9 @@ import reme.steps.evolve.auto_image_resource
@pytest.mark.parametrize("language", ["en", "zh"])
@pytest.mark.parametrize("existing", [False, True], ids=["create", "update"])
@pytest.mark.parametrize("legacy_prompts", [False, True], ids=["default-prompts", "legacy-prompts"])
@pytest.mark.parametrize("legacy_template", [False, True], ids=["default-template", "legacy-template"])
@pytest.mark.asyncio
async def test_auto_image_prompt_merges_resource_instructions(language, existing, legacy_prompts, auto_resource_env):
async def test_auto_image_prompt_merges_resource_instructions(language, existing, legacy_template, auto_resource_env):
"""Shared create/update prompts include localized image requirements exactly once."""
env = auto_resource_env
source_path = "resource/2026-01-01/cat-at-beach.png"
@ -823,14 +823,14 @@ async def test_auto_image_prompt_merges_resource_instructions(language, existing
env.write_note("daily/2026-01-01/cat-at-beach.md", f"[[{source_path}]]")
model = _FakeImageAgentWrapper(_caption_fields("red-square", "Red", "A red square."))
step = env.processor(model, language=language)
if legacy_prompts:
if legacy_template:
suffix = "_zh" if language == "zh" else ""
prompt_name = "user_message_update" if existing else "user_message_create"
step = env.processor(
model,
language=language,
prompt_dict={
f"user_message{suffix}": "Legacy image instructions: {filename}",
f"resource_instructions{suffix}": "Custom image instructions: {filename}",
f"{prompt_name}{suffix}": step.get_prompt(prompt_name).replace("{resource_instructions}", ""),
},
)
@ -848,8 +848,8 @@ async def test_auto_image_prompt_merges_resource_instructions(language, existing
date="2026-01-01",
)
assert prompt.count(instructions) == 1
if legacy_prompts:
assert instructions == "Legacy image instructions: cat-at-beach.png"
if legacy_template:
assert instructions == "Custom image instructions: cat-at-beach.png"
assert prompt.endswith(instructions)
else:
assert ("weak hints" if language == "en" else "弱提示") in prompt
@ -858,20 +858,6 @@ async def test_auto_image_prompt_merges_resource_instructions(language, existing
assert ("read path=" in prompt) is existing
@pytest.mark.parametrize("language,suffix", [("en", ""), ("en", "_en"), ("zh", "_zh")])
def test_image_prompt_aliases_preserve_explicit_new_keys_and_caller_config(language, suffix):
"""Normalize only legacy image keys, leaving shared templates and the input dict intact."""
prompts = {f"user_message{suffix}": "legacy", f"user_message_create{suffix}": "custom create"}
original = dict(prompts)
step = AutoImageResourceStep(language=language, prompt_dict=prompts)
assert step.get_prompt("resource_instructions") == "legacy"
assert step.get_prompt("user_message_create") == "custom create"
assert prompts == original
prompts[f"resource_instructions{suffix}"] = "new"
step = AutoImageResourceStep(language=language, prompt_dict=prompts)
assert step.get_prompt("resource_instructions") == "new"
@pytest.mark.asyncio
async def test_auto_image_reports_modified_when_index_refresh_fails_after_write(auto_resource_env):
"""A post-write failure keeps the actual on-disk modification state."""