peerbench 0.0.6 → 0.0.8
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/dist/aggregators/abstract.d.ts +10 -0
- package/dist/aggregators/index.d.ts +2 -67
- package/dist/aggregators/llm/avg.d.ts +26 -0
- package/dist/benchmarks/examples/echo-basic/index.d.ts +4 -0
- package/dist/benchmarks/examples/echo-basic/runner.d.ts +273 -0
- package/dist/benchmarks/examples/echo-basic/schema-sets/echo.v1.d.ts +241 -0
- package/dist/benchmarks/examples/echo-basic/storages/json.d.ts +14 -0
- package/dist/benchmarks/examples/echo-basic/storages/text.d.ts +24 -0
- package/dist/benchmarks/examples/exact-match-scorer/index.d.ts +4 -0
- package/dist/benchmarks/examples/exact-match-scorer/runner.d.ts +428 -0
- package/dist/benchmarks/examples/exact-match-scorer/schema-sets/exact-match.v1.d.ts +287 -0
- package/dist/benchmarks/examples/exact-match-scorer/scorer.d.ts +30 -0
- package/dist/benchmarks/examples/exact-match-scorer/storages/json.d.ts +8 -0
- package/dist/benchmarks/examples/text-transform/index.d.ts +4 -0
- package/dist/benchmarks/examples/text-transform/runner.d.ts +524 -0
- package/dist/benchmarks/examples/text-transform/schema-sets/echo.v1.d.ts +211 -0
- package/dist/benchmarks/examples/text-transform/schema-sets/namespace.d.ts +1 -0
- package/dist/benchmarks/examples/text-transform/schema-sets/reverse.v1.d.ts +216 -0
- package/dist/benchmarks/examples/text-transform/storages/json.d.ts +9 -0
- package/dist/benchmarks/index.d.ts +1 -1667
- package/dist/benchmarks/index.js +4 -4
- package/dist/benchmarks/peerbench/index.d.ts +5 -0
- package/dist/benchmarks/peerbench/runner.d.ts +754 -0
- package/dist/benchmarks/peerbench/schema-sets/mcq.v1.d.ts +261 -0
- package/dist/benchmarks/peerbench/schema-sets/multi-turn.v1.d.ts +351 -0
- package/dist/benchmarks/peerbench/schema-sets/qa.v1.d.ts +256 -0
- package/dist/benchmarks/peerbench/storages/json.d.ts +10 -0
- package/dist/{chunk-DNGT4SJC.js → chunk-3JHDJEY3.js} +16 -7
- package/dist/chunk-3JHDJEY3.js.map +1 -0
- package/dist/{chunk-3JF7SHLC.js → chunk-SMLNDQFX.js} +16 -7
- package/dist/chunk-SMLNDQFX.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/peerbench.d.ts +6 -0
- package/dist/errors/polyfill.d.ts +1 -0
- package/dist/examples/basic.d.ts +1 -0
- package/dist/helpers/define-runner.d.ts +45 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/index.d.ts +6 -101
- package/dist/providers/abstract/llm.d.ts +20 -0
- package/dist/providers/abstract/provider.d.ts +14 -0
- package/dist/providers/example/echo.d.ts +12 -0
- package/dist/providers/example/restapi.d.ts +37 -0
- package/dist/providers/index.d.ts +5 -84
- package/dist/providers/index.js +1 -1
- package/dist/providers/mastra.d.ts +40 -0
- package/dist/providers/openai.d.ts +29 -0
- package/dist/providers/openrouter.d.ts +27 -0
- package/dist/schemas/extensions/index.d.ts +18 -22
- package/dist/schemas/extensions/response/llm.d.ts +14 -0
- package/dist/schemas/extensions/score/llm-as-a-judge-scorer.d.ts +15 -0
- package/dist/schemas/id.d.ts +2 -0
- package/dist/schemas/index.d.ts +4 -200
- package/dist/schemas/llm/index.d.ts +2 -116
- package/dist/schemas/llm/simple-system-prompt.d.ts +51 -0
- package/dist/schemas/llm/system-prompt.d.ts +59 -0
- package/dist/schemas/response.d.ts +63 -0
- package/dist/schemas/schema-definer.d.ts +47 -0
- package/dist/schemas/score.d.ts +73 -0
- package/dist/schemas/test-case.d.ts +57 -0
- package/dist/scorers/abstract.d.ts +16 -0
- package/dist/scorers/index.d.ts +4 -64
- package/dist/scorers/index.js +1 -1
- package/dist/scorers/llm-judge.d.ts +55 -0
- package/dist/scorers/mcq.d.ts +19 -0
- package/dist/scorers/mcq.test.d.ts +1 -0
- package/dist/scorers/regex.d.ts +58 -0
- package/dist/scorers/regex.test.d.ts +1 -0
- package/dist/storages/abstract.d.ts +7 -0
- package/dist/storages/examples/http.d.ts +1 -0
- package/dist/storages/examples/sqlite.d.ts +1 -0
- package/dist/storages/file.d.ts +43 -0
- package/dist/storages/http.d.ts +22 -0
- package/dist/storages/index.d.ts +5 -69
- package/dist/storages/json-file.d.ts +21 -0
- package/dist/storages/sqlite.d.ts +41 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/runner.d.ts +18 -0
- package/dist/utilities.d.ts +9 -0
- package/dist/utils/id-generator.d.ts +2 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/json.d.ts +17 -0
- package/dist/utils/llm.d.ts +7 -0
- package/dist/{rate-limiter-CSmVIRsM.d.ts → utils/rate-limiter.d.ts} +3 -5
- package/dist/utils/sleep.d.ts +1 -0
- package/dist/utils/string.d.ts +8 -0
- package/package.json +3 -3
- package/dist/abstract-Dec9Sc5O.d.ts +0 -12
- package/dist/chunk-3JF7SHLC.js.map +0 -1
- package/dist/chunk-DNGT4SJC.js.map +0 -1
- package/dist/index-BAioQhp2.d.ts +0 -27
- package/dist/json-file-Bgv9TLcX.d.ts +0 -74
- package/dist/llm-BND163ns.d.ts +0 -23
- package/dist/llm-judge-BS_oNYUK.d.ts +0 -67
- package/dist/provider-BDjGp2y-.d.ts +0 -10
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const BaseTestCaseSchemaV1: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
namespace: z.ZodString;
|
|
5
|
+
schemaVersion: z.ZodNumber;
|
|
6
|
+
kind: z.ZodString;
|
|
7
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export type BaseTestCaseV1 = z.infer<typeof BaseTestCaseSchemaV1>;
|
|
10
|
+
export declare const defineTestCaseSchema: <TBaseSchema extends import("../index.js").WidenZodObject<z.ZodObject<{
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
namespace: z.ZodString;
|
|
13
|
+
schemaVersion: z.ZodNumber;
|
|
14
|
+
kind: z.ZodString;
|
|
15
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
16
|
+
}, z.core.$strip>>, TNamespace extends string | undefined = undefined, TKind extends string | undefined = undefined, TSchemaVersion extends number | undefined = undefined, TFields extends Readonly<{
|
|
17
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
18
|
+
}> = {}>(config: {
|
|
19
|
+
baseSchema: TBaseSchema;
|
|
20
|
+
namespace?: TNamespace | undefined;
|
|
21
|
+
kind?: TKind | undefined;
|
|
22
|
+
schemaVersion?: TSchemaVersion | undefined;
|
|
23
|
+
fields?: TFields | undefined;
|
|
24
|
+
}) => (TBaseSchema extends z.ZodObject<infer U extends Readonly<{
|
|
25
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
26
|
+
}>, z.core.$strip> ? z.ZodObject<Omit<U, "kind" | "namespace" | "schemaVersion"> & TFields & {
|
|
27
|
+
namespace: TNamespace extends undefined ? U["namespace"] : z.ZodLiteral<TNamespace>;
|
|
28
|
+
kind: TKind extends undefined ? U["kind"] : z.ZodLiteral<`${TKind}.tc`>;
|
|
29
|
+
schemaVersion: TSchemaVersion extends undefined ? U["schemaVersion"] : z.ZodLiteral<TSchemaVersion>;
|
|
30
|
+
}, z.core.$strip> : never) & {
|
|
31
|
+
new: (input: Omit<z.core.output<TBaseSchema extends z.ZodObject<infer U extends Readonly<{
|
|
32
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
33
|
+
}>, z.core.$strip> ? z.ZodObject<Omit<U, "kind" | "namespace" | "schemaVersion"> & TFields & {
|
|
34
|
+
namespace: TNamespace extends undefined ? U["namespace"] : z.ZodLiteral<TNamespace>;
|
|
35
|
+
kind: TKind extends undefined ? U["kind"] : z.ZodLiteral<`${TKind}.tc`>;
|
|
36
|
+
schemaVersion: TSchemaVersion extends undefined ? U["schemaVersion"] : z.ZodLiteral<TSchemaVersion>;
|
|
37
|
+
}, z.core.$strip> : never>, "kind" | "namespace" | "schemaVersion">) => z.core.output<TBaseSchema extends z.ZodObject<infer U extends Readonly<{
|
|
38
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
39
|
+
}>, z.core.$strip> ? z.ZodObject<Omit<U, "kind" | "namespace" | "schemaVersion"> & TFields & {
|
|
40
|
+
namespace: TNamespace extends undefined ? U["namespace"] : z.ZodLiteral<TNamespace>;
|
|
41
|
+
kind: TKind extends undefined ? U["kind"] : z.ZodLiteral<`${TKind}.tc`>;
|
|
42
|
+
schemaVersion: TSchemaVersion extends undefined ? U["schemaVersion"] : z.ZodLiteral<TSchemaVersion>;
|
|
43
|
+
}, z.core.$strip> : never>;
|
|
44
|
+
newWithId(input: Omit<z.core.output<TBaseSchema extends z.ZodObject<infer U extends Readonly<{
|
|
45
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
46
|
+
}>, z.core.$strip> ? z.ZodObject<Omit<U, "kind" | "namespace" | "schemaVersion"> & TFields & {
|
|
47
|
+
namespace: TNamespace extends undefined ? U["namespace"] : z.ZodLiteral<TNamespace>;
|
|
48
|
+
kind: TKind extends undefined ? U["kind"] : z.ZodLiteral<`${TKind}.tc`>;
|
|
49
|
+
schemaVersion: TSchemaVersion extends undefined ? U["schemaVersion"] : z.ZodLiteral<TSchemaVersion>;
|
|
50
|
+
}, z.core.$strip> : never>, "kind" | "id" | "namespace" | "schemaVersion">, generator: import("../index.js").IdGenerator): Promise<z.core.output<TBaseSchema extends z.ZodObject<infer U extends Readonly<{
|
|
51
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
52
|
+
}>, z.core.$strip> ? z.ZodObject<Omit<U, "kind" | "namespace" | "schemaVersion"> & TFields & {
|
|
53
|
+
namespace: TNamespace extends undefined ? U["namespace"] : z.ZodLiteral<TNamespace>;
|
|
54
|
+
kind: TKind extends undefined ? U["kind"] : z.ZodLiteral<`${TKind}.tc`>;
|
|
55
|
+
schemaVersion: TSchemaVersion extends undefined ? U["schemaVersion"] : z.ZodLiteral<TSchemaVersion>;
|
|
56
|
+
}, z.core.$strip> : never>>;
|
|
57
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare abstract class AbstractScorer {
|
|
2
|
+
readonly kind: string;
|
|
3
|
+
constructor();
|
|
4
|
+
abstract score(params: any): Promise<BaseScorerResult | null>;
|
|
5
|
+
static withKind<TKind extends string, TThis extends abstract new (...args: any[]) => AbstractScorer>(this: TThis, kind: TKind): (new () => InstanceType<TThis> & {
|
|
6
|
+
readonly kind: TKind;
|
|
7
|
+
}) & {
|
|
8
|
+
readonly kind: TKind;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export type BaseScorerResult = {
|
|
12
|
+
value: number;
|
|
13
|
+
explanation?: string;
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
package/dist/scorers/index.d.ts
CHANGED
|
@@ -1,64 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
import '../provider-BDjGp2y-.js';
|
|
6
|
-
import 'openai/resources/shared';
|
|
7
|
-
import 'openai/resources/chat/completions';
|
|
8
|
-
import '../rate-limiter-CSmVIRsM.js';
|
|
9
|
-
import 'zod';
|
|
10
|
-
|
|
11
|
-
type RegexPattern = {
|
|
12
|
-
/**
|
|
13
|
-
* The regex pattern to match against the response
|
|
14
|
-
*/
|
|
15
|
-
regex: RegExp;
|
|
16
|
-
/**
|
|
17
|
-
* The index of the capture group to extract (1-based, like match[1])
|
|
18
|
-
* If not provided, defaults to 1 (first capture group)
|
|
19
|
-
*/
|
|
20
|
-
captureGroupIndex?: number;
|
|
21
|
-
/**
|
|
22
|
-
* Optional function to transform the extracted value before validation
|
|
23
|
-
*/
|
|
24
|
-
transform?: (value: string) => string | undefined;
|
|
25
|
-
};
|
|
26
|
-
type RegexScorerParams = {
|
|
27
|
-
/**
|
|
28
|
-
* The input text to score
|
|
29
|
-
*/
|
|
30
|
-
input: string;
|
|
31
|
-
/**
|
|
32
|
-
* Array of regex patterns to try (in order, first match wins)
|
|
33
|
-
*/
|
|
34
|
-
patterns: RegexPattern[];
|
|
35
|
-
/**
|
|
36
|
-
* Expected value(s) to match against. Can be a record of expected values for named groups, or a validation function
|
|
37
|
-
*/
|
|
38
|
-
expectedValue: Record<string, string> | ((groupName: string, match: string) => boolean);
|
|
39
|
-
/**
|
|
40
|
-
* Optional: Which match to use when multiple matches are found
|
|
41
|
-
* Defaults to "last" (uses the last match found)
|
|
42
|
-
*/
|
|
43
|
-
matchPreference?: "first" | "last";
|
|
44
|
-
/**
|
|
45
|
-
* Optional: If true, allows partial scoring based on how many groups match
|
|
46
|
-
* For example, if 2 groups are expected and only 1 matches, score would be 0.5
|
|
47
|
-
* Defaults to false (all-or-nothing scoring)
|
|
48
|
-
*/
|
|
49
|
-
allowPartialScoring?: boolean;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Generic Regex scorer. It scores the given input against a set of regex patterns.
|
|
53
|
-
*/
|
|
54
|
-
declare class RegexScorer extends AbstractScorer {
|
|
55
|
-
readonly kind: "peerbench.ai/regex";
|
|
56
|
-
score(params: RegexScorerParams): Promise<{
|
|
57
|
-
value: number;
|
|
58
|
-
extractedAnswers: {
|
|
59
|
-
[k: string]: string;
|
|
60
|
-
};
|
|
61
|
-
}>;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { AbstractScorer, type RegexPattern, RegexScorer, type RegexScorerParams };
|
|
1
|
+
export * from "./abstract";
|
|
2
|
+
export * from "./mcq";
|
|
3
|
+
export * from "./llm-judge";
|
|
4
|
+
export * from "./regex";
|
package/dist/scorers/index.js
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { AbstractLLMProvider } from "../providers/abstract/llm";
|
|
2
|
+
import { RateLimiter } from "../utils/rate-limiter";
|
|
3
|
+
import { AbstractScorer, BaseScorerResult } from "./abstract";
|
|
4
|
+
import z from "zod";
|
|
5
|
+
declare const LLMAsAJudgeScorer_base: (new () => AbstractScorer & {
|
|
6
|
+
readonly kind: "peerbench.ai/llm-as-a-judge";
|
|
7
|
+
}) & {
|
|
8
|
+
readonly kind: "peerbench.ai/llm-as-a-judge";
|
|
9
|
+
};
|
|
10
|
+
export declare class LLMAsAJudgeScorer extends LLMAsAJudgeScorer_base {
|
|
11
|
+
private provider;
|
|
12
|
+
constructor(config: {
|
|
13
|
+
provider: AbstractLLMProvider;
|
|
14
|
+
rateLimiter?: RateLimiter;
|
|
15
|
+
});
|
|
16
|
+
score<T extends z.ZodRawShape>(params: LLMAsAJudgeScoreParams & {
|
|
17
|
+
fieldsToExtract: T;
|
|
18
|
+
}): Promise<ScorerResultWithExtractedFields<T> | null>;
|
|
19
|
+
score(params: LLMAsAJudgeScoreParams & {
|
|
20
|
+
fieldsToExtract?: never;
|
|
21
|
+
}): Promise<ScorerResultWithoutExtractedFields | null>;
|
|
22
|
+
}
|
|
23
|
+
export type LLMAsAJudgeCriterion = {
|
|
24
|
+
id: string;
|
|
25
|
+
description: string;
|
|
26
|
+
weight: number;
|
|
27
|
+
scale?: {
|
|
28
|
+
min: number;
|
|
29
|
+
max: number;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export type LLMAsAJudgeScoreParams = {
|
|
33
|
+
model: string;
|
|
34
|
+
response: string;
|
|
35
|
+
rubric: string;
|
|
36
|
+
criteria: LLMAsAJudgeCriterion[];
|
|
37
|
+
systemPrompt?: string;
|
|
38
|
+
maxExplanationLength?: number;
|
|
39
|
+
};
|
|
40
|
+
type ScorerResultWithoutExtractedFields = BaseScorerResult & {
|
|
41
|
+
results: {
|
|
42
|
+
id: string;
|
|
43
|
+
score: number;
|
|
44
|
+
explanation: string;
|
|
45
|
+
}[];
|
|
46
|
+
provider: string;
|
|
47
|
+
inputTokensUsed?: number;
|
|
48
|
+
outputTokensUsed?: number;
|
|
49
|
+
inputCost?: string;
|
|
50
|
+
outputCost?: string;
|
|
51
|
+
};
|
|
52
|
+
type ScorerResultWithExtractedFields<T extends z.ZodRawShape> = ScorerResultWithoutExtractedFields & {
|
|
53
|
+
extractedFields: z.infer<z.ZodObject<T>>;
|
|
54
|
+
};
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AbstractScorer, BaseScorerResult } from "./abstract";
|
|
2
|
+
export type MCQScorerParams = {
|
|
3
|
+
response: string;
|
|
4
|
+
choices: Record<string, string>;
|
|
5
|
+
correctAnswers: string[];
|
|
6
|
+
};
|
|
7
|
+
declare const MCQScorer_base: (new () => AbstractScorer & {
|
|
8
|
+
readonly kind: "peerbench.ai/mcq";
|
|
9
|
+
}) & {
|
|
10
|
+
readonly kind: "peerbench.ai/mcq";
|
|
11
|
+
};
|
|
12
|
+
export declare class MCQScorer extends MCQScorer_base {
|
|
13
|
+
private regexScorer;
|
|
14
|
+
score(params: MCQScorerParams): Promise<BaseScorerResult & {
|
|
15
|
+
extractedAnswers: string[];
|
|
16
|
+
}>;
|
|
17
|
+
private buildPatternsForAnswer;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AbstractScorer } from "./abstract";
|
|
2
|
+
export type RegexPattern = {
|
|
3
|
+
/**
|
|
4
|
+
* The regex pattern to match against the response
|
|
5
|
+
*/
|
|
6
|
+
regex: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* The index of the capture group to extract (1-based, like match[1])
|
|
9
|
+
* If not provided, defaults to 1 (first capture group)
|
|
10
|
+
*/
|
|
11
|
+
captureGroupIndex?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Optional function to transform the extracted value before validation
|
|
14
|
+
*/
|
|
15
|
+
transform?: (value: string) => string | undefined;
|
|
16
|
+
};
|
|
17
|
+
export type RegexScorerParams = {
|
|
18
|
+
/**
|
|
19
|
+
* The input text to score
|
|
20
|
+
*/
|
|
21
|
+
input: string;
|
|
22
|
+
/**
|
|
23
|
+
* Array of regex patterns to try (in order, first match wins)
|
|
24
|
+
*/
|
|
25
|
+
patterns: RegexPattern[];
|
|
26
|
+
/**
|
|
27
|
+
* Expected value(s) to match against. Can be a record of expected values for named groups, or a validation function
|
|
28
|
+
*/
|
|
29
|
+
expectedValue: Record<string, string> | ((groupName: string, match: string) => boolean);
|
|
30
|
+
/**
|
|
31
|
+
* Optional: Which match to use when multiple matches are found
|
|
32
|
+
* Defaults to "last" (uses the last match found)
|
|
33
|
+
*/
|
|
34
|
+
matchPreference?: "first" | "last";
|
|
35
|
+
/**
|
|
36
|
+
* Optional: If true, allows partial scoring based on how many groups match
|
|
37
|
+
* For example, if 2 groups are expected and only 1 matches, score would be 0.5
|
|
38
|
+
* Defaults to false (all-or-nothing scoring)
|
|
39
|
+
*/
|
|
40
|
+
allowPartialScoring?: boolean;
|
|
41
|
+
};
|
|
42
|
+
declare const RegexScorer_base: (new () => AbstractScorer & {
|
|
43
|
+
readonly kind: "peerbench.ai/regex";
|
|
44
|
+
}) & {
|
|
45
|
+
readonly kind: "peerbench.ai/regex";
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Generic Regex scorer. It scores the given input against a set of regex patterns.
|
|
49
|
+
*/
|
|
50
|
+
export declare class RegexScorer extends RegexScorer_base {
|
|
51
|
+
score(params: RegexScorerParams): Promise<{
|
|
52
|
+
value: number;
|
|
53
|
+
extractedAnswers: {
|
|
54
|
+
[k: string]: string;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare abstract class AbstractStorage<TObject> {
|
|
2
|
+
abstract init(params?: unknown): Promise<void>;
|
|
3
|
+
abstract read(key: string, params?: unknown): Promise<TObject | null>;
|
|
4
|
+
abstract readAll(params?: unknown): Promise<TObject[]>;
|
|
5
|
+
abstract write(key: string, value: TObject, params?: unknown): Promise<unknown>;
|
|
6
|
+
count(): Promise<number>;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FileHandle } from "node:fs/promises";
|
|
2
|
+
import { AbstractStorage } from "./abstract";
|
|
3
|
+
export declare class FileStorage<TObject> extends AbstractStorage<TObject> {
|
|
4
|
+
protected path: string;
|
|
5
|
+
protected codec: AbstractFileStorageCodec<TObject>;
|
|
6
|
+
protected fileHandle: FileHandle | undefined;
|
|
7
|
+
constructor(config: {
|
|
8
|
+
path: string;
|
|
9
|
+
codec: AbstractFileStorageCodec<TObject>;
|
|
10
|
+
});
|
|
11
|
+
init(): Promise<void>;
|
|
12
|
+
read(_key: string, _params?: unknown): Promise<TObject | null>;
|
|
13
|
+
readAll(_params?: unknown): Promise<TObject[]>;
|
|
14
|
+
write(_key: string, _value: TObject, _params?: unknown): Promise<unknown>;
|
|
15
|
+
protected readChunks(params: {
|
|
16
|
+
startOffset?: number;
|
|
17
|
+
chunkSize: number;
|
|
18
|
+
}): AsyncIterable<{
|
|
19
|
+
offset: number;
|
|
20
|
+
bytes: Uint8Array;
|
|
21
|
+
}>;
|
|
22
|
+
protected size(): Promise<number>;
|
|
23
|
+
protected readAt(offset: number, length: number): Promise<Uint8Array>;
|
|
24
|
+
protected assertInitialized(): asserts this is this & {
|
|
25
|
+
fileHandle: FileHandle;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export type FileStorageFileHandle = {
|
|
29
|
+
size(): Promise<number>;
|
|
30
|
+
readAt(offset: number, length: number): Promise<Uint8Array>;
|
|
31
|
+
readChunks(params: {
|
|
32
|
+
startOffset?: number;
|
|
33
|
+
chunkSize: number;
|
|
34
|
+
}): AsyncIterable<{
|
|
35
|
+
offset: number;
|
|
36
|
+
bytes: Uint8Array;
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
export declare abstract class AbstractFileStorageCodec<TObject> {
|
|
40
|
+
abstract readAll(params: {
|
|
41
|
+
fileHandle: FileStorageFileHandle;
|
|
42
|
+
}): Promise<TObject[]>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AbstractStorage } from "../storages/abstract";
|
|
2
|
+
export declare class HttpStorage<TObject> extends AbstractStorage<TObject> {
|
|
3
|
+
protected readonly url: string;
|
|
4
|
+
protected readonly codec: AbstractHttpStorageCodec<TObject>;
|
|
5
|
+
protected readonly fetchFn: typeof fetch;
|
|
6
|
+
constructor(config: {
|
|
7
|
+
url: string;
|
|
8
|
+
codec: AbstractHttpStorageCodec<TObject>;
|
|
9
|
+
fetchFn?: typeof fetch;
|
|
10
|
+
});
|
|
11
|
+
init(_params?: unknown): Promise<void>;
|
|
12
|
+
read(_key: string, _params?: unknown): Promise<TObject | null>;
|
|
13
|
+
readAll(params?: unknown): Promise<TObject[]>;
|
|
14
|
+
write(_key: string, _value: TObject, _params?: unknown): Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
export declare abstract class AbstractHttpStorageCodec<TObject> {
|
|
17
|
+
abstract readAll(params: {
|
|
18
|
+
url: string;
|
|
19
|
+
response: Response;
|
|
20
|
+
params?: unknown;
|
|
21
|
+
}): Promise<TObject[]>;
|
|
22
|
+
}
|
package/dist/storages/index.d.ts
CHANGED
|
@@ -1,69 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
declare class HttpStorage<TObject> extends AbstractStorage<TObject> {
|
|
8
|
-
protected readonly url: string;
|
|
9
|
-
protected readonly codec: AbstractHttpStorageCodec<TObject>;
|
|
10
|
-
protected readonly fetchFn: typeof fetch;
|
|
11
|
-
constructor(config: {
|
|
12
|
-
url: string;
|
|
13
|
-
codec: AbstractHttpStorageCodec<TObject>;
|
|
14
|
-
fetchFn?: typeof fetch;
|
|
15
|
-
});
|
|
16
|
-
init(_params?: unknown): Promise<void>;
|
|
17
|
-
read(_key: string, _params?: unknown): Promise<TObject | null>;
|
|
18
|
-
readAll(params?: unknown): Promise<TObject[]>;
|
|
19
|
-
write(_key: string, _value: TObject, _params?: unknown): Promise<unknown>;
|
|
20
|
-
}
|
|
21
|
-
declare abstract class AbstractHttpStorageCodec<TObject> {
|
|
22
|
-
abstract readAll(params: {
|
|
23
|
-
url: string;
|
|
24
|
-
response: Response;
|
|
25
|
-
params?: unknown;
|
|
26
|
-
}): Promise<TObject[]>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
declare class SQLiteStorage<TObject> extends AbstractStorage<TObject> {
|
|
30
|
-
protected readonly path: string;
|
|
31
|
-
protected readonly codec: AbstractSQLiteStorageCodec<TObject>;
|
|
32
|
-
protected db: SQLiteDatabase | undefined;
|
|
33
|
-
constructor(config: {
|
|
34
|
-
path: string;
|
|
35
|
-
codec: AbstractSQLiteStorageCodec<TObject>;
|
|
36
|
-
});
|
|
37
|
-
init(params?: unknown): Promise<void>;
|
|
38
|
-
read(key: string, params?: unknown): Promise<TObject | null>;
|
|
39
|
-
readAll(params?: unknown): Promise<TObject[]>;
|
|
40
|
-
write(key: string, value: TObject, params?: unknown): Promise<unknown>;
|
|
41
|
-
close(): void;
|
|
42
|
-
protected assertInitialized(): asserts this is this & {
|
|
43
|
-
db: SQLiteDatabase;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
declare abstract class AbstractSQLiteStorageCodec<TObject> {
|
|
47
|
-
init?(params: {
|
|
48
|
-
db: SQLiteDatabase;
|
|
49
|
-
params?: unknown;
|
|
50
|
-
}): Promise<void> | void;
|
|
51
|
-
abstract read(params: {
|
|
52
|
-
db: SQLiteDatabase;
|
|
53
|
-
key: string;
|
|
54
|
-
params?: unknown;
|
|
55
|
-
}): Promise<TObject | null>;
|
|
56
|
-
abstract readAll(params: {
|
|
57
|
-
db: SQLiteDatabase;
|
|
58
|
-
params?: unknown;
|
|
59
|
-
}): Promise<TObject[]>;
|
|
60
|
-
abstract write(params: {
|
|
61
|
-
db: SQLiteDatabase;
|
|
62
|
-
key: string;
|
|
63
|
-
value: TObject;
|
|
64
|
-
params?: unknown;
|
|
65
|
-
}): Promise<unknown>;
|
|
66
|
-
}
|
|
67
|
-
type SQLiteDatabase = better_sqlite3.Database;
|
|
68
|
-
|
|
69
|
-
export { AbstractHttpStorageCodec, AbstractSQLiteStorageCodec, AbstractStorage, HttpStorage, SQLiteStorage };
|
|
1
|
+
export * from "./abstract";
|
|
2
|
+
export * from "./http";
|
|
3
|
+
export * from "./json-file";
|
|
4
|
+
export * from "./file";
|
|
5
|
+
export * from "./sqlite";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AbstractFileStorageCodec, FileStorage, FileStorageFileHandle } from "./file";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
export declare class JSONFileStorage<TObject> extends FileStorage<TObject> {
|
|
4
|
+
codec: JSONFileStorageCodec<TObject>;
|
|
5
|
+
constructor(config: {
|
|
6
|
+
path: string;
|
|
7
|
+
chunkSize?: number;
|
|
8
|
+
schema: z.ZodType<TObject>;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export declare class JSONFileStorageCodec<TObject> extends AbstractFileStorageCodec<TObject> {
|
|
12
|
+
private chunkSize;
|
|
13
|
+
private schema;
|
|
14
|
+
constructor(config: {
|
|
15
|
+
chunkSize?: number;
|
|
16
|
+
schema: z.ZodType<TObject>;
|
|
17
|
+
});
|
|
18
|
+
readAll(params: {
|
|
19
|
+
fileHandle: FileStorageFileHandle;
|
|
20
|
+
}): Promise<TObject[]>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AbstractStorage } from "../storages/abstract";
|
|
2
|
+
export declare class SQLiteStorage<TObject> extends AbstractStorage<TObject> {
|
|
3
|
+
protected readonly path: string;
|
|
4
|
+
protected readonly codec: AbstractSQLiteStorageCodec<TObject>;
|
|
5
|
+
protected db: SQLiteDatabase | undefined;
|
|
6
|
+
constructor(config: {
|
|
7
|
+
path: string;
|
|
8
|
+
codec: AbstractSQLiteStorageCodec<TObject>;
|
|
9
|
+
});
|
|
10
|
+
init(params?: unknown): Promise<void>;
|
|
11
|
+
read(key: string, params?: unknown): Promise<TObject | null>;
|
|
12
|
+
readAll(params?: unknown): Promise<TObject[]>;
|
|
13
|
+
write(key: string, value: TObject, params?: unknown): Promise<unknown>;
|
|
14
|
+
close(): void;
|
|
15
|
+
protected assertInitialized(): asserts this is this & {
|
|
16
|
+
db: SQLiteDatabase;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare abstract class AbstractSQLiteStorageCodec<TObject> {
|
|
20
|
+
init?(params: {
|
|
21
|
+
db: SQLiteDatabase;
|
|
22
|
+
params?: unknown;
|
|
23
|
+
}): Promise<void> | void;
|
|
24
|
+
abstract read(params: {
|
|
25
|
+
db: SQLiteDatabase;
|
|
26
|
+
key: string;
|
|
27
|
+
params?: unknown;
|
|
28
|
+
}): Promise<TObject | null>;
|
|
29
|
+
abstract readAll(params: {
|
|
30
|
+
db: SQLiteDatabase;
|
|
31
|
+
params?: unknown;
|
|
32
|
+
}): Promise<TObject[]>;
|
|
33
|
+
abstract write(params: {
|
|
34
|
+
db: SQLiteDatabase;
|
|
35
|
+
key: string;
|
|
36
|
+
value: TObject;
|
|
37
|
+
params?: unknown;
|
|
38
|
+
}): Promise<unknown>;
|
|
39
|
+
}
|
|
40
|
+
type SQLiteDatabase = import("better-sqlite3").Database;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./runner";
|
|
2
|
+
import { AbstractProvider } from "../providers/index.js";
|
|
3
|
+
import { IdSchema } from "../schemas/id";
|
|
4
|
+
import { AbstractScorer } from "../scorers/abstract";
|
|
5
|
+
import { AbstractClassConstructor, ClassConstructor } from "../utilities";
|
|
6
|
+
import z from "zod";
|
|
7
|
+
export type Id = z.infer<typeof IdSchema>;
|
|
8
|
+
export type IdGenerator<TInput = unknown> = (input: TInput) => MaybePromise<Id>;
|
|
9
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
10
|
+
export declare const ScoringMethod: {
|
|
11
|
+
readonly ai: "ai";
|
|
12
|
+
readonly human: "human";
|
|
13
|
+
readonly algo: "algo";
|
|
14
|
+
};
|
|
15
|
+
export type ScoringMethod = (typeof ScoringMethod)[keyof typeof ScoringMethod];
|
|
16
|
+
export type ScorerCtor = ClassConstructor<AbstractScorer> | AbstractClassConstructor<AbstractScorer>;
|
|
17
|
+
export type ProviderCtor = ClassConstructor<AbstractProvider> | AbstractClassConstructor<AbstractProvider>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AbstractProvider } from "../providers/index.js";
|
|
2
|
+
import { AbstractScorer } from "../scorers/index.js";
|
|
3
|
+
import { IdGenerator } from ".";
|
|
4
|
+
import z from "zod";
|
|
5
|
+
export type Runner<TTestCase extends z.ZodObject, TResponse extends z.ZodObject, TScore extends z.ZodObject, TProvider extends AbstractProvider, TScorer extends AbstractScorer, TRunConfig extends Record<string, unknown>> = (params: {
|
|
6
|
+
testCase: z.infer<TTestCase>;
|
|
7
|
+
provider: TProvider;
|
|
8
|
+
scorer?: TScorer;
|
|
9
|
+
runConfig: TRunConfig;
|
|
10
|
+
idGenerators?: {
|
|
11
|
+
response?: IdGenerator;
|
|
12
|
+
score?: IdGenerator;
|
|
13
|
+
};
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
response: z.infer<TResponse>;
|
|
16
|
+
score?: z.infer<TScore>;
|
|
17
|
+
}>;
|
|
18
|
+
export type InferRunConfig<TRunConfigSchema extends z.ZodRawShape> = z.infer<z.ZodObject<TRunConfigSchema>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
export type ClassConstructor<T> = new (...args: any[]) => T;
|
|
3
|
+
export type AbstractClassConstructor<T> = abstract new (...args: any[]) => T;
|
|
4
|
+
export type InferExtension<TExtension extends z.ZodRawShape, TBase = unknown> = z.infer<z.ZodObject<TExtension>> & TBase;
|
|
5
|
+
type WidenLiteralSchema<S> = S extends z.ZodString ? z.ZodString | z.ZodLiteral<string> : S extends z.ZodNumber ? z.ZodNumber | z.ZodLiteral<number> : S extends z.ZodBoolean ? z.ZodBoolean | z.ZodLiteral<boolean> : S extends z.ZodLiteral<infer L> ? L extends string ? z.ZodString | z.ZodLiteral<L> : L extends number ? z.ZodNumber | z.ZodLiteral<L> : L extends boolean ? z.ZodBoolean | z.ZodLiteral<L> : S : S extends z.ZodOptional<infer O> ? z.ZodOptional<WidenLiteralSchema<O>> : S extends z.ZodType ? S : never;
|
|
6
|
+
export type WidenZodObject<T extends z.ZodObject> = z.ZodObject<{
|
|
7
|
+
[K in keyof T["shape"]]: WidenLiteralSchema<T["shape"][K]>;
|
|
8
|
+
}>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses JSONL formatted string into an array
|
|
3
|
+
* @returns An array of parsed JSON lines
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseJSONL<T>(str: string, options?: {
|
|
6
|
+
errorOnInvalid?: boolean;
|
|
7
|
+
}): T[];
|
|
8
|
+
/**
|
|
9
|
+
* Tries to parse the given string as JSON.
|
|
10
|
+
* Returns `undefined` if it is not a valid JSON entity.
|
|
11
|
+
*/
|
|
12
|
+
export declare function tryParseJson<T = any>(content: string): T | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Stringifies the given JSON value using `safe-stable-stringify` in a stable manner.
|
|
15
|
+
* This stable method generates the same string output for the same input value (including objects).
|
|
16
|
+
*/
|
|
17
|
+
export declare function stableStringify(value: any): string | undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tries to repair and parse LLM response as a JSON object. LLM must
|
|
3
|
+
* be configured to return a JSON object. This function only helps to
|
|
4
|
+
* get rid out of some additional formatting (e.g. ```json) and repair
|
|
5
|
+
* the JSON syntax (e.g missing comma, single quotes instead double).
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseResponseAsJSON<T>(response: string): T | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface RateLimiterOptions {
|
|
1
|
+
export interface RateLimiterOptions {
|
|
2
2
|
/**
|
|
3
3
|
* Maximum weight of calls allowed within a time window. Each call has a weight of 1 by default.
|
|
4
4
|
* Rate limiting is disabled when this is 0 or negative.
|
|
@@ -11,7 +11,7 @@ interface RateLimiterOptions {
|
|
|
11
11
|
*/
|
|
12
12
|
timeWindow?: number;
|
|
13
13
|
}
|
|
14
|
-
interface RateLimiterCallOptions {
|
|
14
|
+
export interface RateLimiterCallOptions {
|
|
15
15
|
/**
|
|
16
16
|
* Weight of the call. Rate limiting is applied based on the total weight of the calls.
|
|
17
17
|
* @default 1
|
|
@@ -26,7 +26,7 @@ interface RateLimiterCallOptions {
|
|
|
26
26
|
* Generic rate limiter. It can be used to limit async function calls
|
|
27
27
|
* by a given number of calls within a time window.
|
|
28
28
|
*/
|
|
29
|
-
declare class RateLimiter {
|
|
29
|
+
export declare class RateLimiter {
|
|
30
30
|
maxWeight: number;
|
|
31
31
|
timeWindow: number;
|
|
32
32
|
private timestamps;
|
|
@@ -56,5 +56,3 @@ declare class RateLimiter {
|
|
|
56
56
|
*/
|
|
57
57
|
reset(): void;
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
export { RateLimiter as R, type RateLimiterOptions as a, type RateLimiterCallOptions as b };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the given byte array to a string
|
|
3
|
+
*/
|
|
4
|
+
export declare function bufferToString(buffer: Uint8Array, encoding?: BufferEncoding): string;
|
|
5
|
+
/**
|
|
6
|
+
* Converts the given string to a byte array
|
|
7
|
+
*/
|
|
8
|
+
export declare function stringToBuffer(str: string): Uint8Array;
|