Improve online mining record conversion
This commit is contained in:
@@ -35,6 +35,69 @@ def case_value(case: dict, key: str):
|
||||
return case.get(key) or pre.get(key) or main.get(key)
|
||||
|
||||
|
||||
def build_dataset_draft_text(
|
||||
*,
|
||||
dataset_label: str,
|
||||
target: str,
|
||||
complex_value: bool,
|
||||
cases: list[dict],
|
||||
) -> str:
|
||||
"""把 review 后的线上 case 转成 product-data dataset draft text。
|
||||
|
||||
这个 draft 是中间格式,不是最终数据。后续必须再经过
|
||||
product-data 的 normalize/validate/export。
|
||||
"""
|
||||
|
||||
lines = [f"# dataset_label: {dataset_label}", ""]
|
||||
for index, case in enumerate(cases, start=1):
|
||||
query = str(case_value(case, "query") or "").strip()
|
||||
if not query:
|
||||
continue
|
||||
request_id = str(case_value(case, "request_id") or "").strip()
|
||||
timestamp = case_value(case, "timestamp")
|
||||
tts = str(case_value(case, "tts") or "").strip()
|
||||
planning_result = str(case_value(case, "planning_result") or "").strip()
|
||||
case_target = str(case_value(case, "target") or target).strip()
|
||||
case_complex = case_value(case, "complex")
|
||||
if isinstance(case_complex, str):
|
||||
case_complex_text = case_complex.strip().lower()
|
||||
item_complex = case_complex_text in {"true", "1", "yes", "y", "是", "复杂", "complex"}
|
||||
elif isinstance(case_complex, bool):
|
||||
item_complex = case_complex
|
||||
else:
|
||||
item_complex = complex_value
|
||||
notes = []
|
||||
if planning_result:
|
||||
notes.append(f"线上模型输出: {planning_result}")
|
||||
main_domain = case_value(case, "domain") or case.get("main_domain")
|
||||
if main_domain:
|
||||
notes.append(f"线上 domain: {main_domain}")
|
||||
lines.append(f"### case: online_{index:04d}")
|
||||
prev_session = case_value(case, "prev_session")
|
||||
if isinstance(prev_session, list):
|
||||
for item in prev_session[-10:]:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
prev_query = str(item.get("query") or "").strip()
|
||||
prev_tts = str(item.get("tts") or "").strip()
|
||||
if prev_query and prev_tts:
|
||||
lines.append(f"用户: {prev_query}")
|
||||
lines.append(f"小爱: {prev_tts}")
|
||||
lines.append(f"用户: {query}")
|
||||
lines.append(f"complex: {'true' if item_complex else 'false'}")
|
||||
lines.append(f"target: {case_target}")
|
||||
if request_id:
|
||||
lines.append(f"request_id: {request_id}")
|
||||
if timestamp:
|
||||
lines.append(f"timestamp: {timestamp}")
|
||||
if tts:
|
||||
lines.append(f"notes: tts={tts}" + (f";{';'.join(notes)}" if notes else ""))
|
||||
elif notes:
|
||||
lines.append(f"notes: {';'.join(notes)}")
|
||||
lines.append("")
|
||||
return "\n".join(lines).strip() + "\n"
|
||||
|
||||
|
||||
def main() -> int:
|
||||
try:
|
||||
payload = load_json_payload()
|
||||
@@ -49,36 +112,12 @@ def main() -> int:
|
||||
if not cases:
|
||||
raise ValueError("cases must not be empty")
|
||||
|
||||
lines = [f"# dataset_label: {dataset_label}", ""]
|
||||
for index, case in enumerate(cases, start=1):
|
||||
query = str(case_value(case, "query") or "").strip()
|
||||
if not query:
|
||||
continue
|
||||
request_id = str(case_value(case, "request_id") or "").strip()
|
||||
timestamp = case_value(case, "timestamp")
|
||||
tts = str(case_value(case, "tts") or "").strip()
|
||||
planning_result = str(case_value(case, "planning_result") or "").strip()
|
||||
notes = []
|
||||
if planning_result:
|
||||
notes.append(f"线上模型输出: {planning_result}")
|
||||
main_domain = case_value(case, "domain") or case.get("main_domain")
|
||||
if main_domain:
|
||||
notes.append(f"线上 domain: {main_domain}")
|
||||
lines.append(f"### case: online_{index:04d}")
|
||||
lines.append(f"用户: {query}")
|
||||
lines.append(f"complex: {'true' if complex_value else 'false'}")
|
||||
lines.append(f"target: {target}")
|
||||
if request_id:
|
||||
lines.append(f"request_id: {request_id}")
|
||||
if timestamp:
|
||||
lines.append(f"timestamp: {timestamp}")
|
||||
if tts:
|
||||
lines.append(f"notes: tts={tts}" + (f";{';'.join(notes)}" if notes else ""))
|
||||
elif notes:
|
||||
lines.append(f"notes: {';'.join(notes)}")
|
||||
lines.append("")
|
||||
|
||||
draft_text = "\n".join(lines).strip() + "\n"
|
||||
draft_text = build_dataset_draft_text(
|
||||
dataset_label=dataset_label,
|
||||
target=target,
|
||||
complex_value=complex_value,
|
||||
cases=cases,
|
||||
)
|
||||
output_path = None
|
||||
if payload.get("output_path"):
|
||||
output = resolve_portable_path(str(payload["output_path"]))
|
||||
@@ -94,4 +133,3 @@ def main() -> int:
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user