veryfront 0.1.948 → 0.1.949
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"judges.d.ts","sourceRoot":"","sources":["../../../src/src/eval/judges.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,sBAAsB,CAAC;AAGvE,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC;AAEtE,KAAK,iBAAiB,GAAG,WAAW,CAAC,mCAAmC,CAAC,OAAO,CAAC,CAAC,CAAC;AAEnF,uDAAuD;AACvD,MAAM,WAAW,+BAA+B;IAC9C,8FAA8F;IAC9F,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAC9B,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6FAA6F;IAC7F,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;
|
|
1
|
+
{"version":3,"file":"judges.d.ts","sourceRoot":"","sources":["../../../src/src/eval/judges.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,sBAAsB,CAAC;AAGvE,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC;AAEtE,KAAK,iBAAiB,GAAG,WAAW,CAAC,mCAAmC,CAAC,OAAO,CAAC,CAAC,CAAC;AAEnF,uDAAuD;AACvD,MAAM,WAAW,+BAA+B;IAC9C,8FAA8F;IAC9F,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAC9B,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6FAA6F;IAC7F,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;AAoND,iBAAS,0BAA0B,CACjC,OAAO,GAAE,+BAAoC,GAC5C,iBAAiB,CAoBnB;AAED,0DAA0D;AAC1D,eAAO,MAAM,MAAM;;QAEf,6DAA6D;;;CAGvD,CAAC"}
|
package/esm/src/eval/judges.js
CHANGED
|
@@ -5,6 +5,8 @@ const DEFAULT_JUDGE_MODEL = "auto";
|
|
|
5
5
|
const DEFAULT_THRESHOLD = 0.8;
|
|
6
6
|
const DEFAULT_MAX_EVIDENCE_CHARS = 12_000;
|
|
7
7
|
const DEFAULT_MAX_OUTPUT_TOKENS = 800;
|
|
8
|
+
const MAX_SOURCE_CHARS = 2_000;
|
|
9
|
+
const SOURCE_BUDGET_RATIO = 0.25;
|
|
8
10
|
function asJson(value) {
|
|
9
11
|
try {
|
|
10
12
|
return JSON.stringify(value, null, 2);
|
|
@@ -24,22 +26,29 @@ function resolveJudgeModel(model) {
|
|
|
24
26
|
return resolveModel(resolveRuntimeModel(model ?? DEFAULT_JUDGE_MODEL));
|
|
25
27
|
}
|
|
26
28
|
function truncate(value, maxChars) {
|
|
29
|
+
if (maxChars <= 0)
|
|
30
|
+
return "";
|
|
27
31
|
if (value.length <= maxChars)
|
|
28
32
|
return value;
|
|
29
|
-
|
|
33
|
+
const marker = "\n[truncated]";
|
|
34
|
+
if (maxChars <= marker.length)
|
|
35
|
+
return value.slice(0, maxChars);
|
|
36
|
+
return `${value.slice(0, maxChars - marker.length)}${marker}`;
|
|
30
37
|
}
|
|
31
38
|
function buildEvidenceBlock(evidence, sources, maxChars) {
|
|
32
39
|
const entries = evidence.length > 0 ? evidence : ["No retrieved evidence was provided."];
|
|
40
|
+
const evidenceBlock = entries.map((entry, index) => `[evidence ${index + 1}]\n${entry}`).join("\n\n");
|
|
33
41
|
const sourceBlock = sources.length > 0
|
|
34
42
|
? sources.map((source, index) => `- [source ${index + 1}] ${source}`).join("\n")
|
|
35
43
|
: "- none";
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
44
|
+
const sourceBudget = Math.min(sourceBlock.length, MAX_SOURCE_CHARS, Math.floor(maxChars * SOURCE_BUDGET_RATIO));
|
|
45
|
+
const sectionOverhead = "Evidence snippets:\n\n\nRetrieved sources:\n".length;
|
|
46
|
+
const evidenceBudget = Math.max(0, maxChars - sectionOverhead - sourceBudget);
|
|
47
|
+
return `Evidence snippets:
|
|
48
|
+
${truncate(evidenceBlock, evidenceBudget)}
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
${
|
|
42
|
-
return truncate(block, maxChars);
|
|
50
|
+
Retrieved sources:
|
|
51
|
+
${truncate(sourceBlock, sourceBudget)}`;
|
|
43
52
|
}
|
|
44
53
|
function buildGroundednessPrompt(input, options) {
|
|
45
54
|
return `Evaluate whether an agent answer is grounded in retrieved evidence.
|
|
@@ -144,8 +153,22 @@ function parseJudgeResponse(text, threshold) {
|
|
|
144
153
|
}
|
|
145
154
|
try {
|
|
146
155
|
const parsed = JSON.parse(json);
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
if (typeof parsed.score !== "number" || !Number.isFinite(parsed.score)) {
|
|
157
|
+
return {
|
|
158
|
+
score: 0,
|
|
159
|
+
pass: false,
|
|
160
|
+
explanation: "LLM judge response did not include a finite numeric score.",
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
if (typeof parsed.pass !== "boolean") {
|
|
164
|
+
return {
|
|
165
|
+
score: 0,
|
|
166
|
+
pass: false,
|
|
167
|
+
explanation: "LLM judge response did not include a boolean pass field.",
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const score = clampScore(parsed.score);
|
|
171
|
+
const modelPass = parsed.pass;
|
|
149
172
|
const unsupportedClaims = stringList(parsed.unsupportedClaims);
|
|
150
173
|
const missingEvidence = stringList(parsed.missingEvidence);
|
|
151
174
|
const details = [
|