MCPcopy Create free account
hub / github.com/promptfoo/promptfoo / write_metrics

Function write_metrics

examples/integration-e2b/metrics.py:7–27  ·  view source on GitHub ↗
(
    task_id, provider, model, success, runtime_s, memory_mb=None, extra=None
)

Source from the content-addressed store, hash-verified

5
6
7def 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

Callers 1

get_assertFunction · 0.90

Calls 1

getenvMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…