forked from DietrichGebert/ponytail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloc.js
More file actions
13 lines (13 loc) · 738 Bytes
/
Copy pathloc.js
File metadata and controls
13 lines (13 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
// Deterministic code-size metric: non-blank, non-comment lines of code. Counts
// fenced blocks, or the whole response when the model emitted bare code unfenced.
// Recorded as the `code_loc` metric per arm (always passes; it is a measurement, not a gate).
module.exports = (output) => {
const text = String(output || '');
const blocks = [...text.matchAll(/```[a-zA-Z0-9_+-]*\n([\s\S]*?)```/g)].map((m) => m[1]);
const code = blocks.length ? blocks.join('\n') : text;
const loc = code
.split('\n')
.map((l) => l.trim())
.filter((l) => l && !l.startsWith('//') && !l.startsWith('#') && l !== '*/' && !l.startsWith('/*') && !l.startsWith('*')).length;
return { pass: true, score: loc, reason: loc + ' code LOC' };
};