MCPcopy Create free account
hub / github.com/openai/plugins / extractUsagePayload

Function extractUsagePayload

plugins/plugin-eval/src/core/observed-usage.js:43–85  ·  view source on GitHub ↗
(candidate)

Source from the content-addressed store, hash-verified

41}
42
43function extractUsagePayload(candidate) {
44 if (!candidate || typeof candidate !== "object") {
45 return null;
46 }
47
48 if (candidate.type === "response.done" && candidate.response?.usage) {
49 return {
50 usage: candidate.response.usage,
51 responseId: candidate.response.id || candidate.id || null,
52 label: candidate.metadata?.scenario || candidate.response?.metadata?.scenario || null,
53 };
54 }
55
56 if (candidate.response?.usage) {
57 return {
58 usage: candidate.response.usage,
59 responseId: candidate.response.id || candidate.id || null,
60 label: candidate.metadata?.scenario || candidate.response?.metadata?.scenario || null,
61 };
62 }
63
64 if (candidate.usage) {
65 return {
66 usage: candidate.usage,
67 responseId: candidate.response_id || candidate.id || null,
68 label: candidate.metadata?.scenario || candidate.scenario || null,
69 };
70 }
71
72 if (
73 typeof candidate.input_tokens === "number" ||
74 typeof candidate.output_tokens === "number" ||
75 typeof candidate.total_tokens === "number"
76 ) {
77 return {
78 usage: candidate,
79 responseId: candidate.response_id || candidate.id || null,
80 label: candidate.metadata?.scenario || candidate.scenario || null,
81 };
82 }
83
84 return null;
85}
86
87function normalizeSnapshot(candidate, sourcePath, index) {
88 const extracted = extractUsagePayload(candidate);

Callers 1

normalizeSnapshotFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected