feat: thread and persist sub_pattern into accepted questions

This commit is contained in:
2026-07-14 13:45:31 -04:00
parent 25f2a845ff
commit ae0a718f67
4 changed files with 98 additions and 25 deletions
+19 -25
View File
@@ -323,6 +323,23 @@ def _build_embed_provider():
# ---------------------------------------------------------------------------
def _question_to_entry(question: GeneratedQuestion) -> dict:
"""将题目序列化为 JSON entry_append_to_json 与 _on_accept 共用)。"""
return {
"question_id": question.question_id,
"video_id": question.video_id,
"task_type": question.task_type,
"question": question.question,
"options": list(question.options),
"answer": question.answer,
"source_nodes": list(question.source_nodes),
"difficulty": question.difficulty,
"family": question.family,
"skill_target": question.skill_target,
"sub_pattern": question.sub_pattern,
}
def _append_to_json(output_dir: Path, question: GeneratedQuestion) -> None:
"""将生成的题目追加到对应 video_id 的 JSON 文件。
@@ -341,17 +358,7 @@ def _append_to_json(output_dir: Path, question: GeneratedQuestion) -> None:
logger.warning("读取 {} 失败,覆盖写入", json_path)
existing = []
entry = {
"question_id": question.question_id,
"task_type": question.task_type,
"question": question.question,
"options": list(question.options),
"answer": question.answer,
"source_nodes": list(question.source_nodes),
"difficulty": question.difficulty,
"family": question.family,
"skill_target": question.skill_target,
}
entry = _question_to_entry(question)
existing.append(entry)
# 原子写入
@@ -1120,20 +1127,7 @@ async def _run_generate_v2(args: argparse.Namespace) -> None:
except (json.JSONDecodeError, OSError):
existing = []
existing.append(
{
"question_id": q.question_id,
"video_id": q.video_id,
"task_type": q.task_type,
"question": q.question,
"options": list(q.options),
"answer": q.answer,
"source_nodes": list(q.source_nodes),
"difficulty": q.difficulty,
"family": q.family,
"skill_target": q.skill_target,
}
)
existing.append(_question_to_entry(q))
tmp_path = output_path.with_suffix(".tmp")
tmp_path.write_text(