oh-my-knowledge 0.0.1 → 0.19.0
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/LICENSE +21 -0
- package/README.md +600 -322
- package/README.zh.md +724 -0
- package/dist/src/analysis/coverage-analyzer.d.ts +57 -0
- package/dist/src/analysis/coverage-analyzer.d.ts.map +1 -0
- package/dist/src/analysis/coverage-analyzer.js +262 -0
- package/dist/src/analysis/coverage-analyzer.js.map +1 -0
- package/dist/src/analysis/gap-analyzer.d.ts +114 -0
- package/dist/src/analysis/gap-analyzer.d.ts.map +1 -0
- package/dist/src/analysis/gap-analyzer.js +439 -0
- package/dist/src/analysis/gap-analyzer.js.map +1 -0
- package/dist/src/analysis/hedging-classifier.d.ts +34 -0
- package/dist/src/analysis/hedging-classifier.d.ts.map +1 -0
- package/dist/src/analysis/hedging-classifier.js +144 -0
- package/dist/src/analysis/hedging-classifier.js.map +1 -0
- package/dist/src/analysis/report-diagnostics.d.ts +9 -0
- package/dist/src/analysis/report-diagnostics.d.ts.map +1 -0
- package/dist/src/analysis/report-diagnostics.js +631 -0
- package/dist/src/analysis/report-diagnostics.js.map +1 -0
- package/dist/src/authoring/evolver.d.ts +64 -0
- package/dist/src/authoring/evolver.d.ts.map +1 -0
- package/dist/src/authoring/evolver.js +275 -0
- package/dist/src/authoring/evolver.js.map +1 -0
- package/dist/src/authoring/generator.d.ts +13 -0
- package/dist/src/authoring/generator.d.ts.map +1 -0
- package/dist/src/authoring/generator.js +60 -0
- package/dist/src/authoring/generator.js.map +1 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +1012 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/eval-core/cache.d.ts +11 -0
- package/dist/src/eval-core/cache.d.ts.map +1 -0
- package/dist/src/eval-core/cache.js +53 -0
- package/dist/src/eval-core/cache.js.map +1 -0
- package/dist/src/eval-core/ci-gates.d.ts +17 -0
- package/dist/src/eval-core/ci-gates.d.ts.map +1 -0
- package/dist/src/eval-core/ci-gates.js +42 -0
- package/dist/src/eval-core/ci-gates.js.map +1 -0
- package/dist/src/eval-core/dependency-checker.d.ts +37 -0
- package/dist/src/eval-core/dependency-checker.d.ts.map +1 -0
- package/dist/src/eval-core/dependency-checker.js +280 -0
- package/dist/src/eval-core/dependency-checker.js.map +1 -0
- package/dist/src/eval-core/evaluation-execution.d.ts +26 -0
- package/dist/src/eval-core/evaluation-execution.d.ts.map +1 -0
- package/dist/src/eval-core/evaluation-execution.js +196 -0
- package/dist/src/eval-core/evaluation-execution.js.map +1 -0
- package/dist/src/eval-core/evaluation-job.d.ts +50 -0
- package/dist/src/eval-core/evaluation-job.d.ts.map +1 -0
- package/dist/src/eval-core/evaluation-job.js +114 -0
- package/dist/src/eval-core/evaluation-job.js.map +1 -0
- package/dist/src/eval-core/evaluation-reporting.d.ts +28 -0
- package/dist/src/eval-core/evaluation-reporting.d.ts.map +1 -0
- package/dist/src/eval-core/evaluation-reporting.js +123 -0
- package/dist/src/eval-core/evaluation-reporting.js.map +1 -0
- package/dist/src/eval-core/execution-strategy.d.ts +11 -0
- package/dist/src/eval-core/execution-strategy.d.ts.map +1 -0
- package/dist/src/eval-core/execution-strategy.js +121 -0
- package/dist/src/eval-core/execution-strategy.js.map +1 -0
- package/dist/src/eval-core/fact-checker.d.ts +25 -0
- package/dist/src/eval-core/fact-checker.d.ts.map +1 -0
- package/dist/src/eval-core/fact-checker.js +66 -0
- package/dist/src/eval-core/fact-checker.js.map +1 -0
- package/dist/src/eval-core/schema.d.ts +30 -0
- package/dist/src/eval-core/schema.d.ts.map +1 -0
- package/dist/src/eval-core/schema.js +195 -0
- package/dist/src/eval-core/schema.js.map +1 -0
- package/dist/src/eval-core/statistics.d.ts +86 -0
- package/dist/src/eval-core/statistics.d.ts.map +1 -0
- package/dist/src/eval-core/statistics.js +210 -0
- package/dist/src/eval-core/statistics.js.map +1 -0
- package/dist/src/eval-core/task-planner.d.ts +4 -0
- package/dist/src/eval-core/task-planner.d.ts.map +1 -0
- package/dist/src/eval-core/task-planner.js +33 -0
- package/dist/src/eval-core/task-planner.js.map +1 -0
- package/dist/src/eval-workflows/each-evaluation-workflow.d.ts +137 -0
- package/dist/src/eval-workflows/each-evaluation-workflow.d.ts.map +1 -0
- package/dist/src/eval-workflows/each-evaluation-workflow.js +174 -0
- package/dist/src/eval-workflows/each-evaluation-workflow.js.map +1 -0
- package/dist/src/eval-workflows/evaluation-pipeline.d.ts +42 -0
- package/dist/src/eval-workflows/evaluation-pipeline.d.ts.map +1 -0
- package/dist/src/eval-workflows/evaluation-pipeline.js +218 -0
- package/dist/src/eval-workflows/evaluation-pipeline.js.map +1 -0
- package/dist/src/eval-workflows/evaluation-preparation.d.ts +64 -0
- package/dist/src/eval-workflows/evaluation-preparation.d.ts.map +1 -0
- package/dist/src/eval-workflows/evaluation-preparation.js +90 -0
- package/dist/src/eval-workflows/evaluation-preparation.js.map +1 -0
- package/dist/src/eval-workflows/run-evaluation.d.ts +111 -0
- package/dist/src/eval-workflows/run-evaluation.d.ts.map +1 -0
- package/dist/src/eval-workflows/run-evaluation.js +272 -0
- package/dist/src/eval-workflows/run-evaluation.js.map +1 -0
- package/dist/src/executors/anthropic-api.d.ts +3 -0
- package/dist/src/executors/anthropic-api.d.ts.map +1 -0
- package/dist/src/executors/anthropic-api.js +43 -0
- package/dist/src/executors/anthropic-api.js.map +1 -0
- package/dist/src/executors/claude-cli.d.ts +3 -0
- package/dist/src/executors/claude-cli.d.ts.map +1 -0
- package/dist/src/executors/claude-cli.js +103 -0
- package/dist/src/executors/claude-cli.js.map +1 -0
- package/dist/src/executors/claude-sdk-trace.d.ts +10 -0
- package/dist/src/executors/claude-sdk-trace.d.ts.map +1 -0
- package/dist/src/executors/claude-sdk-trace.js +100 -0
- package/dist/src/executors/claude-sdk-trace.js.map +1 -0
- package/dist/src/executors/claude-sdk.d.ts +3 -0
- package/dist/src/executors/claude-sdk.d.ts.map +1 -0
- package/dist/src/executors/claude-sdk.js +160 -0
- package/dist/src/executors/claude-sdk.js.map +1 -0
- package/dist/src/executors/gemini.d.ts +3 -0
- package/dist/src/executors/gemini.d.ts.map +1 -0
- package/dist/src/executors/gemini.js +78 -0
- package/dist/src/executors/gemini.js.map +1 -0
- package/dist/src/executors/index.d.ts +7 -0
- package/dist/src/executors/index.d.ts.map +1 -0
- package/dist/src/executors/index.js +22 -0
- package/dist/src/executors/index.js.map +1 -0
- package/dist/src/executors/openai-api.d.ts +3 -0
- package/dist/src/executors/openai-api.d.ts.map +1 -0
- package/dist/src/executors/openai-api.js +40 -0
- package/dist/src/executors/openai-api.js.map +1 -0
- package/dist/src/executors/openai-cli.d.ts +3 -0
- package/dist/src/executors/openai-cli.d.ts.map +1 -0
- package/dist/src/executors/openai-cli.js +60 -0
- package/dist/src/executors/openai-cli.js.map +1 -0
- package/dist/src/executors/script.d.ts +3 -0
- package/dist/src/executors/script.d.ts.map +1 -0
- package/dist/src/executors/script.js +63 -0
- package/dist/src/executors/script.js.map +1 -0
- package/dist/src/executors/shared.d.ts +117 -0
- package/dist/src/executors/shared.d.ts.map +1 -0
- package/dist/src/executors/shared.js +49 -0
- package/dist/src/executors/shared.js.map +1 -0
- package/dist/src/grading/assertions.d.ts +18 -0
- package/dist/src/grading/assertions.d.ts.map +1 -0
- package/dist/src/grading/assertions.js +239 -0
- package/dist/src/grading/assertions.js.map +1 -0
- package/dist/src/grading/index.d.ts +26 -0
- package/dist/src/grading/index.d.ts.map +1 -0
- package/dist/src/grading/index.js +98 -0
- package/dist/src/grading/index.js.map +1 -0
- package/dist/src/grading/judge.d.ts +13 -0
- package/dist/src/grading/judge.d.ts.map +1 -0
- package/dist/src/grading/judge.js +98 -0
- package/dist/src/grading/judge.js.map +1 -0
- package/dist/src/grading/layered-scores.d.ts +13 -0
- package/dist/src/grading/layered-scores.d.ts.map +1 -0
- package/dist/src/grading/layered-scores.js +62 -0
- package/dist/src/grading/layered-scores.js.map +1 -0
- package/dist/src/inputs/eval-config.d.ts +13 -0
- package/dist/src/inputs/eval-config.d.ts.map +1 -0
- package/dist/src/inputs/eval-config.js +136 -0
- package/dist/src/inputs/eval-config.js.map +1 -0
- package/dist/src/inputs/load-samples.d.ts +16 -0
- package/dist/src/inputs/load-samples.d.ts.map +1 -0
- package/dist/src/inputs/load-samples.js +51 -0
- package/dist/src/inputs/load-samples.js.map +1 -0
- package/dist/src/inputs/mcp-resolver.d.ts +50 -0
- package/dist/src/inputs/mcp-resolver.d.ts.map +1 -0
- package/dist/src/inputs/mcp-resolver.js +307 -0
- package/dist/src/inputs/mcp-resolver.js.map +1 -0
- package/dist/src/inputs/skill-loader.d.ts +18 -0
- package/dist/src/inputs/skill-loader.d.ts.map +1 -0
- package/dist/src/inputs/skill-loader.js +222 -0
- package/dist/src/inputs/skill-loader.js.map +1 -0
- package/dist/src/inputs/url-fetcher.d.ts +19 -0
- package/dist/src/inputs/url-fetcher.d.ts.map +1 -0
- package/dist/src/inputs/url-fetcher.js +241 -0
- package/dist/src/inputs/url-fetcher.js.map +1 -0
- package/dist/src/observability/skill-health-analyzer.d.ts +83 -0
- package/dist/src/observability/skill-health-analyzer.d.ts.map +1 -0
- package/dist/src/observability/skill-health-analyzer.js +238 -0
- package/dist/src/observability/skill-health-analyzer.js.map +1 -0
- package/dist/src/observability/trace-adapter.d.ts +75 -0
- package/dist/src/observability/trace-adapter.d.ts.map +1 -0
- package/dist/src/observability/trace-adapter.js +367 -0
- package/dist/src/observability/trace-adapter.js.map +1 -0
- package/dist/src/renderer/html-renderer.d.ts +9 -0
- package/dist/src/renderer/html-renderer.d.ts.map +1 -0
- package/dist/src/renderer/html-renderer.js +360 -0
- package/dist/src/renderer/html-renderer.js.map +1 -0
- package/dist/src/renderer/layout.d.ts +13 -0
- package/dist/src/renderer/layout.d.ts.map +1 -0
- package/dist/src/renderer/layout.js +582 -0
- package/dist/src/renderer/layout.js.map +1 -0
- package/dist/src/renderer/skill-health-renderer.d.ts +20 -0
- package/dist/src/renderer/skill-health-renderer.d.ts.map +1 -0
- package/dist/src/renderer/skill-health-renderer.js +253 -0
- package/dist/src/renderer/skill-health-renderer.js.map +1 -0
- package/dist/src/renderer/summary.d.ts +21 -0
- package/dist/src/renderer/summary.d.ts.map +1 -0
- package/dist/src/renderer/summary.js +1072 -0
- package/dist/src/renderer/summary.js.map +1 -0
- package/dist/src/renderer/table.d.ts +3 -0
- package/dist/src/renderer/table.d.ts.map +1 -0
- package/dist/src/renderer/table.js +134 -0
- package/dist/src/renderer/table.js.map +1 -0
- package/dist/src/renderer/trends.d.ts +6 -0
- package/dist/src/renderer/trends.d.ts.map +1 -0
- package/dist/src/renderer/trends.js +127 -0
- package/dist/src/renderer/trends.js.map +1 -0
- package/dist/src/server/job-store.d.ts +4 -0
- package/dist/src/server/job-store.d.ts.map +1 -0
- package/dist/src/server/job-store.js +68 -0
- package/dist/src/server/job-store.js.map +1 -0
- package/dist/src/server/report-server.d.ts +17 -0
- package/dist/src/server/report-server.d.ts.map +1 -0
- package/dist/src/server/report-server.js +591 -0
- package/dist/src/server/report-server.js.map +1 -0
- package/dist/src/server/report-store.d.ts +44 -0
- package/dist/src/server/report-store.d.ts.map +1 -0
- package/dist/src/server/report-store.js +190 -0
- package/dist/src/server/report-store.js.map +1 -0
- package/dist/src/types.d.ts +559 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +53 -5
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { delimiter, join } from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
export const execFileAsync = promisify(execFile);
|
|
6
|
+
export const DEFAULT_MODEL = 'sonnet';
|
|
7
|
+
export const JUDGE_MODEL = 'haiku';
|
|
8
|
+
export const DEFAULT_TIMEOUT_MS = 120_000;
|
|
9
|
+
export const MAX_BUFFER = 10 * 1024 * 1024;
|
|
10
|
+
export function asErrorLike(err) {
|
|
11
|
+
return typeof err === 'object' && err !== null ? err : {};
|
|
12
|
+
}
|
|
13
|
+
export function errorMessage(err, fallback = 'unknown error') {
|
|
14
|
+
const details = asErrorLike(err);
|
|
15
|
+
return details.message || fallback;
|
|
16
|
+
}
|
|
17
|
+
export function parseJson(content) {
|
|
18
|
+
return JSON.parse(content);
|
|
19
|
+
}
|
|
20
|
+
export function buildExecEnv(skillDir) {
|
|
21
|
+
const proxyUrl = process.env.CCV_PROXY_URL || undefined;
|
|
22
|
+
const env = proxyUrl
|
|
23
|
+
? { ...process.env, ANTHROPIC_BASE_URL: proxyUrl }
|
|
24
|
+
: { ...process.env };
|
|
25
|
+
if (skillDir) {
|
|
26
|
+
const nodeBin = join(skillDir, 'node_modules', '.bin');
|
|
27
|
+
if (existsSync(nodeBin)) {
|
|
28
|
+
env.PATH = `${nodeBin}${env.PATH ? delimiter + env.PATH : ''}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return env;
|
|
32
|
+
}
|
|
33
|
+
export function timeoutExecResult(timeoutMs, durationMs) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
error: `execution timed out after ${timeoutMs / 1000}s`,
|
|
37
|
+
durationMs,
|
|
38
|
+
durationApiMs: 0,
|
|
39
|
+
inputTokens: 0,
|
|
40
|
+
outputTokens: 0,
|
|
41
|
+
cacheReadTokens: 0,
|
|
42
|
+
cacheCreationTokens: 0,
|
|
43
|
+
costUSD: 0,
|
|
44
|
+
output: null,
|
|
45
|
+
stopReason: 'timeout',
|
|
46
|
+
numTurns: 0,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/executors/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oB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AO,GAAG,IAAI,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;QACvD,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YACxB,GAAG,CAAC,IAAI,GAAG,GAAG,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACjE,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,SAAiB,EAAE,UAAkB;IACrE,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,6BAA6B,SAAS,GAAG,IAAI,GAAG;QACvD,UAAU;QACV,aAAa,EAAE,CAAC;QAChB,WAAW,EAAE,CAAC;QACd,YAAY,EAAE,CAAC;QACf,eAAe,EAAE,CAAC;QAClB,mBAAmB,EAAE,CAAC;QACtB,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,SAAS;QACrB,QAAQ,EAAE,CAAC;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Assertion, AssertionResults, ExecutorFn, Sample, ToolCallInfo } from '../types.js';
|
|
2
|
+
export declare const ASYNC_ASSERTION_TYPES: Set<string>;
|
|
3
|
+
export interface AsyncAssertionContext {
|
|
4
|
+
executor: ExecutorFn;
|
|
5
|
+
judgeModel: string;
|
|
6
|
+
sample: Sample;
|
|
7
|
+
samplesDir: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function ratioToScore(ratio: number): number;
|
|
10
|
+
export declare function validateJsonSchema(data: unknown, schema: Record<string, unknown>): boolean;
|
|
11
|
+
export declare function runAssertions(output: string, assertions: Assertion[], context?: {
|
|
12
|
+
costUSD?: number;
|
|
13
|
+
durationMs?: number;
|
|
14
|
+
numTurns?: number;
|
|
15
|
+
toolCalls?: ToolCallInfo[];
|
|
16
|
+
}): AssertionResults;
|
|
17
|
+
export declare function runAsyncAssertions(output: string, assertions: Assertion[], { executor, judgeModel, sample, samplesDir }: AsyncAssertionContext): Promise<AssertionResults>;
|
|
18
|
+
//# sourceMappingURL=assertions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../../../src/grading/assertions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAmB,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMlH,eAAO,MAAM,qBAAqB,aAA6C,CAAC;AAEhF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,UAAU,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAwBD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAQ1F;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,YAAY,EAAE,CAAA;CAAO,GAAG,gBAAgB,CAqI/L;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAkFhL"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import _Ajv from 'ajv';
|
|
3
|
+
const Ajv = _Ajv.default ?? _Ajv;
|
|
4
|
+
const ajv = new Ajv();
|
|
5
|
+
const CUSTOM_ASSERTION_TIMEOUT_MS = 30_000;
|
|
6
|
+
export const ASYNC_ASSERTION_TYPES = new Set(['semantic_similarity', 'custom']);
|
|
7
|
+
function getErrorMessage(err) {
|
|
8
|
+
return err instanceof Error ? err.message : String(err);
|
|
9
|
+
}
|
|
10
|
+
export function ratioToScore(ratio) {
|
|
11
|
+
return Number((1 + ratio * 4).toFixed(2));
|
|
12
|
+
}
|
|
13
|
+
export function validateJsonSchema(data, schema) {
|
|
14
|
+
if (!schema || typeof schema !== 'object')
|
|
15
|
+
return true;
|
|
16
|
+
try {
|
|
17
|
+
const validate = ajv.compile(schema);
|
|
18
|
+
return validate(data);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function runAssertions(output, assertions, context = {}) {
|
|
25
|
+
const outputLower = output.toLowerCase();
|
|
26
|
+
const details = [];
|
|
27
|
+
const toolCalls = context.toolCalls || [];
|
|
28
|
+
const toolNames = toolCalls.map((tc) => tc.tool.toLowerCase());
|
|
29
|
+
for (const assertion of assertions) {
|
|
30
|
+
const weight = assertion.weight ?? 1;
|
|
31
|
+
let passed = false;
|
|
32
|
+
switch (assertion.type) {
|
|
33
|
+
case 'contains':
|
|
34
|
+
passed = outputLower.includes(String(assertion.value).toLowerCase());
|
|
35
|
+
break;
|
|
36
|
+
case 'not_contains':
|
|
37
|
+
passed = !outputLower.includes(String(assertion.value).toLowerCase());
|
|
38
|
+
break;
|
|
39
|
+
case 'regex': {
|
|
40
|
+
const flags = assertion.flags || 'i';
|
|
41
|
+
const re = new RegExp(assertion.pattern, flags);
|
|
42
|
+
passed = re.test(output);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case 'min_length':
|
|
46
|
+
passed = output.length >= assertion.value;
|
|
47
|
+
break;
|
|
48
|
+
case 'max_length':
|
|
49
|
+
passed = output.length <= assertion.value;
|
|
50
|
+
break;
|
|
51
|
+
case 'json_valid':
|
|
52
|
+
try {
|
|
53
|
+
JSON.parse(output);
|
|
54
|
+
passed = true;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
passed = false;
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
case 'json_schema':
|
|
61
|
+
try {
|
|
62
|
+
const data = JSON.parse(output);
|
|
63
|
+
passed = validateJsonSchema(data, assertion.schema);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
passed = false;
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case 'starts_with':
|
|
70
|
+
passed = outputLower.startsWith(String(assertion.value).toLowerCase());
|
|
71
|
+
break;
|
|
72
|
+
case 'ends_with':
|
|
73
|
+
passed = outputLower.endsWith(String(assertion.value).toLowerCase());
|
|
74
|
+
break;
|
|
75
|
+
case 'equals':
|
|
76
|
+
passed = output.trim() === String(assertion.value).trim();
|
|
77
|
+
break;
|
|
78
|
+
case 'not_equals':
|
|
79
|
+
passed = output.trim() !== String(assertion.value).trim();
|
|
80
|
+
break;
|
|
81
|
+
case 'word_count_min':
|
|
82
|
+
passed = output.split(/\s+/).filter(Boolean).length >= assertion.value;
|
|
83
|
+
break;
|
|
84
|
+
case 'word_count_max':
|
|
85
|
+
passed = output.split(/\s+/).filter(Boolean).length <= assertion.value;
|
|
86
|
+
break;
|
|
87
|
+
case 'contains_all':
|
|
88
|
+
passed = (assertion.values || []).every((v) => outputLower.includes(String(v).toLowerCase()));
|
|
89
|
+
break;
|
|
90
|
+
case 'contains_any':
|
|
91
|
+
passed = (assertion.values || []).some((v) => outputLower.includes(String(v).toLowerCase()));
|
|
92
|
+
break;
|
|
93
|
+
case 'cost_max':
|
|
94
|
+
passed = (context.costUSD ?? Infinity) <= assertion.value;
|
|
95
|
+
break;
|
|
96
|
+
case 'latency_max':
|
|
97
|
+
passed = (context.durationMs ?? Infinity) <= assertion.value;
|
|
98
|
+
break;
|
|
99
|
+
case 'turns_max':
|
|
100
|
+
passed = (context.numTurns ?? Infinity) <= assertion.value;
|
|
101
|
+
break;
|
|
102
|
+
case 'turns_min':
|
|
103
|
+
passed = (context.numTurns ?? 0) >= assertion.value;
|
|
104
|
+
break;
|
|
105
|
+
case 'tools_called':
|
|
106
|
+
passed = (assertion.values || []).every((v) => toolNames.includes(String(v).toLowerCase()));
|
|
107
|
+
break;
|
|
108
|
+
case 'tools_not_called':
|
|
109
|
+
passed = (assertion.values || []).every((v) => !toolNames.includes(String(v).toLowerCase()));
|
|
110
|
+
break;
|
|
111
|
+
case 'tools_count_max':
|
|
112
|
+
passed = toolCalls.length <= assertion.value;
|
|
113
|
+
break;
|
|
114
|
+
case 'tools_count_min':
|
|
115
|
+
passed = toolCalls.length >= assertion.value;
|
|
116
|
+
break;
|
|
117
|
+
case 'tool_output_contains': {
|
|
118
|
+
const sep = String(assertion.value).indexOf(':');
|
|
119
|
+
if (sep > 0) {
|
|
120
|
+
const targetTool = String(assertion.value).slice(0, sep).toLowerCase();
|
|
121
|
+
const expected = String(assertion.value).slice(sep + 1).toLowerCase();
|
|
122
|
+
passed = toolCalls.some((tc) => tc.tool.toLowerCase() === targetTool &&
|
|
123
|
+
String(tc.output || '').toLowerCase().includes(expected));
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case 'tool_input_contains': {
|
|
128
|
+
const sep = String(assertion.value).indexOf(':');
|
|
129
|
+
if (sep > 0) {
|
|
130
|
+
const targetTool = String(assertion.value).slice(0, sep).toLowerCase();
|
|
131
|
+
const expected = String(assertion.value).slice(sep + 1).toLowerCase();
|
|
132
|
+
passed = toolCalls.some((tc) => tc.tool.toLowerCase() === targetTool &&
|
|
133
|
+
JSON.stringify(tc.input || '').toLowerCase().includes(expected));
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
default:
|
|
138
|
+
passed = false;
|
|
139
|
+
}
|
|
140
|
+
details.push({
|
|
141
|
+
type: assertion.type,
|
|
142
|
+
value: assertion.value ?? assertion.pattern ?? assertion.values?.join(', ') ?? '',
|
|
143
|
+
weight,
|
|
144
|
+
passed,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const totalWeight = details.reduce((s, d) => s + d.weight, 0);
|
|
148
|
+
const passedWeight = details.filter((d) => d.passed).reduce((s, d) => s + d.weight, 0);
|
|
149
|
+
const passedCount = details.filter((d) => d.passed).length;
|
|
150
|
+
const ratio = totalWeight > 0 ? passedWeight / totalWeight : 0;
|
|
151
|
+
return {
|
|
152
|
+
passed: passedCount,
|
|
153
|
+
total: details.length,
|
|
154
|
+
score: ratioToScore(ratio),
|
|
155
|
+
details,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
export async function runAsyncAssertions(output, assertions, { executor, judgeModel, sample, samplesDir }) {
|
|
159
|
+
const details = [];
|
|
160
|
+
let asyncCostUSD = 0;
|
|
161
|
+
for (const assertion of assertions) {
|
|
162
|
+
const weight = assertion.weight ?? 1;
|
|
163
|
+
let passed = false;
|
|
164
|
+
let message = '';
|
|
165
|
+
if (assertion.type === 'semantic_similarity') {
|
|
166
|
+
const reference = assertion.reference || '';
|
|
167
|
+
const judgePrompt = [
|
|
168
|
+
'请判断以下两段文本的语义相似度。',
|
|
169
|
+
'',
|
|
170
|
+
'## 参考文本',
|
|
171
|
+
reference,
|
|
172
|
+
'',
|
|
173
|
+
'## 待评估文本',
|
|
174
|
+
output,
|
|
175
|
+
'',
|
|
176
|
+
'请返回 JSON(不要包含 markdown 代码块标记):',
|
|
177
|
+
'{"score": <1-5的整数>, "reason": "<简短理由>"}',
|
|
178
|
+
'',
|
|
179
|
+
'评分:1=完全无关, 2=略有关联, 3=部分相似, 4=大致相同, 5=高度一致',
|
|
180
|
+
].join('\n');
|
|
181
|
+
const result = await executor({
|
|
182
|
+
model: judgeModel,
|
|
183
|
+
system: '你是语义相似度评审员。只返回 JSON,不要其他内容。',
|
|
184
|
+
prompt: judgePrompt,
|
|
185
|
+
});
|
|
186
|
+
asyncCostUSD += result.costUSD || 0;
|
|
187
|
+
if (result.ok) {
|
|
188
|
+
try {
|
|
189
|
+
const jsonMatch = result.output.trim().match(/\{[\s\S]*\}/);
|
|
190
|
+
if (jsonMatch) {
|
|
191
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
192
|
+
const score = Number(parsed.score) || 0;
|
|
193
|
+
const threshold = assertion.threshold ?? 3;
|
|
194
|
+
passed = score >= threshold;
|
|
195
|
+
message = parsed.reason || '';
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
process.stderr.write(`[omk] semantic_similarity judge returned non-JSON: ${result.output.slice(0, 100)}\n`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (parseErr) {
|
|
202
|
+
process.stderr.write(`[omk] semantic_similarity judge parse error: ${getErrorMessage(parseErr)}\n`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else if (assertion.type === 'custom') {
|
|
207
|
+
try {
|
|
208
|
+
const fnPath = resolve(samplesDir, assertion.fn);
|
|
209
|
+
const mod = await import(fnPath);
|
|
210
|
+
const fn = mod.default || mod.check;
|
|
211
|
+
if (!fn)
|
|
212
|
+
throw new Error('custom assertion module must export default or check');
|
|
213
|
+
const result = await Promise.race([
|
|
214
|
+
fn(output, { sample, assertion }),
|
|
215
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error(`custom assertion timed out (${CUSTOM_ASSERTION_TIMEOUT_MS / 1000}s)`)), CUSTOM_ASSERTION_TIMEOUT_MS)),
|
|
216
|
+
]);
|
|
217
|
+
passed = Boolean(result.pass);
|
|
218
|
+
message = result.message || '';
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
passed = false;
|
|
222
|
+
message = `custom assertion error: ${getErrorMessage(err)}`;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
details.push({
|
|
226
|
+
type: assertion.type,
|
|
227
|
+
value: assertion.reference || assertion.fn || '',
|
|
228
|
+
weight,
|
|
229
|
+
passed,
|
|
230
|
+
...(message && { message }),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
const totalWeight = details.reduce((s, d) => s + d.weight, 0);
|
|
234
|
+
const passedWeight = details.filter((d) => d.passed).reduce((s, d) => s + d.weight, 0);
|
|
235
|
+
const passedCount = details.filter((d) => d.passed).length;
|
|
236
|
+
const ratio = totalWeight > 0 ? passedWeight / totalWeight : 0;
|
|
237
|
+
return { passed: passedCount, total: details.length, score: ratioToScore(ratio), details, judgeCostUSD: asyncCostUSD };
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=assertions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertions.js","sourceRoot":"","sources":["../../../src/grading/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,IAAI,MAAM,KAAK,CAAC;AAGvB,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC;AACjC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AACtB,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAE3C,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC,CAAC;AA2BhF,SAAS,eAAe,CAAC,GAAY;IACnC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,OA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AC;QACH,CAAC;QAED,OAAO,CAAC,IAAI,CAAC;YACX,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,KAAK,EAAE,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE;YAChD,MAAM;YACN,MAAM;YACN,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC9D,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACvF,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;IAC3D,MAAM,KAAK,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAE/D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AACzH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mixed grading: deterministic assertions + LLM judge + multi-dimensional scoring.
|
|
3
|
+
*/
|
|
4
|
+
import type { GradeResult, ExecutorFn, Sample, ToolCallInfo, TurnInfo } from '../types.js';
|
|
5
|
+
interface GradeOptions {
|
|
6
|
+
output: string;
|
|
7
|
+
sample: Sample;
|
|
8
|
+
executor: ExecutorFn;
|
|
9
|
+
judgeModel: string;
|
|
10
|
+
allowLlmJudge?: boolean;
|
|
11
|
+
execMetrics?: {
|
|
12
|
+
costUSD?: number;
|
|
13
|
+
durationMs?: number;
|
|
14
|
+
numTurns?: number;
|
|
15
|
+
toolCalls?: ToolCallInfo[];
|
|
16
|
+
turns?: TurnInfo[];
|
|
17
|
+
};
|
|
18
|
+
samplesDir?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Grade a model output against a sample's criteria.
|
|
22
|
+
*/
|
|
23
|
+
export declare function grade({ output, sample, executor, judgeModel, allowLlmJudge, execMetrics, samplesDir }: GradeOptions): Promise<GradeResult>;
|
|
24
|
+
export { runAssertions, validateJsonSchema } from './assertions.js';
|
|
25
|
+
export { buildTraceSummary } from './judge.js';
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/grading/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAoB,WAAW,EAAkC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK7I,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,UAAU,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAA;KAAE,CAAC;IAC3H,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAsB,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAoB,EAAE,WAAgB,EAAE,UAAgB,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CA+FlK;AACD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mixed grading: deterministic assertions + LLM judge + multi-dimensional scoring.
|
|
3
|
+
*/
|
|
4
|
+
import { ASYNC_ASSERTION_TYPES, ratioToScore, runAssertions, runAsyncAssertions } from './assertions.js';
|
|
5
|
+
import { buildTraceSummary, llmJudge } from './judge.js';
|
|
6
|
+
import { computeLayeredScores } from './layered-scores.js';
|
|
7
|
+
/**
|
|
8
|
+
* Grade a model output against a sample's criteria.
|
|
9
|
+
*/
|
|
10
|
+
export async function grade({ output, sample, executor, judgeModel, allowLlmJudge = true, execMetrics = {}, samplesDir = '.' }) {
|
|
11
|
+
const results = { compositeScore: 0 };
|
|
12
|
+
// 1. Deterministic assertions (pure, no LLM)
|
|
13
|
+
const allAssertions = sample.assertions || [];
|
|
14
|
+
const syncAssertions = allAssertions.filter((a) => !ASYNC_ASSERTION_TYPES.has(a.type));
|
|
15
|
+
const asyncAssertions = allAssertions.filter((assertion) => {
|
|
16
|
+
if (!ASYNC_ASSERTION_TYPES.has(assertion.type))
|
|
17
|
+
return false;
|
|
18
|
+
if (allowLlmJudge)
|
|
19
|
+
return true;
|
|
20
|
+
return assertion.type === 'custom';
|
|
21
|
+
});
|
|
22
|
+
if (syncAssertions.length > 0) {
|
|
23
|
+
results.assertions = runAssertions(output, syncAssertions, { ...execMetrics });
|
|
24
|
+
}
|
|
25
|
+
// 1b. Async assertions (custom JS, semantic_similarity)
|
|
26
|
+
if (asyncAssertions.length > 0 && executor != null) {
|
|
27
|
+
const asyncResults = await runAsyncAssertions(output, asyncAssertions, {
|
|
28
|
+
executor, judgeModel, sample, samplesDir,
|
|
29
|
+
});
|
|
30
|
+
if (results.assertions) {
|
|
31
|
+
// Merge async results into sync results
|
|
32
|
+
results.assertions.details.push(...asyncResults.details);
|
|
33
|
+
results.assertions.total += asyncResults.total;
|
|
34
|
+
results.assertions.passed += asyncResults.passed;
|
|
35
|
+
// Recompute score from merged details
|
|
36
|
+
const allDetails = results.assertions.details;
|
|
37
|
+
const totalWeight = allDetails.reduce((s, d) => s + d.weight, 0);
|
|
38
|
+
const passedWeight = allDetails.filter((d) => d.passed).reduce((s, d) => s + d.weight, 0);
|
|
39
|
+
const ratio = totalWeight > 0 ? passedWeight / totalWeight : 0;
|
|
40
|
+
results.assertions.score = ratioToScore(ratio);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
results.assertions = asyncResults;
|
|
44
|
+
}
|
|
45
|
+
// Accumulate async assertion judge cost
|
|
46
|
+
if (asyncResults.judgeCostUSD && asyncResults.judgeCostUSD > 0) {
|
|
47
|
+
results.judgeCostUSD = (results.judgeCostUSD || 0) + asyncResults.judgeCostUSD;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// 2. LLM scoring
|
|
51
|
+
// Build execution trace summary for agent-aware judging
|
|
52
|
+
const traceSummary = buildTraceSummary(execMetrics.turns, execMetrics.toolCalls);
|
|
53
|
+
if (allowLlmJudge && sample.dimensions && Object.keys(sample.dimensions).length > 0) {
|
|
54
|
+
// Multi-dimensional scoring
|
|
55
|
+
results.dimensions = {};
|
|
56
|
+
for (const [dim, rubric] of Object.entries(sample.dimensions)) {
|
|
57
|
+
results.dimensions[dim] = await llmJudge({
|
|
58
|
+
output,
|
|
59
|
+
rubric,
|
|
60
|
+
prompt: sample.prompt,
|
|
61
|
+
executor,
|
|
62
|
+
model: judgeModel,
|
|
63
|
+
traceSummary,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const dimValues = Object.values(results.dimensions);
|
|
67
|
+
const dimScores = dimValues.map((d) => d.score).filter((s) => s > 0);
|
|
68
|
+
if (dimScores.length > 0) {
|
|
69
|
+
results.llmScore = Number((dimScores.reduce((a, b) => a + b, 0) / dimScores.length).toFixed(2));
|
|
70
|
+
}
|
|
71
|
+
// Accumulate judge cost from all dimensions (add to any existing async assertion cost)
|
|
72
|
+
const dimCost = dimValues.reduce((s, d) => s + (d.judgeCostUSD || 0), 0);
|
|
73
|
+
if (dimCost > 0)
|
|
74
|
+
results.judgeCostUSD = (results.judgeCostUSD || 0) + dimCost;
|
|
75
|
+
}
|
|
76
|
+
else if (allowLlmJudge && sample.rubric) {
|
|
77
|
+
// Single rubric scoring
|
|
78
|
+
const judge = await llmJudge({
|
|
79
|
+
output,
|
|
80
|
+
rubric: sample.rubric,
|
|
81
|
+
prompt: sample.prompt,
|
|
82
|
+
executor,
|
|
83
|
+
model: judgeModel,
|
|
84
|
+
traceSummary,
|
|
85
|
+
});
|
|
86
|
+
results.llmScore = judge.score;
|
|
87
|
+
results.llmReason = judge.reason;
|
|
88
|
+
results.judgeCostUSD = (results.judgeCostUSD || 0) + (judge.judgeCostUSD || 0);
|
|
89
|
+
}
|
|
90
|
+
// 3. Layered scores + composite
|
|
91
|
+
const { compositeScore, layeredScores } = computeLayeredScores(results);
|
|
92
|
+
results.compositeScore = compositeScore;
|
|
93
|
+
results.layeredScores = layeredScores;
|
|
94
|
+
return results;
|
|
95
|
+
}
|
|
96
|
+
export { runAssertions, validateJsonSchema } from './assertions.js';
|
|
97
|
+
export { buildTraceSummary } from './judge.js';
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/grading/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,kBA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|
+
interface LlmJudgeOptions {
|
|
3
|
+
output: string;
|
|
4
|
+
rubric: string;
|
|
5
|
+
prompt: string;
|
|
6
|
+
executor: ExecutorFn;
|
|
7
|
+
model: string;
|
|
8
|
+
traceSummary?: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function buildTraceSummary(turns?: TurnInfo[], toolCalls?: ToolCallInfo[]): string | null;
|
|
11
|
+
export declare function llmJudge({ output, rubric, prompt, executor, model, traceSummary }: LlmJudgeOptions): Promise<DimensionResult>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=judge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"judge.d.ts","sourceRoot":"","sources":["../../../src/grading/judge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOvF,UAAU,eAAe;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,UAAU,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAMD,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,EAAE,YAAY,EAAE,GAAG,MAAM,GAAG,IAAI,CA6C/F;AAED,wBAAsB,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAiDnI"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
function getErrorMessage(err) {
|
|
2
|
+
return err instanceof Error ? err.message : String(err);
|
|
3
|
+
}
|
|
4
|
+
export function buildTraceSummary(turns, toolCalls) {
|
|
5
|
+
if ((!turns || turns.length === 0) && (!toolCalls || toolCalls.length === 0))
|
|
6
|
+
return null;
|
|
7
|
+
const lines = [];
|
|
8
|
+
if (toolCalls && toolCalls.length > 0) {
|
|
9
|
+
lines.push(`共调用 ${toolCalls.length} 个工具:`);
|
|
10
|
+
const successCount = toolCalls.filter((tc) => tc.success).length;
|
|
11
|
+
const failureCount = toolCalls.length - successCount;
|
|
12
|
+
lines.push(` 成功 ${successCount}/${toolCalls.length}`);
|
|
13
|
+
if (failureCount > 0)
|
|
14
|
+
lines.push(` 失败 ${failureCount}/${toolCalls.length}`);
|
|
15
|
+
const dist = {};
|
|
16
|
+
for (const tc of toolCalls) {
|
|
17
|
+
dist[tc.tool] = (dist[tc.tool] || 0) + 1;
|
|
18
|
+
}
|
|
19
|
+
lines.push(` 工具分布:${Object.entries(dist).map(([k, v]) => `${k}(${v})`).join(', ')}`);
|
|
20
|
+
const failedTools = toolCalls.filter((tc) => !tc.success).map((tc) => tc.tool);
|
|
21
|
+
if (failedTools.length > 0) {
|
|
22
|
+
lines.push(` 失败工具:${[...new Set(failedTools)].join(', ')}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (turns && turns.length > 0) {
|
|
26
|
+
lines.push('');
|
|
27
|
+
lines.push('执行轨迹摘要:');
|
|
28
|
+
const assistantTurns = turns.filter((turn) => turn.role === 'assistant').length;
|
|
29
|
+
const toolTurns = turns.filter((turn) => turn.role === 'tool').length;
|
|
30
|
+
lines.push(` 共 ${turns.length} 步(assistant ${assistantTurns} / tool ${toolTurns})`);
|
|
31
|
+
const maxTurns = Math.min(turns.length, 10);
|
|
32
|
+
for (let i = 0; i < maxTurns; i++) {
|
|
33
|
+
const t = turns[i];
|
|
34
|
+
const preview = t.content.slice(0, 100) + (t.content.length > 100 ? '...' : '');
|
|
35
|
+
if (t.role === 'assistant' && t.toolCalls?.length) {
|
|
36
|
+
lines.push(` [${i + 1}] assistant: 调用 ${t.toolCalls.map((tc) => tc.tool).join(', ')}`);
|
|
37
|
+
}
|
|
38
|
+
else if (t.role === 'tool') {
|
|
39
|
+
lines.push(` [${i + 1}] tool: ${preview}`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
lines.push(` [${i + 1}] ${t.role}: ${preview}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (turns.length > maxTurns)
|
|
46
|
+
lines.push(` ... 还有 ${turns.length - maxTurns} 步`);
|
|
47
|
+
}
|
|
48
|
+
return lines.join('\n');
|
|
49
|
+
}
|
|
50
|
+
export async function llmJudge({ output, rubric, prompt, executor, model, traceSummary }) {
|
|
51
|
+
const traceSection = traceSummary
|
|
52
|
+
? ['', '## Agent 执行过程', traceSummary, '', '请同时考虑执行过程的合理性(工具选择、步骤效率、错误恢复)。']
|
|
53
|
+
: [];
|
|
54
|
+
const judgePrompt = [
|
|
55
|
+
'请对以下 AI 输出进行质量评分。',
|
|
56
|
+
'',
|
|
57
|
+
'## 原始任务',
|
|
58
|
+
prompt,
|
|
59
|
+
'',
|
|
60
|
+
'## 评分标准',
|
|
61
|
+
rubric,
|
|
62
|
+
'',
|
|
63
|
+
'## AI 输出',
|
|
64
|
+
output,
|
|
65
|
+
...traceSection,
|
|
66
|
+
'',
|
|
67
|
+
'请返回 JSON(不要包含 markdown 代码块标记):',
|
|
68
|
+
'{"score": <1-5的整数>, "reason": "<简短理由>"}',
|
|
69
|
+
'',
|
|
70
|
+
'评分标准:1=完全不达标, 2=部分涉及, 3=基本达标, 4=较好, 5=优秀',
|
|
71
|
+
].join('\n');
|
|
72
|
+
const result = await executor({
|
|
73
|
+
model,
|
|
74
|
+
system: '你是一个严格的 AI 输出质量评审员。只返回 JSON,不要其他内容。',
|
|
75
|
+
prompt: judgePrompt,
|
|
76
|
+
});
|
|
77
|
+
if (!result.ok)
|
|
78
|
+
return { score: 0, reason: `judge error: ${result.error}`, judgeCostUSD: result.costUSD };
|
|
79
|
+
try {
|
|
80
|
+
const text = result.output.trim();
|
|
81
|
+
const jsonMatch = text.match(/\{[\s\S]*\}/);
|
|
82
|
+
if (!jsonMatch) {
|
|
83
|
+
process.stderr.write(`[omk] LLM judge returned non-JSON: ${text.slice(0, 100)}\n`);
|
|
84
|
+
return { score: 0, reason: 'judge returned non-JSON', judgeCostUSD: result.costUSD };
|
|
85
|
+
}
|
|
86
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
87
|
+
return {
|
|
88
|
+
score: Number(parsed.score) || 0,
|
|
89
|
+
reason: String(parsed.reason || ''),
|
|
90
|
+
judgeCostUSD: result.costUSD,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (parseErr) {
|
|
94
|
+
process.stderr.write(`[omk] LLM judge parse error: ${getErrorMessage(parseErr)}\n`);
|
|
95
|
+
return { score: 0, reason: 'failed to parse judge response', judgeCostUSD: result.costUSD };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=judge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"judge.js","sourceRoot":"","sources":["../../../src/grading/judge.ts"],"names":[],"mappings":"AAgBA,SAAS,eAAe,CAAC,GAAY;IACnC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAkB,EAAE,SAA0B;IAC9E,IAAI,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAE1F,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtC,KAAK,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC,MAAM,OAAO,CAAC,CAAC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: {
|
|
4
|
+
details?: AssertionDetail[];
|
|
5
|
+
};
|
|
6
|
+
llmScore?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function computeLayeredScores(results: CompositeInput): {
|
|
9
|
+
compositeScore: number;
|
|
10
|
+
layeredScores: LayeredScores;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=layered-scores.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layered-scores.d.ts","sourceRoot":"","sources":["../../../src/grading/layered-scores.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA+ClE,UAAU,cAAc;IACtB,UAAU,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,eAAe,EAAE,CAAA;KAAE,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,GAAG;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,aAAa,CAAA;CAAE,CAqBtH"}
|