(
task_id, provider, model, success, runtime_s, memory_mb=None, extra=None
)
| 5 | |
| 6 | |
| 7 | def write_metrics( |
| 8 | task_id, provider, model, success, runtime_s, memory_mb=None, extra=None |
| 9 | ): |
| 10 | metrics = { |
| 11 | "task_id": str(task_id), |
| 12 | "provider": provider, |
| 13 | "model": model, |
| 14 | "success": bool(success), |
| 15 | "runtime_s": float(runtime_s), |
| 16 | "memory_mb": memory_mb, |
| 17 | "extra": extra or {}, |
| 18 | "timestamp": int(time.time()), |
| 19 | } |
| 20 | out_dir = os.getenv("PROMPTFOO_RESULTS_DIR", ".promptfoo_results") |
| 21 | os.makedirs(out_dir, exist_ok=True) |
| 22 | fn = f"{metrics['task_id']}_{provider}_{model}.json".replace("/", "_") |
| 23 | path = os.path.join(out_dir, fn) |
| 24 | with open(path, "w") as f: |
| 25 | # <- this makes ExecutionError, Exception, etc. become strings |
| 26 | json.dump(metrics, f, indent=2, default=str) |
| 27 | return path |
no test coverage detected
searching dependent graphs…