Files
wehub-resource-sync 0d3cb498a3
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00

81 lines
2.5 KiB
Python

"""
Example Python extension hook for processing evaluation results.
Usage:
promptfoo eval -x file://result-handler.py:after_all
Or in promptfooconfig.yaml:
extensions:
- file://result-handler.py:after_all
"""
def after_all(context):
"""
Called after all tests complete.
Args:
context: Dictionary with keys:
- evalId: Unique evaluation ID
- config: Full evaluation configuration
- suite: Test suite configuration
- results: List of all evaluation results
- prompts: List of completed prompts with metrics
"""
eval_id = context.get("evalId")
results = context.get("results", [])
# Calculate statistics
total = len(results)
passed = sum(1 for r in results if r.get("success"))
failed = total - passed
success_rate = (passed / total * 100) if total > 0 else 0
# Calculate costs and latency
total_cost = sum(r.get("cost", 0) or 0 for r in results)
avg_latency = (
sum(r.get("latencyMs", 0) or 0 for r in results) / total if total > 0 else 0
)
print("\n" + "=" * 40)
print(" EVALUATION RESULTS SUMMARY ")
print("=" * 40)
print(f"Eval ID: {eval_id}")
print(f"Total Tests: {total}")
print(f"Passed: {passed}")
print(f"Failed: {failed}")
print(f"Success Rate: {success_rate:.1f}%")
print(f"Total Cost: ${total_cost:.4f}")
print(f"Avg Latency: {avg_latency:.0f}ms")
print("=" * 40 + "\n")
# Alert on low success rate
if success_rate < 80:
print(f"WARNING: Success rate {success_rate:.1f}% is below 80% threshold!")
# Example: Send webhook notification
# import requests
# requests.post("https://hooks.slack.com/...", json={
# "text": f"Evaluation {eval_id} has low success rate: {success_rate:.1f}%"
# })
# Log failures
if failed > 0:
print("Failed tests:")
for i, r in enumerate(results):
if not r.get("success"):
error = r.get("error") or "Assertion failed"
print(f" {i + 1}. {error}")
# Example: Export to CSV
# import csv
# with open(f"results_{eval_id}.csv", "w", newline="") as f:
# writer = csv.DictWriter(f, fieldnames=["success", "latencyMs", "cost"])
# writer.writeheader()
# for r in results:
# writer.writerow({
# "success": r.get("success"),
# "latencyMs": r.get("latencyMs"),
# "cost": r.get("cost"),
# })