feat: 实现AI拒答机制和语言控制优化
- 添加 RunStatus.REFUSED 状态,AI可明确表达拒答意图 - 优化 System Prompt 使用视觉强调提高AI对拒答规则的遵守 - User Prompt 添加 SCOPE CHECK 和语言约束 - Worker Rules 添加多语言版本角色扮演规则 - Runner 传递 language 参数到 worker stage - json_finalize 添加语言约束参数 - 更新单元测试匹配新的 prompt 结构
This commit is contained in:
@@ -47,12 +47,41 @@ class _Model:
|
||||
return _Response(self._payload)
|
||||
|
||||
|
||||
def test_build_instruction_uses_output_schema_title() -> None:
|
||||
def test_build_instruction_has_schema() -> None:
|
||||
instruction = build_json_finalize_instruction(
|
||||
schema_json="{}",
|
||||
attempt=1,
|
||||
)
|
||||
assert "[输出结构Output Schema]" in instruction
|
||||
assert "[Output Schema]" in instruction
|
||||
|
||||
|
||||
def test_build_instruction_has_language_constraint_en() -> None:
|
||||
instruction = build_json_finalize_instruction(
|
||||
schema_json="{}",
|
||||
attempt=1,
|
||||
language="en-US",
|
||||
)
|
||||
assert "ENGLISH OUTPUT REQUIRED" in instruction
|
||||
assert "═══════════════════════════════════════════════════════════════════════════════" in instruction
|
||||
|
||||
|
||||
def test_build_instruction_has_language_constraint_zh() -> None:
|
||||
instruction = build_json_finalize_instruction(
|
||||
schema_json="{}",
|
||||
attempt=1,
|
||||
language="zh-CN",
|
||||
)
|
||||
assert "返回 JSON。使用简体中文" in instruction
|
||||
|
||||
|
||||
def test_build_instruction_no_language_constraint_when_none() -> None:
|
||||
instruction = build_json_finalize_instruction(
|
||||
schema_json="{}",
|
||||
attempt=1,
|
||||
language=None,
|
||||
)
|
||||
assert "ENGLISH OUTPUT REQUIRED" not in instruction
|
||||
assert "返回 JSON" not in instruction
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user