@memberjunction/testing-engine 6.2.0-edge.1 → 6.2.0-edge.2
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/README.md +4 -1
- package/dist/decision-eval/corpus.d.ts +94 -0
- package/dist/decision-eval/corpus.d.ts.map +1 -0
- package/dist/decision-eval/corpus.js +144 -0
- package/dist/decision-eval/corpus.js.map +1 -0
- package/dist/decision-eval/discovery-baseline.d.ts +62 -0
- package/dist/decision-eval/discovery-baseline.d.ts.map +1 -0
- package/dist/decision-eval/discovery-baseline.js +90 -0
- package/dist/decision-eval/discovery-baseline.js.map +1 -0
- package/dist/decision-eval/discovery-corpus.d.ts +75 -0
- package/dist/decision-eval/discovery-corpus.d.ts.map +1 -0
- package/dist/decision-eval/discovery-corpus.js +110 -0
- package/dist/decision-eval/discovery-corpus.js.map +1 -0
- package/dist/decision-eval/discovery-mapping.d.ts +18 -0
- package/dist/decision-eval/discovery-mapping.d.ts.map +1 -0
- package/dist/decision-eval/discovery-mapping.js +21 -0
- package/dist/decision-eval/discovery-mapping.js.map +1 -0
- package/dist/decision-eval/discovery-metrics.d.ts +339 -0
- package/dist/decision-eval/discovery-metrics.d.ts.map +1 -0
- package/dist/decision-eval/discovery-metrics.js +401 -0
- package/dist/decision-eval/discovery-metrics.js.map +1 -0
- package/dist/decision-eval/discovery-scorecard.d.ts +96 -0
- package/dist/decision-eval/discovery-scorecard.d.ts.map +1 -0
- package/dist/decision-eval/discovery-scorecard.js +351 -0
- package/dist/decision-eval/discovery-scorecard.js.map +1 -0
- package/dist/decision-eval/discovery-suite.d.ts +201 -0
- package/dist/decision-eval/discovery-suite.d.ts.map +1 -0
- package/dist/decision-eval/discovery-suite.js +180 -0
- package/dist/decision-eval/discovery-suite.js.map +1 -0
- package/dist/decision-eval/discovery-types.d.ts +896 -0
- package/dist/decision-eval/discovery-types.d.ts.map +1 -0
- package/dist/decision-eval/discovery-types.js +211 -0
- package/dist/decision-eval/discovery-types.js.map +1 -0
- package/dist/decision-eval/index.d.ts +18 -0
- package/dist/decision-eval/index.d.ts.map +1 -0
- package/dist/decision-eval/index.js +18 -0
- package/dist/decision-eval/index.js.map +1 -0
- package/dist/decision-eval/metrics.d.ts +330 -0
- package/dist/decision-eval/metrics.d.ts.map +1 -0
- package/dist/decision-eval/metrics.js +574 -0
- package/dist/decision-eval/metrics.js.map +1 -0
- package/dist/decision-eval/output-paths.d.ts +119 -0
- package/dist/decision-eval/output-paths.d.ts.map +1 -0
- package/dist/decision-eval/output-paths.js +258 -0
- package/dist/decision-eval/output-paths.js.map +1 -0
- package/dist/decision-eval/point-mapping.d.ts +50 -0
- package/dist/decision-eval/point-mapping.d.ts.map +1 -0
- package/dist/decision-eval/point-mapping.js +83 -0
- package/dist/decision-eval/point-mapping.js.map +1 -0
- package/dist/decision-eval/scorecard.d.ts +190 -0
- package/dist/decision-eval/scorecard.d.ts.map +1 -0
- package/dist/decision-eval/scorecard.js +384 -0
- package/dist/decision-eval/scorecard.js.map +1 -0
- package/dist/decision-eval/suite.d.ts +244 -0
- package/dist/decision-eval/suite.d.ts.map +1 -0
- package/dist/decision-eval/suite.js +238 -0
- package/dist/decision-eval/suite.js.map +1 -0
- package/dist/decision-eval/types.d.ts +993 -0
- package/dist/decision-eval/types.d.ts.map +1 -0
- package/dist/decision-eval/types.js +227 -0
- package/dist/decision-eval/types.js.map +1 -0
- package/dist/drivers/AgentEvalDriver.d.ts +30 -1
- package/dist/drivers/AgentEvalDriver.d.ts.map +1 -1
- package/dist/drivers/AgentEvalDriver.js +145 -16
- package/dist/drivers/AgentEvalDriver.js.map +1 -1
- package/dist/drivers/DecisionEvalDriver.d.ts +297 -0
- package/dist/drivers/DecisionEvalDriver.d.ts.map +1 -0
- package/dist/drivers/DecisionEvalDriver.js +716 -0
- package/dist/drivers/DecisionEvalDriver.js.map +1 -0
- package/dist/drivers/PinnedDecisionRunner.d.ts +24 -0
- package/dist/drivers/PinnedDecisionRunner.d.ts.map +1 -0
- package/dist/drivers/PinnedDecisionRunner.js +24 -0
- package/dist/drivers/PinnedDecisionRunner.js.map +1 -0
- package/dist/drivers/PromptEvalDriver.d.ts.map +1 -1
- package/dist/drivers/PromptEvalDriver.js +8 -1
- package/dist/drivers/PromptEvalDriver.js.map +1 -1
- package/dist/drivers/RubricCalibrationTestDriver.d.ts +34 -0
- package/dist/drivers/RubricCalibrationTestDriver.d.ts.map +1 -0
- package/dist/drivers/RubricCalibrationTestDriver.js +193 -0
- package/dist/drivers/RubricCalibrationTestDriver.js.map +1 -0
- package/dist/drivers/calibration.d.ts +85 -0
- package/dist/drivers/calibration.d.ts.map +1 -0
- package/dist/drivers/calibration.js +191 -0
- package/dist/drivers/calibration.js.map +1 -0
- package/dist/drivers/index.d.ts +2 -0
- package/dist/drivers/index.d.ts.map +1 -1
- package/dist/drivers/index.js +2 -0
- package/dist/drivers/index.js.map +1 -1
- package/dist/engine/TestEngine.d.ts.map +1 -1
- package/dist/engine/TestEngine.js +14 -4
- package/dist/engine/TestEngine.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/oracles/DecisionJudgeOracle.d.ts +97 -0
- package/dist/oracles/DecisionJudgeOracle.d.ts.map +1 -0
- package/dist/oracles/DecisionJudgeOracle.js +230 -0
- package/dist/oracles/DecisionJudgeOracle.js.map +1 -0
- package/dist/oracles/DecisionLabelMatchOracle.d.ts +38 -0
- package/dist/oracles/DecisionLabelMatchOracle.d.ts.map +1 -0
- package/dist/oracles/DecisionLabelMatchOracle.js +96 -0
- package/dist/oracles/DecisionLabelMatchOracle.js.map +1 -0
- package/dist/oracles/DiscoveryLabelMatchOracle.d.ts +39 -0
- package/dist/oracles/DiscoveryLabelMatchOracle.d.ts.map +1 -0
- package/dist/oracles/DiscoveryLabelMatchOracle.js +88 -0
- package/dist/oracles/DiscoveryLabelMatchOracle.js.map +1 -0
- package/dist/oracles/LLMJudgeOracle.d.ts +2 -47
- package/dist/oracles/LLMJudgeOracle.d.ts.map +1 -1
- package/dist/oracles/LLMJudgeOracle.js +80 -149
- package/dist/oracles/LLMJudgeOracle.js.map +1 -1
- package/dist/oracles/RubricOracle.d.ts +51 -0
- package/dist/oracles/RubricOracle.d.ts.map +1 -0
- package/dist/oracles/RubricOracle.js +66 -0
- package/dist/oracles/RubricOracle.js.map +1 -0
- package/dist/oracles/index.d.ts +5 -0
- package/dist/oracles/index.d.ts.map +1 -1
- package/dist/oracles/index.js +5 -0
- package/dist/oracles/index.js.map +1 -1
- package/dist/oracles/inline-rubric.d.ts +25 -0
- package/dist/oracles/inline-rubric.d.ts.map +1 -0
- package/dist/oracles/inline-rubric.js +82 -0
- package/dist/oracles/inline-rubric.js.map +1 -0
- package/dist/oracles/judge-trace.d.ts +76 -0
- package/dist/oracles/judge-trace.d.ts.map +1 -0
- package/dist/oracles/judge-trace.js +125 -0
- package/dist/oracles/judge-trace.js.map +1 -0
- package/dist/oracles/promote-criteria.d.ts +57 -0
- package/dist/oracles/promote-criteria.d.ts.map +1 -0
- package/dist/oracles/promote-criteria.js +104 -0
- package/dist/oracles/promote-criteria.js.map +1 -0
- package/dist/oracles/rubric-resolution.d.ts +69 -0
- package/dist/oracles/rubric-resolution.d.ts.map +1 -0
- package/dist/oracles/rubric-resolution.js +110 -0
- package/dist/oracles/rubric-resolution.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/result-formatter.d.ts +5 -0
- package/dist/utils/result-formatter.d.ts.map +1 -1
- package/dist/utils/result-formatter.js +8 -2
- package/dist/utils/result-formatter.js.map +1 -1
- package/package.json +12 -10
|
@@ -4,45 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { IOracle } from './IOracle.js';
|
|
6
6
|
import { OracleInput, OracleConfig, OracleResult } from '../types.js';
|
|
7
|
-
/**
|
|
8
|
-
* LLM Judge Oracle.
|
|
9
|
-
*
|
|
10
|
-
* Uses an LLM to evaluate output quality based on custom criteria.
|
|
11
|
-
* Provides semantic evaluation beyond deterministic checks.
|
|
12
|
-
*
|
|
13
|
-
* Configuration:
|
|
14
|
-
* - criteria: Array of validation criteria (required)
|
|
15
|
-
* - model: Model to use for judging (default: from prompt or default model)
|
|
16
|
-
* - temperature: Temperature for LLM (default: 0.1 for consistency)
|
|
17
|
-
* - promptTemplate: Custom prompt template (optional, uses default if not provided)
|
|
18
|
-
* - strictMode: Require all criteria to pass (default: false, uses weighted scoring)
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const oracle = new LLMJudgeOracle();
|
|
23
|
-
* const result = await oracle.evaluate({
|
|
24
|
-
* actualOutput: { response: 'Sales by region report created successfully' },
|
|
25
|
-
* expectedOutput: {
|
|
26
|
-
* judgeValidationCriteria: [
|
|
27
|
-
* 'Response accurately answers the user\'s question',
|
|
28
|
-
* 'Response includes actionable information',
|
|
29
|
-
* 'Response is professional and clear'
|
|
30
|
-
* ]
|
|
31
|
-
* },
|
|
32
|
-
* contextUser
|
|
33
|
-
* }, {
|
|
34
|
-
* model: 'claude-sonnet-4',
|
|
35
|
-
* temperature: 0.1
|
|
36
|
-
* });
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
7
|
export declare class LLMJudgeOracle implements IOracle {
|
|
40
8
|
readonly type = "llm-judge";
|
|
41
|
-
/**
|
|
42
|
-
* Default prompt template for LLM judge.
|
|
43
|
-
* @private
|
|
44
|
-
*/
|
|
45
|
-
private readonly defaultPromptTemplate;
|
|
46
9
|
/**
|
|
47
10
|
* Evaluate output using LLM judge.
|
|
48
11
|
*
|
|
@@ -51,15 +14,7 @@ export declare class LLMJudgeOracle implements IOracle {
|
|
|
51
14
|
* @returns Oracle result with LLM judgment
|
|
52
15
|
*/
|
|
53
16
|
evaluate(input: OracleInput, config: OracleConfig): Promise<OracleResult>;
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
* @private
|
|
57
|
-
*/
|
|
58
|
-
private buildPrompt;
|
|
59
|
-
/**
|
|
60
|
-
* Parse LLM judgment response.
|
|
61
|
-
* @private
|
|
62
|
-
*/
|
|
63
|
-
private parseJudgment;
|
|
17
|
+
/** A failed result with this message and a score of 0. */
|
|
18
|
+
private failed;
|
|
64
19
|
}
|
|
65
20
|
//# sourceMappingURL=LLMJudgeOracle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LLMJudgeOracle.d.ts","sourceRoot":"","sources":["../../src/oracles/LLMJudgeOracle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"LLMJudgeOracle.d.ts","sourceRoot":"","sources":["../../src/oracles/LLMJudgeOracle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAoEnE,qBAAa,cAAe,YAAW,OAAO;IAC1C,QAAQ,CAAC,IAAI,eAAe;IAE5B;;;;;;OAMG;IACG,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAiE/E,0DAA0D;IAC1D,OAAO,CAAC,MAAM;CAGjB"}
|
|
@@ -2,21 +2,33 @@
|
|
|
2
2
|
* @fileoverview LLM Judge oracle implementation
|
|
3
3
|
* @module @memberjunction/testing-engine
|
|
4
4
|
*/
|
|
5
|
+
import { BuildJudgeTrace, ReadJudgeCriteria, ReadJudgeTimeoutMS } from './judge-trace.js';
|
|
6
|
+
import { InlineOracleResult, InlineVersion, ScoreInline } from './inline-rubric.js';
|
|
5
7
|
import { AIPromptParams } from '@memberjunction/ai-core-plus';
|
|
6
|
-
import { AIPromptRunner } from '@memberjunction/ai-prompts';
|
|
7
8
|
import { AIEngine } from '@memberjunction/aiengine';
|
|
9
|
+
import { AIPromptRunner } from '@memberjunction/ai-prompts';
|
|
10
|
+
import { RenderRubricEvaluatorPrompt } from '@memberjunction/rubrics';
|
|
11
|
+
/** The prompt whose model selection this judge uses. The rendered rubric text is the user message. */
|
|
12
|
+
const RUBRIC_EVALUATOR_PROMPT = 'Rubric Evaluator';
|
|
8
13
|
/**
|
|
9
14
|
* LLM Judge Oracle.
|
|
10
15
|
*
|
|
11
16
|
* Uses an LLM to evaluate output quality based on custom criteria.
|
|
12
17
|
* Provides semantic evaluation beyond deterministic checks.
|
|
13
18
|
*
|
|
19
|
+
* Criteria come from `expectedOutput.judgeValidationCriteria`, or else from `config.criteria`. Each is
|
|
20
|
+
* a string or `{ "criterion": "...", "weight": 2 }`, as for {@link DecisionJudgeOracle}. The weight
|
|
21
|
+
* is the leaf weight. A criterion the model does not answer stays unanswered. Malformed criteria fail
|
|
22
|
+
* the oracle without a call.
|
|
23
|
+
*
|
|
14
24
|
* Configuration:
|
|
15
25
|
* - criteria: Array of validation criteria (required)
|
|
16
|
-
* - model: Model
|
|
26
|
+
* - model: Model name or API name. When set, that model is required. Otherwise the Rubric Evaluator prompt selects one.
|
|
17
27
|
* - temperature: Temperature for LLM (default: 0.1 for consistency)
|
|
18
28
|
* - promptTemplate: Custom prompt template (optional, uses default if not provided)
|
|
19
29
|
* - strictMode: Require all criteria to pass (default: false, uses weighted scoring)
|
|
30
|
+
* - timeoutMS: How long to wait for each judge model call, in milliseconds (default: 120000, two
|
|
31
|
+
* minutes). A call that runs over fails the oracle.
|
|
20
32
|
*
|
|
21
33
|
* @example
|
|
22
34
|
* ```typescript
|
|
@@ -37,42 +49,28 @@ import { AIEngine } from '@memberjunction/aiengine';
|
|
|
37
49
|
* });
|
|
38
50
|
* ```
|
|
39
51
|
*/
|
|
52
|
+
function answersFromModel(raw, criteria) {
|
|
53
|
+
const parsed = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
54
|
+
const decisions = parsed?.decisions ?? [];
|
|
55
|
+
const scores = parsed?.criteriaScores ?? [];
|
|
56
|
+
const answers = [];
|
|
57
|
+
criteria.forEach((text, index) => {
|
|
58
|
+
const decision = decisions.find((item) => item.key === `c${index}` || item.criterion === text);
|
|
59
|
+
const scored = scores.find((item) => item.criterion === text);
|
|
60
|
+
if (!decision && !scored)
|
|
61
|
+
return;
|
|
62
|
+
const met = decision?.level === 'Met' || decision?.met === true || (typeof scored?.score === 'number' && scored.score >= 1);
|
|
63
|
+
answers.push({ index, met, rationale: decision?.rationale ?? scored?.explanation });
|
|
64
|
+
});
|
|
65
|
+
return answers;
|
|
66
|
+
}
|
|
67
|
+
/** Input, expected output, and actual output, inside the template's one untrusted fence. */
|
|
68
|
+
function judgeSubject(trace) {
|
|
69
|
+
return ['Input:', trace.Input ?? '', '', 'Expected:', trace.Expected ?? '', '', 'Actual:', trace.Actual ?? ''].join('\n');
|
|
70
|
+
}
|
|
40
71
|
export class LLMJudgeOracle {
|
|
41
72
|
constructor() {
|
|
42
73
|
this.type = 'llm-judge';
|
|
43
|
-
/**
|
|
44
|
-
* Default prompt template for LLM judge.
|
|
45
|
-
* @private
|
|
46
|
-
*/
|
|
47
|
-
this.defaultPromptTemplate = `You are an expert AI evaluator. Your task is to judge whether an AI agent's output meets the specified validation criteria.
|
|
48
|
-
|
|
49
|
-
**Input:**
|
|
50
|
-
{{input}}
|
|
51
|
-
|
|
52
|
-
**Expected Output Requirements:**
|
|
53
|
-
{{expected}}
|
|
54
|
-
|
|
55
|
-
**Actual Output:**
|
|
56
|
-
{{actual}}
|
|
57
|
-
|
|
58
|
-
**Validation Criteria:**
|
|
59
|
-
{{criteria}}
|
|
60
|
-
|
|
61
|
-
**Instructions:**
|
|
62
|
-
For each criterion, evaluate whether the actual output satisfies it. Provide:
|
|
63
|
-
1. A score from 0.0 to 1.0 for each criterion
|
|
64
|
-
2. A brief explanation for each score
|
|
65
|
-
3. An overall assessment
|
|
66
|
-
|
|
67
|
-
Respond in JSON format:
|
|
68
|
-
{
|
|
69
|
-
"criteriaScores": [
|
|
70
|
-
{ "criterion": "...", "score": 0.0-1.0, "explanation": "..." }
|
|
71
|
-
],
|
|
72
|
-
"overallScore": 0.0-1.0,
|
|
73
|
-
"overallAssessment": "...",
|
|
74
|
-
"passed": true/false
|
|
75
|
-
}`;
|
|
76
74
|
}
|
|
77
75
|
/**
|
|
78
76
|
* Evaluate output using LLM judge.
|
|
@@ -83,132 +81,65 @@ Respond in JSON format:
|
|
|
83
81
|
*/
|
|
84
82
|
async evaluate(input, config) {
|
|
85
83
|
try {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const criteria = input.expectedOutput?.judgeValidationCriteria ||
|
|
90
|
-
config.criteria;
|
|
91
|
-
if (!criteria || criteria.length === 0) {
|
|
92
|
-
return {
|
|
93
|
-
oracleType: this.type,
|
|
94
|
-
passed: false,
|
|
95
|
-
score: 0,
|
|
96
|
-
message: 'No validation criteria provided'
|
|
97
|
-
};
|
|
84
|
+
const criteria = ReadJudgeCriteria(input, config);
|
|
85
|
+
if (!criteria.Success) {
|
|
86
|
+
return this.failed(criteria.ErrorMessage);
|
|
98
87
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
88
|
+
const timeout = ReadJudgeTimeoutMS(config);
|
|
89
|
+
if (!timeout.Success) {
|
|
90
|
+
return this.failed(timeout.ErrorMessage);
|
|
91
|
+
}
|
|
92
|
+
const trace = BuildJudgeTrace(input);
|
|
93
|
+
const leaves = criteria.Value.map(item => ({ text: item.Criterion, weight: item.Weight }));
|
|
94
|
+
const texts = leaves.map(leaf => leaf.text);
|
|
95
|
+
const strict = config.strictMode === true;
|
|
96
|
+
const passThreshold = typeof config.passThreshold === 'number' ? config.passThreshold : 0.7;
|
|
97
|
+
const version = InlineVersion(leaves, strict, passThreshold);
|
|
98
|
+
const rendered = RenderRubricEvaluatorPrompt(version, { text: judgeSubject(trace) }, 'SinglePass');
|
|
99
|
+
await AIEngine.Instance.Config(false, input.contextUser);
|
|
100
|
+
const prompt = AIEngine.Instance.Prompts.find(item => item.Name === RUBRIC_EVALUATOR_PROMPT);
|
|
101
|
+
if (!prompt) {
|
|
102
|
+
return this.failed('The Rubric Evaluator prompt is not configured.');
|
|
108
103
|
}
|
|
109
|
-
// Prepare data for prompt template
|
|
110
|
-
const inputDefinition = input.test.InputDefinition ?
|
|
111
|
-
(typeof input.test.InputDefinition === 'string' ?
|
|
112
|
-
JSON.parse(input.test.InputDefinition) :
|
|
113
|
-
input.test.InputDefinition) :
|
|
114
|
-
{};
|
|
115
|
-
const promptData = {
|
|
116
|
-
input: JSON.stringify(inputDefinition, null, 2),
|
|
117
|
-
expected: JSON.stringify(input.expectedOutput, null, 2),
|
|
118
|
-
actual: JSON.stringify(input.actualOutput, null, 2),
|
|
119
|
-
criteria: criteria.map((c, i) => `${i + 1}. ${c}`).join('\n')
|
|
120
|
-
};
|
|
121
|
-
// Execute LLM judgment
|
|
122
104
|
const promptParams = new AIPromptParams();
|
|
123
|
-
promptParams.prompt =
|
|
124
|
-
promptParams.
|
|
105
|
+
promptParams.prompt = prompt;
|
|
106
|
+
promptParams.systemPromptOverride = rendered;
|
|
107
|
+
// The Rubric Evaluator record stores TemplateText and may have no TemplateID. A user
|
|
108
|
+
// message still reaches the model in that case; an override alone would not.
|
|
109
|
+
promptParams.templateMessageRole = 'none';
|
|
110
|
+
promptParams.conversationMessages = [{ role: 'user', content: rendered }];
|
|
111
|
+
promptParams.data = { criteria: texts, input: trace.Input, expected: trace.Expected, actual: trace.Actual, model: config.model };
|
|
125
112
|
promptParams.contextUser = input.contextUser;
|
|
113
|
+
promptParams.timeoutMS = timeout.Value;
|
|
114
|
+
const requestedModel = typeof config.model === 'string' ? config.model.trim() : '';
|
|
115
|
+
if (requestedModel) {
|
|
116
|
+
const model = AIEngine.Instance.Models.find(item => item.Name === requestedModel || item.APIName === requestedModel);
|
|
117
|
+
if (!model) {
|
|
118
|
+
return this.failed(`Judge model "${requestedModel}" was not found.`);
|
|
119
|
+
}
|
|
120
|
+
promptParams.override = { modelId: model.ID };
|
|
121
|
+
}
|
|
126
122
|
const runner = new AIPromptRunner();
|
|
127
123
|
const result = await runner.ExecutePrompt(promptParams);
|
|
128
124
|
if (!result.success) {
|
|
129
|
-
return {
|
|
130
|
-
oracleType: this.type,
|
|
131
|
-
passed: false,
|
|
132
|
-
score: 0,
|
|
133
|
-
message: `LLM judgment failed: ${result.errorMessage}`
|
|
134
|
-
};
|
|
125
|
+
return this.failed(`LLM judgment failed: ${result.errorMessage}`);
|
|
135
126
|
}
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return
|
|
144
|
-
oracleType: this.type,
|
|
145
|
-
passed,
|
|
146
|
-
score: judgment.overallScore,
|
|
147
|
-
message: judgment.overallAssessment,
|
|
148
|
-
details: {
|
|
149
|
-
criteriaScores: judgment.criteriaScores,
|
|
150
|
-
llmModel: config.model || 'default',
|
|
151
|
-
llmCost: result.cost
|
|
152
|
-
}
|
|
153
|
-
};
|
|
127
|
+
const answers = answersFromModel(result.result, texts);
|
|
128
|
+
const scored = ScoreInline(leaves, answers, { strict, passThreshold });
|
|
129
|
+
const evidence = [];
|
|
130
|
+
for (const answer of answers)
|
|
131
|
+
evidence[answer.index] = answer.rationale;
|
|
132
|
+
const report = InlineOracleResult(texts, scored, evidence);
|
|
133
|
+
report.details = { ...report.details, llmModel: config.model || 'default', llmCost: result.cost };
|
|
134
|
+
return report;
|
|
154
135
|
}
|
|
155
136
|
catch (error) {
|
|
156
|
-
return {
|
|
157
|
-
oracleType: this.type,
|
|
158
|
-
passed: false,
|
|
159
|
-
score: 0,
|
|
160
|
-
message: `LLM judge error: ${error.message}`
|
|
161
|
-
};
|
|
137
|
+
return this.failed(`LLM judge error: ${error.message}`);
|
|
162
138
|
}
|
|
163
139
|
}
|
|
164
|
-
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
*/
|
|
168
|
-
buildPrompt(input, criteria, customTemplate) {
|
|
169
|
-
const template = customTemplate || this.defaultPromptTemplate;
|
|
170
|
-
// Format input data
|
|
171
|
-
const inputStr = JSON.stringify(input.test.InputDefinition, null, 2);
|
|
172
|
-
const expectedStr = JSON.stringify(input.expectedOutput, null, 2);
|
|
173
|
-
const actualStr = JSON.stringify(input.actualOutput, null, 2);
|
|
174
|
-
const criteriaStr = criteria.map((c, i) => `${i + 1}. ${c}`).join('\n');
|
|
175
|
-
// Replace placeholders. Function replacements throughout: these are test
|
|
176
|
-
// inputs, expected values and actual outputs, all of which routinely
|
|
177
|
-
// contain `$` — and a string replacement would expand `$&`/`` $` ``/`$'`,
|
|
178
|
-
// silently feeding the judge a prompt that differs from the data under
|
|
179
|
-
// test. See issue #3171.
|
|
180
|
-
return template
|
|
181
|
-
.replace('{{input}}', () => inputStr)
|
|
182
|
-
.replace('{{expected}}', () => expectedStr)
|
|
183
|
-
.replace('{{actual}}', () => actualStr)
|
|
184
|
-
.replace('{{criteria}}', () => criteriaStr);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Parse LLM judgment response.
|
|
188
|
-
* @private
|
|
189
|
-
*/
|
|
190
|
-
parseJudgment(response) {
|
|
191
|
-
try {
|
|
192
|
-
// Try to extract JSON from response
|
|
193
|
-
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
194
|
-
if (!jsonMatch) {
|
|
195
|
-
throw new Error('No JSON found in LLM response');
|
|
196
|
-
}
|
|
197
|
-
const parsed = JSON.parse(jsonMatch[0]);
|
|
198
|
-
return {
|
|
199
|
-
criteriaScores: parsed.criteriaScores || [],
|
|
200
|
-
overallScore: parsed.overallScore || 0,
|
|
201
|
-
overallAssessment: parsed.overallAssessment || 'No assessment provided'
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
catch (error) {
|
|
205
|
-
// Fallback to simple parsing
|
|
206
|
-
return {
|
|
207
|
-
criteriaScores: [],
|
|
208
|
-
overallScore: 0,
|
|
209
|
-
overallAssessment: `Failed to parse LLM response: ${response.substring(0, 200)}`
|
|
210
|
-
};
|
|
211
|
-
}
|
|
140
|
+
/** A failed result with this message and a score of 0. */
|
|
141
|
+
failed(message) {
|
|
142
|
+
return { oracleType: this.type, passed: false, score: 0, message };
|
|
212
143
|
}
|
|
213
144
|
}
|
|
214
145
|
//# sourceMappingURL=LLMJudgeOracle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LLMJudgeOracle.js","sourceRoot":"","sources":["../../src/oracles/LLMJudgeOracle.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"LLMJudgeOracle.js","sourceRoot":"","sources":["../../src/oracles/LLMJudgeOracle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAEtE,sGAAsG;AACtG,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,SAAS,gBAAgB,CAAC,GAAY,EAAE,QAAkB;IACtD,MAAM,MAAM,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,C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MAAM,CAAC,IAAI,EAAE,CAAC;YAC9G,OAAO,MAAM,CAAC;QAElB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,IAAI,CAAC,MAAM,CAAC,oBAAqB,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QACvE,CAAC;IACL,CAAC;IAED,0DAA0D;IAClD,MAAM,CAAC,OAAe;QAC1B,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;IACvE,CAAC;CACJ"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import '@memberjunction/ai-agents';
|
|
2
|
+
import type { OracleConfig, OracleInput, OracleResult } from '../types.js';
|
|
3
|
+
import type { IOracle } from './IOracle.js';
|
|
4
|
+
export interface RubricOracleEngine {
|
|
5
|
+
EvaluateRecord(input: {
|
|
6
|
+
rubricId?: string;
|
|
7
|
+
versionId?: string;
|
|
8
|
+
subjectEntityName: string;
|
|
9
|
+
subjectRecordId: string;
|
|
10
|
+
contextEntityName?: string;
|
|
11
|
+
contextRecordId?: string;
|
|
12
|
+
passThreshold?: number | null;
|
|
13
|
+
evaluator?: 'LLM' | 'Deterministic' | 'AI';
|
|
14
|
+
content?: {
|
|
15
|
+
text?: string;
|
|
16
|
+
data?: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
}): Promise<{
|
|
19
|
+
evaluationId: string;
|
|
20
|
+
score: number | null;
|
|
21
|
+
outcome: string | null;
|
|
22
|
+
displayScore?: number | null;
|
|
23
|
+
criteria: {
|
|
24
|
+
key: string;
|
|
25
|
+
normalizedScore: number | null;
|
|
26
|
+
rationale?: string;
|
|
27
|
+
}[];
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Judges a test run with a rubric. The subject is the test run and the context
|
|
32
|
+
* is the test. A host can inject the engine; otherwise the call uses the input provider.
|
|
33
|
+
*/
|
|
34
|
+
export declare class RubricOracle implements IOracle {
|
|
35
|
+
private readonly engine?;
|
|
36
|
+
readonly type = "rubric";
|
|
37
|
+
constructor(engine?: RubricOracleEngine | undefined);
|
|
38
|
+
evaluate(input: OracleInput, config: OracleConfig): Promise<OracleResult>;
|
|
39
|
+
}
|
|
40
|
+
/** The output the driver already has. The test-run row is not saved until later. */
|
|
41
|
+
export declare function RubricOracleContent(input: {
|
|
42
|
+
test?: {
|
|
43
|
+
InputDefinition?: unknown;
|
|
44
|
+
};
|
|
45
|
+
expectedOutput?: unknown;
|
|
46
|
+
actualOutput?: unknown;
|
|
47
|
+
}): {
|
|
48
|
+
text?: string;
|
|
49
|
+
data: Record<string, unknown>;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=RubricOracle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RubricOracle.d.ts","sourceRoot":"","sources":["../../src/oracles/RubricOracle.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,WAAW,kBAAkB;IAC/B,cAAc,CAAC,KAAK,EAAE;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,eAAe,EAAE,MAAM,CAAC;QACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC9B,SAAS,CAAC,EAAE,KAAK,GAAG,eAAe,GAAG,IAAI,CAAC;QAC3C,OAAO,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,CAAC;KAC/D,GAAG,OAAO,CAAC;QACR,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,QAAQ,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;YAAC,SAAS,CAAC,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;KACnF,CAAC,CAAC;CACN;AAED;;;GAGG;AACH,qBAAa,YAAa,YAAW,OAAO;IAGrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAF3C,SAAgB,IAAI,YAAY;gBAEI,MAAM,CAAC,EAAE,kBAAkB,YAAA;IAElD,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;CA0CzF;AAED,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CASvL"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import '@memberjunction/ai-agents';
|
|
2
|
+
import { ProviderRubricEngine } from '@memberjunction/rubrics';
|
|
3
|
+
/**
|
|
4
|
+
* Judges a test run with a rubric. The subject is the test run and the context
|
|
5
|
+
* is the test. A host can inject the engine; otherwise the call uses the input provider.
|
|
6
|
+
*/
|
|
7
|
+
export class RubricOracle {
|
|
8
|
+
constructor(engine) {
|
|
9
|
+
this.engine = engine;
|
|
10
|
+
this.type = 'rubric';
|
|
11
|
+
}
|
|
12
|
+
async evaluate(input, config) {
|
|
13
|
+
const settings = config;
|
|
14
|
+
const provider = input.provider;
|
|
15
|
+
const engine = this.engine ?? (provider ? ProviderRubricEngine(provider, input.contextUser) : undefined);
|
|
16
|
+
if (!engine) {
|
|
17
|
+
return { oracleType: this.type, passed: false, score: 0, message: 'No rubric engine is configured.' };
|
|
18
|
+
}
|
|
19
|
+
if (!input.testRunId) {
|
|
20
|
+
return { oracleType: this.type, passed: false, score: 0, message: 'subject not found or not readable' };
|
|
21
|
+
}
|
|
22
|
+
const result = await engine.EvaluateRecord({
|
|
23
|
+
rubricId: settings.rubricId,
|
|
24
|
+
versionId: settings.rubricVersionId,
|
|
25
|
+
subjectEntityName: 'MJ: Test Runs',
|
|
26
|
+
subjectRecordId: input.testRunId,
|
|
27
|
+
contextEntityName: 'MJ: Tests',
|
|
28
|
+
contextRecordId: input.test?.ID,
|
|
29
|
+
passThreshold: settings.passThreshold ?? null,
|
|
30
|
+
evaluator: 'LLM',
|
|
31
|
+
content: RubricOracleContent(input),
|
|
32
|
+
});
|
|
33
|
+
const passed = result.outcome === 'Passed' || result.outcome === 'Scored';
|
|
34
|
+
const label = settings.versionLabel ?? settings.rubricVersionId ?? 'published';
|
|
35
|
+
const shown = result.displayScore ?? result.score ?? 0;
|
|
36
|
+
return {
|
|
37
|
+
oracleType: this.type,
|
|
38
|
+
passed,
|
|
39
|
+
score: result.score ?? 0,
|
|
40
|
+
message: `${settings.rubricId ?? 'rubric'} v${label}: ${result.outcome} (${shown})`,
|
|
41
|
+
details: {
|
|
42
|
+
RubricEvaluationID: result.evaluationId,
|
|
43
|
+
RubricVersionLabel: label,
|
|
44
|
+
Outcome: result.outcome,
|
|
45
|
+
Criteria: result.criteria.map(item => ({
|
|
46
|
+
Key: item.key,
|
|
47
|
+
Name: item.key,
|
|
48
|
+
NormalizedScore: item.normalizedScore,
|
|
49
|
+
Rationale: item.rationale,
|
|
50
|
+
})),
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** The output the driver already has. The test-run row is not saved until later. */
|
|
56
|
+
export function RubricOracleContent(input) {
|
|
57
|
+
return {
|
|
58
|
+
text: typeof input.actualOutput === 'string' ? input.actualOutput : undefined,
|
|
59
|
+
data: {
|
|
60
|
+
input: input.test?.InputDefinition,
|
|
61
|
+
expectedOutput: input.expectedOutput,
|
|
62
|
+
actualOutput: input.actualOutput,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=RubricOracle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RubricOracle.js","sourceRoot":"","sources":["../../src/oracles/RubricOracle.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAwB/D;;;GAGG;AACH,MAAM,OAAO,YAAY;IAGrB,YAAoC,MAA2B;QAA3B,WAAM,GAAN,MAAM,CAAqB;QAF/C,SAAI,GAAG,QAAQ,CAAC;IAEkC,CAAC;IAE5D,KAAK,CAAC,QAAQ,CAAC,KAAkB,EAAE,MAAoB;QAC1D,MAAM,QAAQ,GAAG,MAAwG,CAAC;QAC1H,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,oBAAoB,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACzG,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,OAA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AAE,MAAM,CAAC,OAAO;gBACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBACnC,GAAG,EAAE,IAAI,CAAC,GAAG;oBACb,IAAI,EAAE,IAAI,CAAC,GAAG;oBACd,eAAe,EAAE,IAAI,CAAC,eAAe;oBACrC,SAAS,EAAE,IAAI,CAAC,SAAS;iBAC5B,CAAC,CAAC;aACN;SACJ,CAAC;IACN,CAAC;CACJ;AAED,oFAAoF;AACpF,MAAM,UAAU,mBAAmB,CAAC,KAAiG;IACjI,OAAO;QACH,IAAI,EAAE,OAAO,KAAK,CAAC,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;QAC7E,IAAI,EAAE;YACF,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,eAAe;YAClC,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,YAAY,EAAE,KAAK,CAAC,YAAY;SACnC;KACJ,CAAC;AACN,CAAC"}
|
package/dist/oracles/index.d.ts
CHANGED
|
@@ -6,7 +6,12 @@ export * from './SchemaValidatorOracle.js';
|
|
|
6
6
|
export * from './TraceValidatorOracle.js';
|
|
7
7
|
export * from './TraceSubAgentValidatorOracle.js';
|
|
8
8
|
export * from './AgentDecisionOracle.js';
|
|
9
|
+
export * from './DecisionLabelMatchOracle.js';
|
|
10
|
+
export * from './DiscoveryLabelMatchOracle.js';
|
|
9
11
|
export * from './LLMJudgeOracle.js';
|
|
12
|
+
export * from './DecisionJudgeOracle.js';
|
|
10
13
|
export * from './ExactMatchOracle.js';
|
|
11
14
|
export * from './SQLValidatorOracle.js';
|
|
15
|
+
export * from './RubricOracle.js';
|
|
16
|
+
export * from './rubric-resolution.js';
|
|
12
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/oracles/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/oracles/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
|
package/dist/oracles/index.js
CHANGED
|
@@ -6,7 +6,12 @@ export * from './SchemaValidatorOracle.js';
|
|
|
6
6
|
export * from './TraceValidatorOracle.js';
|
|
7
7
|
export * from './TraceSubAgentValidatorOracle.js';
|
|
8
8
|
export * from './AgentDecisionOracle.js';
|
|
9
|
+
export * from './DecisionLabelMatchOracle.js';
|
|
10
|
+
export * from './DiscoveryLabelMatchOracle.js';
|
|
9
11
|
export * from './LLMJudgeOracle.js';
|
|
12
|
+
export * from './DecisionJudgeOracle.js';
|
|
10
13
|
export * from './ExactMatchOracle.js';
|
|
11
14
|
export * from './SQLValidatorOracle.js';
|
|
15
|
+
export * from './RubricOracle.js';
|
|
16
|
+
export * from './rubric-resolution.js';
|
|
12
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oracles/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oracles/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type RubricScoreResult, type RubricVersionSnapshot } from '@memberjunction/rubrics-base';
|
|
2
|
+
import type { OracleResult } from '../types.js';
|
|
3
|
+
/** One binary leaf. Weight defaults to 1. A weight of 0 is kept and does not enter the weighted mean. */
|
|
4
|
+
export type InlineCriterion = {
|
|
5
|
+
text: string;
|
|
6
|
+
weight?: number;
|
|
7
|
+
};
|
|
8
|
+
/** A binary inline rubric. Met = 1 and Not met = 0. There is no version row. */
|
|
9
|
+
export declare function InlineVersion(criteria: Array<string | InlineCriterion>, strict: boolean, passThreshold: number): RubricVersionSnapshot;
|
|
10
|
+
export declare function ScoreInline(criteria: Array<string | InlineCriterion>, answers: {
|
|
11
|
+
index: number;
|
|
12
|
+
met: boolean;
|
|
13
|
+
rationale?: string;
|
|
14
|
+
}[], options: {
|
|
15
|
+
strict?: boolean;
|
|
16
|
+
passThreshold?: number;
|
|
17
|
+
}): RubricScoreResult;
|
|
18
|
+
/** Computer Use verdicts, reported in the same inline details shape. Not stored as a RubricEvaluation. */
|
|
19
|
+
export declare function InlineOracleFromVerdicts(verdicts: {
|
|
20
|
+
criterion: string;
|
|
21
|
+
met: boolean;
|
|
22
|
+
evidence?: string;
|
|
23
|
+
}[], passThreshold?: number): OracleResult;
|
|
24
|
+
export declare function InlineOracleResult(criteria: string[], scored: RubricScoreResult, evidence?: (string | undefined)[]): OracleResult;
|
|
25
|
+
//# sourceMappingURL=inline-rubric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-rubric.d.ts","sourceRoot":"","sources":["../../src/oracles/inline-rubric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,iBAAiB,EAAE,KAAK,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACjH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,yGAAyG;AACzG,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAMhE,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,GAAG,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,qBAAqB,CAmCtI;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,GAAG,eAAe,CAAC,EAAE,OAAO,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,EAAE,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,iBA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