From 48a9624723bd458fb5c8ee42fdb10c00e59792ce Mon Sep 17 00:00:00 2001 From: lhl Date: Fri, 14 Aug 2026 00:12:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(writer):=20=E6=AD=A3=E6=96=87=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E9=A1=BB=E4=B8=8E=E7=AB=A0=E8=8A=82=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E4=B8=80=E8=87=B4=EF=BC=88=E6=A8=A1=E6=9D=BF=E6=97=A5=E6=96=87?= =?UTF-8?q?=E5=88=99=E8=BE=93=E5=87=BA=E6=97=A5=E6=96=87=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _AI_USAGE_LOG.md | 3 ++- src/genesis/writer/writer_agent.py | 5 ++++- tests/test_phase5_writer_agent.py | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/_AI_USAGE_LOG.md b/_AI_USAGE_LOG.md index 5301ba6..af69d91 100644 --- a/_AI_USAGE_LOG.md +++ b/_AI_USAGE_LOG.md @@ -107,4 +107,5 @@ | 2026-08-13 23:11 | Agent 实现 | 接通真实 LLM 引擎工厂(P5-T10 门禁接线):新增 inference/factory.py,orchestrator/qa_loop 接入,脚本校验适配,补工厂测试 | src/genesis/inference/factory.py; src/genesis/writer/orchestrator.py; src/genesis/qa/qa_loop.py; scripts/run_phase5_slice.py; tests/test_inference_factory.py | hy3-free | | 2026-08-13 23:20 | 测试验证 | P5-T10 引擎工厂接线:补 engine=None 委托工厂测试(orchestrator/qa_loop),全量 296 passed / 99.04% | tests/test_phase5_writer_orchestrator.py; tests/test_phase5_qa_loop.py | hy3-free | | 2026-08-13 23:35 | 测试验证 | P5-T10 门禁诊断:修复 WriterGenerationError 吞掉底层 LLM 错误(如 401 详情),补透传测试 | src/genesis/writer/writer_agent.py; tests/test_phase5_writer_agent.py | hy3-free | -| 2026-08-13 23:50 | Agent 实现 | 修复 HttpLLMClient 在同步门禁中多次 asyncio.run 复用已关闭事件循环致 Event loop is closed:chat 改为每次调用新建 client(保留 async with 协议)| src/genesis/inference/client.py | hy3-free | \ No newline at end of file +| 2026-08-13 23:50 | Agent 实现 | 修复 HttpLLMClient 在同步门禁中多次 asyncio.run 复用已关闭事件循环致 Event loop is closed:chat 改为每次调用新建 client(保留 async with 协议)| src/genesis/inference/client.py | hy3-free | +| 2026-08-13 23:58 | Agent 实现 | P5-T10 语言对齐:WRITER_PROMPT_TEMPLATE 增加「正文语言须与章节标题一致」约束(模板日文则输出日文)| src/genesis/writer/writer_agent.py; tests/test_phase5_writer_agent.py | hy3-free | \ No newline at end of file diff --git a/src/genesis/writer/writer_agent.py b/src/genesis/writer/writer_agent.py index 71ca6bd..007cf23 100644 --- a/src/genesis/writer/writer_agent.py +++ b/src/genesis/writer/writer_agent.py @@ -22,7 +22,10 @@ WRITER_PROMPT_TEMPLATE = ( "设计规则:\n{{design_rules}}\n" "模板样式:\n{{template_styles}}\n" "参考资料:\n{{source}}\n" - "请输出符合 schema 的章节内容 JSON。" + "请输出符合 schema 的章节内容 JSON。\n" + "【语言约束】章节正文(所有 block 的 text 字段)所使用的自然语言," + "必须与章节标题「{{title}}」所用语言保持一致:标题为日文则用日文撰写," + "为中文则用中文撰写,依此类推。" ) CHAPTER_OUTPUT_SCHEMA = { diff --git a/tests/test_phase5_writer_agent.py b/tests/test_phase5_writer_agent.py index fcbd8e7..bf671ba 100644 --- a/tests/test_phase5_writer_agent.py +++ b/tests/test_phase5_writer_agent.py @@ -54,6 +54,12 @@ def test_generate_chapter_success(): assert content.blocks and content.blocks[0].type == "paragraph" +def test_prompt_template_enforces_title_language(): + # 语言约束:正文需与章节标题语言一致(模板为日文时输出日文) + assert "语言约束" in WRITER_PROMPT_TEMPLATE + assert "{{title}}" in WRITER_PROMPT_TEMPLATE + + def test_generate_chapter_retries(): class Boom(FakeEngine): def chat_structured(self, *, session_id, prompt, variables, schema, retry_count=2):