"""EIN Trainings-Trial: frischer Prozess (CREATOR_PARAMS wirkt beim Import), ein kompletter Mini-Lauf, deterministische Metriken als JSON — danach ist das Topic weg. CLI: python3 train_lauf.py (benchmark-location repo-relativ, z. B. "benchmarks/sortierverfahren") """ import asyncio import shutil import sys from datetime import datetime, timezone from pathlib import Path import agents import database import qa from blocks import generate_blocks from fsutil import atomic_write_json from paths import source_path, topic_dir async def trial(topic: str, location: str, out: str) -> None: await database.init_db() agents.on_event = database.add_event # sonst keine Dauer-/Token-Events (main.py-lifespan-Pendant) try: await _aufraeumen(topic) # Reste eines abgebrochenen Trials await database.create_topic(topic) qp = source_path(topic) qp.parent.mkdir(parents=True, exist_ok=True) atomic_write_json(qp, {"type": "uni", "location": location, "spec": ""}) start = datetime.now(timezone.utc) # qa_force=True: das Gate misst, pausiert den Trial aber nie await generate_blocks(topic, provider="minimax", research=True, qa_force=True) dauer_min = round((datetime.now(timezone.utc) - start).total_seconds() / 60, 1) report = await qa.qa_report(topic, llm=False) or {} lauf = report.get("lauf") or {} metrics = { "topic": topic, "note": report.get("note"), "note_artefakte": report.get("note_artefakte"), "quoten": report.get("quoten") or {}, "quoten_artefakte": report.get("quoten_artefakte") or {}, "bloecke": report.get("bloecke"), "dauer_min": lauf.get("dauer_min") or dauer_min, "tokens": (lauf.get("tokens") or {}), "agents": (lauf.get("agents") or {}), } atomic_write_json(Path(out), metrics, indent=1) finally: await _aufraeumen(topic) await database.close_db() async def _aufraeumen(topic: str) -> None: """Topic restlos entfernen (DELETE-/topics-Sequenz aus routes.py).""" await database.delete_topic(topic) await database.delete_block_data(topic) await database.delete_topic_pipeline(topic) await database.delete_source(topic) await database.delete_guide_content(topic) shutil.rmtree(topic_dir(topic), ignore_errors=True) shutil.rmtree(qa.QA_DIR / topic, ignore_errors=True) if __name__ == "__main__": if len(sys.argv) != 4: raise SystemExit("Nutzung: python3 train_lauf.py ") asyncio.run(trial(sys.argv[1], sys.argv[2], sys.argv[3]))