feat(writer): 输出语言一致性保障 + 用户可选输出语言
- 步骤0: 新增中文镜像模板 scripts/make_zh_template.py 与 samples/概要设计书模板_中文.docx(7章锚点原样保留) - 步骤1: config.WriterConfig.output_language→Settings.writer;GenerationContext.output_language + to_vars.language_instruction(zh/ja/auto);writer_agent【语言约束】改引变量;context_builder/orchestrator/run_trial 透传 --output-language - 步骤A: 新建 src/genesis/writer/language.py(detect_script/resolve_expected_language/find_language_violations);WriterAgent.generate_chapter 按期望语言强制、违规重试、耗尽硬失败;max_retries 默认 1→2 - 步骤B: _format_impact 影响调查标签按 output_language 本地化(zh 新建/变更/删除/警告) - 步骤C: eval scorer 第 11 维度 language_consistency(不可验证=满分,不拉低总分);ChapterArtifact.expected_language;QAValidator.validate_doc 透传;QALoop.run 透传 output_language - 测试: test_zh_template/test_language_plumbing/test_writer_language/test_scorer_language/test_language_coverage,并更新 test_phase5_e2e - 全量 pytest 424 passed / 99.15%(覆盖率门槛 99% 达标)
This commit is contained in:
@@ -21,8 +21,8 @@ class QALoop:
|
||||
def __init__(self, max_rounds: int = DEFAULT_MAX_QA_ROUNDS) -> None:
|
||||
self.controller = QALoopController(max_rounds=max_rounds)
|
||||
|
||||
def _build(self, structured_source, samples_dir, engine, prompt_registry, template_path, output_path, session_id, only_ids=None, prev=None):
|
||||
ctxs = build_contexts(structured_source, samples_dir)
|
||||
def _build(self, structured_source, samples_dir, engine, prompt_registry, template_path, output_path, session_id, only_ids=None, prev=None, output_language: str = "auto"):
|
||||
ctxs = build_contexts(structured_source, samples_dir, output_language=output_language)
|
||||
_warn_unanchored(ctxs)
|
||||
state = WriterState([c.chapter_id for c in ctxs])
|
||||
agent = WriterAgent(session_id=session_id, engine=engine, prompt_registry=prompt_registry, state=state)
|
||||
@@ -47,12 +47,14 @@ class QALoop:
|
||||
doc.save(output_path)
|
||||
return [contents_map[cid] for cid in order]
|
||||
|
||||
def run(self, structured_source, output_path, session_id="writer", samples_dir="samples", engine=None, prompt_registry=None, template_path=None) -> QAReport:
|
||||
def run(self, structured_source, output_path, session_id="writer", samples_dir="samples", engine=None, prompt_registry=None, template_path=None, output_language: str = "auto") -> QAReport:
|
||||
engine = engine or build_inference_engine()
|
||||
prompt_registry = prompt_registry or PromptRegistry()
|
||||
validator = QAValidator()
|
||||
contents = self._build(structured_source, samples_dir, engine, prompt_registry, template_path, output_path, session_id)
|
||||
report = validator.validate_doc(contents, structured_source)
|
||||
# auto 不可推导期望语言 → 语言维度记满分(unverifiable);zh/ja 显式强制
|
||||
expected = output_language if output_language in ("zh", "ja") else ""
|
||||
contents = self._build(structured_source, samples_dir, engine, prompt_registry, template_path, output_path, session_id, output_language=output_language)
|
||||
report = validator.validate_doc(contents, structured_source, expected_language=expected)
|
||||
while self.controller.can_continue() and report.failed_chapters:
|
||||
self.controller.advance()
|
||||
contents = self._build(
|
||||
@@ -65,6 +67,7 @@ class QALoop:
|
||||
session_id,
|
||||
only_ids=set(report.failed_chapters),
|
||||
prev={c.chapter_id: c for c in contents},
|
||||
output_language=output_language,
|
||||
)
|
||||
report = validator.validate_doc(contents, structured_source)
|
||||
report = validator.validate_doc(contents, structured_source, expected_language=expected)
|
||||
return report
|
||||
|
||||
Reference in New Issue
Block a user