feat(data-process): 增加可配置思维链生成
This commit is contained in:
@@ -33,6 +33,8 @@ def test_generate_model_records_uses_prompt_auth_and_stable_split() -> None:
|
||||
assert payload["model"] == "qwen-plus"
|
||||
assert payload["response_format"] == {"type": "json_object"}
|
||||
assert "客户反馈页面加载慢" in payload["messages"][1]["content"]
|
||||
assert "你正在生成标准监督微调问答数据" in payload["messages"][0]["content"]
|
||||
assert "禁止输出分析、推理过程" in payload["messages"][0]["content"]
|
||||
return httpx.Response(
|
||||
200,
|
||||
json={
|
||||
@@ -91,6 +93,8 @@ def test_generate_model_records_builds_reasoning_output_with_think_tags() -> Non
|
||||
payload = json.loads(request.content)
|
||||
system_prompt = payload["messages"][0]["content"]
|
||||
assert '"reasoning":"...","answer":"..."' in system_prompt
|
||||
assert "你正在生成用于训练推理模型的思维链数据" in system_prompt
|
||||
assert "推理详细程度为“普通”" in system_prompt
|
||||
assert "系统会在保存时统一组装" in system_prompt
|
||||
content = "<think>模型接口自己的分析</think>" + json.dumps(
|
||||
{
|
||||
@@ -126,6 +130,49 @@ def test_generate_model_records_builds_reasoning_output_with_think_tags() -> Non
|
||||
)
|
||||
|
||||
|
||||
def test_generate_model_records_uses_detailed_reasoning_instruction() -> None:
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
system_prompt = json.loads(request.content)["messages"][0]["content"]
|
||||
assert "推理详细程度为“详细”" in system_prompt
|
||||
assert "完整展开问题条件、来源依据、中间计算或推导" in system_prompt
|
||||
return httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"choices": [
|
||||
{
|
||||
"message": {
|
||||
"content": json.dumps(
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"instruction": "计算报销总额",
|
||||
"reasoning": "条件为交通费 30 元和餐费 20 元。分别核对后相加,30 + 20 = 50。",
|
||||
"answer": "报销总额为 50 元。",
|
||||
}
|
||||
]
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
records = generate_model_records(
|
||||
[{"id": "preview-detailed", "edited_content": "交通费 30 元,餐费 20 元"}],
|
||||
model={"name": "model", "api_url": "https://model.example/v1"},
|
||||
config={"output_type": "reasoning", "reasoning_detail": "detailed"},
|
||||
task_id="task-detailed",
|
||||
split={"train": 100, "validation": 0, "test": 0},
|
||||
qa_pairs_per_item=1,
|
||||
client=httpx.Client(transport=httpx.MockTransport(handler)),
|
||||
)
|
||||
|
||||
assert records[0]["status"] == "valid"
|
||||
assert "分别核对后相加" in records[0]["output"]
|
||||
|
||||
|
||||
def test_generate_model_records_marks_reasoning_without_reasoning_field_invalid() -> None:
|
||||
response = {
|
||||
"choices": [
|
||||
@@ -392,3 +439,15 @@ def test_generate_model_records_rejects_unknown_output_type() -> None:
|
||||
split={"train": 100, "validation": 0, "test": 0},
|
||||
qa_pairs_per_item=1,
|
||||
)
|
||||
|
||||
|
||||
def test_generate_model_records_rejects_unknown_reasoning_detail() -> None:
|
||||
with pytest.raises(ModelGenerationError, match="reasoning_detail"):
|
||||
generate_model_records(
|
||||
[],
|
||||
model={"name": "model", "api_url": "https://model.example/v1"},
|
||||
config={"output_type": "reasoning", "reasoning_detail": "verbose"},
|
||||
task_id="task-invalid-reasoning-detail",
|
||||
split={"train": 100, "validation": 0, "test": 0},
|
||||
qa_pairs_per_item=1,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user