@assay-ai/core 0.1.0-beta
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/dist/index.cjs +2443 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +460 -0
- package/dist/index.d.ts +460 -0
- package/dist/index.js +2378 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import { ZodType, z } from 'zod';
|
|
2
|
+
|
|
3
|
+
interface ToolCall {
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
reasoning?: string;
|
|
7
|
+
output?: unknown;
|
|
8
|
+
inputParameters?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
interface LLMTestCase {
|
|
11
|
+
input: string;
|
|
12
|
+
actualOutput?: string;
|
|
13
|
+
expectedOutput?: string;
|
|
14
|
+
context?: string[];
|
|
15
|
+
retrievalContext?: string[];
|
|
16
|
+
toolsCalled?: ToolCall[];
|
|
17
|
+
expectedTools?: ToolCall[];
|
|
18
|
+
tokenCost?: number;
|
|
19
|
+
completionTime?: number;
|
|
20
|
+
name?: string;
|
|
21
|
+
tags?: string[];
|
|
22
|
+
}
|
|
23
|
+
interface ConversationalTestCase {
|
|
24
|
+
turns: Array<{
|
|
25
|
+
role: "user" | "assistant";
|
|
26
|
+
content: string;
|
|
27
|
+
}>;
|
|
28
|
+
scenario?: string;
|
|
29
|
+
expectedOutcome?: string;
|
|
30
|
+
chatbotRole?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Golden {
|
|
34
|
+
input: string;
|
|
35
|
+
actualOutput?: string;
|
|
36
|
+
expectedOutput?: string;
|
|
37
|
+
context?: string[];
|
|
38
|
+
retrievalContext?: string[];
|
|
39
|
+
}
|
|
40
|
+
interface EvaluationDataset {
|
|
41
|
+
name?: string;
|
|
42
|
+
goldens: Golden[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface ProviderConfig {
|
|
46
|
+
apiKey?: string;
|
|
47
|
+
model?: string;
|
|
48
|
+
baseUrl?: string;
|
|
49
|
+
temperature?: number;
|
|
50
|
+
maxTokens?: number;
|
|
51
|
+
}
|
|
52
|
+
declare abstract class BaseLLMProvider {
|
|
53
|
+
protected readonly config: ProviderConfig;
|
|
54
|
+
readonly modelName: string;
|
|
55
|
+
protected readonly temperature: number;
|
|
56
|
+
protected readonly maxTokens: number;
|
|
57
|
+
constructor(config: ProviderConfig, defaultModel: string);
|
|
58
|
+
/**
|
|
59
|
+
* Generate a raw text completion from the LLM.
|
|
60
|
+
*/
|
|
61
|
+
abstract generate(prompt: string): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Generate a typed JSON response from the LLM, validated against a Zod schema.
|
|
64
|
+
* Instructs the model to return JSON conforming to the schema, then parses
|
|
65
|
+
* and validates the response.
|
|
66
|
+
*
|
|
67
|
+
* @param prompt - The user prompt
|
|
68
|
+
* @param schema - A Zod schema to validate the response
|
|
69
|
+
* @param retries - Number of retries on parse/validation failure (default 2)
|
|
70
|
+
*/
|
|
71
|
+
generateJSON<T>(prompt: string, schema: ZodType<T>, retries?: number): Promise<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the provider name for logging/identification.
|
|
74
|
+
*/
|
|
75
|
+
abstract get providerName(): string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface MetricResult {
|
|
79
|
+
/** Score from 0 to 1 */
|
|
80
|
+
score: number;
|
|
81
|
+
/** LLM-generated explanation of the score */
|
|
82
|
+
reason?: string;
|
|
83
|
+
/** Whether the score meets the threshold */
|
|
84
|
+
pass: boolean;
|
|
85
|
+
/** Name of the metric */
|
|
86
|
+
metricName: string;
|
|
87
|
+
/** Threshold used */
|
|
88
|
+
threshold: number;
|
|
89
|
+
/** Time taken in ms */
|
|
90
|
+
evaluationTimeMs: number;
|
|
91
|
+
/** Details for debugging (extracted statements, verdicts, etc.) */
|
|
92
|
+
details?: Record<string, unknown>;
|
|
93
|
+
}
|
|
94
|
+
interface MetricConfig {
|
|
95
|
+
/** Score threshold for pass/fail (default: 0.5) */
|
|
96
|
+
threshold?: number;
|
|
97
|
+
/** LLM provider to use for evaluation */
|
|
98
|
+
provider?: BaseLLMProvider | string;
|
|
99
|
+
/** Include reasoning in results (default: true) */
|
|
100
|
+
includeReason?: boolean;
|
|
101
|
+
/** Binary scoring mode — 0 or 1 only (default: false) */
|
|
102
|
+
strictMode?: boolean;
|
|
103
|
+
/** Enable verbose logging (default: false) */
|
|
104
|
+
verbose?: boolean;
|
|
105
|
+
}
|
|
106
|
+
declare abstract class BaseMetric {
|
|
107
|
+
abstract readonly name: string;
|
|
108
|
+
abstract readonly requiredFields: (keyof LLMTestCase)[];
|
|
109
|
+
readonly threshold: number;
|
|
110
|
+
readonly includeReason: boolean;
|
|
111
|
+
readonly strictMode: boolean;
|
|
112
|
+
readonly verbose: boolean;
|
|
113
|
+
/** Whether a lower score is better (e.g., Hallucination, Bias, Toxicity) */
|
|
114
|
+
readonly lowerIsBetter: boolean;
|
|
115
|
+
protected provider: BaseLLMProvider;
|
|
116
|
+
constructor(config?: MetricConfig);
|
|
117
|
+
/** Run the metric evaluation. Must be implemented by each metric. */
|
|
118
|
+
abstract measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
119
|
+
/** Validate that required fields exist on the test case */
|
|
120
|
+
protected validate(testCase: LLMTestCase): void;
|
|
121
|
+
/** Apply strict mode (binary 0/1) if enabled */
|
|
122
|
+
protected applyStrictMode(score: number): number;
|
|
123
|
+
/** Build a MetricResult from score, reason, and timing */
|
|
124
|
+
protected buildResult(score: number, reason: string | undefined, startTime: number, details?: Record<string, unknown>): MetricResult;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
declare class AnswerRelevancyMetric extends BaseMetric {
|
|
128
|
+
readonly name = "Answer Relevancy";
|
|
129
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
130
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare class FaithfulnessMetric extends BaseMetric {
|
|
134
|
+
readonly name = "Faithfulness";
|
|
135
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
136
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
declare class HallucinationMetric extends BaseMetric {
|
|
140
|
+
readonly name = "Hallucination";
|
|
141
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
142
|
+
readonly lowerIsBetter = true;
|
|
143
|
+
constructor(config?: MetricConfig);
|
|
144
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
declare class ContextualPrecisionMetric extends BaseMetric {
|
|
148
|
+
readonly name = "Contextual Precision";
|
|
149
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
150
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class ContextualRecallMetric extends BaseMetric {
|
|
154
|
+
readonly name = "Contextual Recall";
|
|
155
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
156
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
declare class ContextualRelevancyMetric extends BaseMetric {
|
|
160
|
+
readonly name = "Contextual Relevancy";
|
|
161
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
162
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
declare class BiasMetric extends BaseMetric {
|
|
166
|
+
readonly name = "Bias";
|
|
167
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
168
|
+
readonly lowerIsBetter = true;
|
|
169
|
+
constructor(config?: MetricConfig);
|
|
170
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare class ToxicityMetric extends BaseMetric {
|
|
174
|
+
readonly name = "Toxicity";
|
|
175
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
176
|
+
readonly lowerIsBetter = true;
|
|
177
|
+
constructor(config?: MetricConfig);
|
|
178
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
interface GEvalConfig extends MetricConfig {
|
|
182
|
+
/** Human-readable name for this evaluation */
|
|
183
|
+
name?: string;
|
|
184
|
+
/** The evaluation criteria in natural language */
|
|
185
|
+
criteria: string;
|
|
186
|
+
/** Which test case fields to include in evaluation */
|
|
187
|
+
evaluationParams?: (keyof LLMTestCase)[];
|
|
188
|
+
/** Optional pre-defined evaluation steps (auto-generated if omitted) */
|
|
189
|
+
evaluationSteps?: string[];
|
|
190
|
+
}
|
|
191
|
+
declare class GEval extends BaseMetric {
|
|
192
|
+
readonly name: string;
|
|
193
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
194
|
+
private readonly criteria;
|
|
195
|
+
private readonly evaluationParams;
|
|
196
|
+
private evaluationSteps?;
|
|
197
|
+
constructor(config: GEvalConfig);
|
|
198
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
declare class SummarizationMetric extends BaseMetric {
|
|
202
|
+
readonly name = "Summarization";
|
|
203
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
204
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
205
|
+
private evaluateAlignment;
|
|
206
|
+
private evaluateCoverage;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface ExactMatchConfig extends MetricConfig {
|
|
210
|
+
/** Whether to ignore case when comparing (default: false) */
|
|
211
|
+
ignoreCase?: boolean;
|
|
212
|
+
/** Whether to trim whitespace when comparing (default: true) */
|
|
213
|
+
trimWhitespace?: boolean;
|
|
214
|
+
}
|
|
215
|
+
declare class ExactMatchMetric extends BaseMetric {
|
|
216
|
+
readonly name = "Exact Match";
|
|
217
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
218
|
+
readonly requiresProvider = false;
|
|
219
|
+
private readonly ignoreCase;
|
|
220
|
+
private readonly trimWhitespace;
|
|
221
|
+
constructor(config?: ExactMatchConfig);
|
|
222
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
interface JsonCorrectnessConfig extends MetricConfig {
|
|
226
|
+
/** Optional Zod schema to validate the JSON structure against */
|
|
227
|
+
schema?: z.ZodSchema;
|
|
228
|
+
/** If true, also compares against expectedOutput JSON (default: false) */
|
|
229
|
+
compareWithExpected?: boolean;
|
|
230
|
+
}
|
|
231
|
+
declare class JsonCorrectnessMetric extends BaseMetric {
|
|
232
|
+
readonly name = "JSON Correctness";
|
|
233
|
+
readonly requiredFields: (keyof LLMTestCase)[];
|
|
234
|
+
readonly requiresProvider = false;
|
|
235
|
+
private readonly schema?;
|
|
236
|
+
private readonly compareWithExpected;
|
|
237
|
+
constructor(config?: JsonCorrectnessConfig);
|
|
238
|
+
measure(testCase: LLMTestCase): Promise<MetricResult>;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare class OpenAIProvider extends BaseLLMProvider {
|
|
242
|
+
private client;
|
|
243
|
+
constructor(config?: ProviderConfig);
|
|
244
|
+
get providerName(): string;
|
|
245
|
+
generate(prompt: string): Promise<string>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
declare class AnthropicProvider extends BaseLLMProvider {
|
|
249
|
+
private client;
|
|
250
|
+
constructor(config?: ProviderConfig);
|
|
251
|
+
get providerName(): string;
|
|
252
|
+
generate(prompt: string): Promise<string>;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
declare class OllamaProvider extends BaseLLMProvider {
|
|
256
|
+
private readonly baseUrl;
|
|
257
|
+
constructor(config?: ProviderConfig);
|
|
258
|
+
get providerName(): string;
|
|
259
|
+
generate(prompt: string): Promise<string>;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Resolve a provider from a string name, provider instance, or auto-detect from env vars.
|
|
264
|
+
* Returns a noop provider if undefined (for non-LLM metrics).
|
|
265
|
+
*/
|
|
266
|
+
declare function resolveProvider(provider?: BaseLLMProvider | string): BaseLLMProvider;
|
|
267
|
+
|
|
268
|
+
interface AssayConfig {
|
|
269
|
+
/** Default LLM provider for metrics that need one */
|
|
270
|
+
provider?: BaseLLMProvider;
|
|
271
|
+
/** Provider name shorthand (resolved via resolveProvider) */
|
|
272
|
+
providerName?: "openai" | "anthropic" | "ollama";
|
|
273
|
+
/** Model override */
|
|
274
|
+
model?: string;
|
|
275
|
+
/** API key override */
|
|
276
|
+
apiKey?: string;
|
|
277
|
+
/** Base URL override */
|
|
278
|
+
baseUrl?: string;
|
|
279
|
+
/** Default metrics to run if not specified per-evaluate call */
|
|
280
|
+
metrics?: BaseMetric[];
|
|
281
|
+
/** Max concurrent test case evaluations. Default 5. */
|
|
282
|
+
concurrency?: number;
|
|
283
|
+
/** Global threshold override */
|
|
284
|
+
threshold?: number;
|
|
285
|
+
/** Whether to print results to console. Default true. */
|
|
286
|
+
verbose?: boolean;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Attempt to auto-discover and load assay.config.ts from the current
|
|
290
|
+
* working directory. Returns an empty config if not found.
|
|
291
|
+
*
|
|
292
|
+
* Looks for:
|
|
293
|
+
* - assay.config.ts
|
|
294
|
+
* - assay.config.js
|
|
295
|
+
* - assay.config.mjs
|
|
296
|
+
*/
|
|
297
|
+
declare function resolveConfig(overrides?: AssayConfig): Promise<AssayConfig>;
|
|
298
|
+
/**
|
|
299
|
+
* Reset the cached config (useful for testing).
|
|
300
|
+
*/
|
|
301
|
+
declare function resetConfigCache(): void;
|
|
302
|
+
|
|
303
|
+
interface EvaluateConfig {
|
|
304
|
+
/** Maximum concurrent metric evaluations (default: 10) */
|
|
305
|
+
maxConcurrency?: number;
|
|
306
|
+
/** Delay between batches in ms (default: 0) */
|
|
307
|
+
throttleMs?: number;
|
|
308
|
+
/** Continue even if some metrics error (default: false) */
|
|
309
|
+
ignoreErrors?: boolean;
|
|
310
|
+
/** Show verbose output (default: true) */
|
|
311
|
+
verbose?: boolean;
|
|
312
|
+
/** Display mode: "all" | "failing" | "passing" (default: "all") */
|
|
313
|
+
display?: "all" | "failing" | "passing";
|
|
314
|
+
}
|
|
315
|
+
interface EvaluateResult {
|
|
316
|
+
testCases: Array<{
|
|
317
|
+
testCase: LLMTestCase;
|
|
318
|
+
results: MetricResult[];
|
|
319
|
+
passed: boolean;
|
|
320
|
+
}>;
|
|
321
|
+
summary: {
|
|
322
|
+
total: number;
|
|
323
|
+
passed: number;
|
|
324
|
+
failed: number;
|
|
325
|
+
passRate: number;
|
|
326
|
+
averageScores: Record<string, number>;
|
|
327
|
+
totalTimeMs: number;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Run a batch evaluation: execute all metrics on all test cases,
|
|
332
|
+
* collect results, compute summary statistics, and print a report.
|
|
333
|
+
*/
|
|
334
|
+
declare function evaluate(testCases: LLMTestCase[] | EvaluationDataset, metrics: BaseMetric[], config?: EvaluateConfig): Promise<EvaluateResult>;
|
|
335
|
+
|
|
336
|
+
interface AssertEvalOptions {
|
|
337
|
+
/** The test case to evaluate */
|
|
338
|
+
testCase: LLMTestCase;
|
|
339
|
+
/** Metrics to check */
|
|
340
|
+
metrics: BaseMetric[];
|
|
341
|
+
}
|
|
342
|
+
interface AssertEvalResult {
|
|
343
|
+
/** Whether all metrics passed */
|
|
344
|
+
passed: boolean;
|
|
345
|
+
/** Individual metric results */
|
|
346
|
+
results: MetricResult[];
|
|
347
|
+
/** Failure messages for metrics that did not pass */
|
|
348
|
+
failures: string[];
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Evaluate a single test case against one or more metrics.
|
|
352
|
+
* Designed for use inside unit tests (vitest, jest, etc).
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* const result = await assertEval({
|
|
357
|
+
* testCase: { input: "What is 2+2?", actualOutput: "4" },
|
|
358
|
+
* metrics: [new AnswerRelevancyMetric({ threshold: 0.7 })],
|
|
359
|
+
* });
|
|
360
|
+
* expect(result.passed).toBe(true);
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
declare function assertEval(options: AssertEvalOptions): Promise<AssertEvalResult>;
|
|
364
|
+
|
|
365
|
+
interface EvaluationSummary {
|
|
366
|
+
results: TestCaseResult[];
|
|
367
|
+
totalTests: number;
|
|
368
|
+
totalPassed: number;
|
|
369
|
+
totalFailed: number;
|
|
370
|
+
averageScores: Record<string, number>;
|
|
371
|
+
duration: number;
|
|
372
|
+
}
|
|
373
|
+
interface TestCaseResult {
|
|
374
|
+
testCaseName: string;
|
|
375
|
+
input: string;
|
|
376
|
+
metricResults: MetricResult[];
|
|
377
|
+
passed: boolean;
|
|
378
|
+
}
|
|
379
|
+
declare class ConsoleReporter {
|
|
380
|
+
/**
|
|
381
|
+
* Print a full evaluation summary to the console.
|
|
382
|
+
*/
|
|
383
|
+
report(summary: EvaluationSummary): void;
|
|
384
|
+
private printHeader;
|
|
385
|
+
private printResultsTable;
|
|
386
|
+
private printSummaryFooter;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Safely extracts and parses JSON from LLM responses that may contain
|
|
391
|
+
* markdown fences, surrounding text, or minor formatting issues.
|
|
392
|
+
*/
|
|
393
|
+
interface ParseJsonOptions {
|
|
394
|
+
/** If true, returns null instead of throwing on failure */
|
|
395
|
+
silent?: boolean;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Parse JSON from an LLM response string. Applies multiple strategies:
|
|
399
|
+
* 1. Direct JSON.parse
|
|
400
|
+
* 2. Strip markdown code fences, then parse
|
|
401
|
+
* 3. Remove trailing commas, then parse
|
|
402
|
+
* 4. Extract JSON substring by balanced braces
|
|
403
|
+
* 5. Regex fallback extraction
|
|
404
|
+
*
|
|
405
|
+
* @throws {Error} if all strategies fail and `silent` is not set
|
|
406
|
+
*/
|
|
407
|
+
declare function parseJson<T = unknown>(text: string, options?: ParseJsonOptions): T | null;
|
|
408
|
+
/**
|
|
409
|
+
* Convenience wrapper that always returns null on failure.
|
|
410
|
+
*/
|
|
411
|
+
declare function tryParseJson<T = unknown>(text: string): T | null;
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* A minimal p-limit style concurrency limiter.
|
|
415
|
+
* Controls the maximum number of concurrent async operations.
|
|
416
|
+
*/
|
|
417
|
+
type Limiter = <T>(fn: () => Promise<T>) => Promise<T>;
|
|
418
|
+
/**
|
|
419
|
+
* Creates a concurrency limiter that ensures no more than `concurrency`
|
|
420
|
+
* async operations run simultaneously.
|
|
421
|
+
*
|
|
422
|
+
* @param concurrency - Maximum number of concurrent operations. Must be >= 1.
|
|
423
|
+
* @returns A function that wraps async operations with concurrency control.
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```ts
|
|
427
|
+
* const limit = createLimiter(5);
|
|
428
|
+
* const results = await Promise.all(
|
|
429
|
+
* urls.map(url => limit(() => fetch(url)))
|
|
430
|
+
* );
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
declare function createLimiter(concurrency: number): Limiter;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Common scoring utilities for evaluation metrics.
|
|
437
|
+
*/
|
|
438
|
+
/**
|
|
439
|
+
* Safe division returning 0 when total is 0.
|
|
440
|
+
* Result is clamped to [0, 1].
|
|
441
|
+
*/
|
|
442
|
+
declare function ratio(count: number, total: number): number;
|
|
443
|
+
/**
|
|
444
|
+
* Compute a weighted average of values.
|
|
445
|
+
* If weights sum to 0, returns 0.
|
|
446
|
+
*
|
|
447
|
+
* @throws {Error} if values and weights have different lengths.
|
|
448
|
+
*/
|
|
449
|
+
declare function weightedAverage(values: number[], weights: number[]): number;
|
|
450
|
+
/**
|
|
451
|
+
* Compute Mean Average Precision (MAP) from a list of relevance judgments.
|
|
452
|
+
* Used for evaluating contextual precision - how well relevant items
|
|
453
|
+
* are ranked before irrelevant ones.
|
|
454
|
+
*
|
|
455
|
+
* @param relevances - Array of boolean values indicating whether each item is relevant.
|
|
456
|
+
* @returns MAP score between 0 and 1.
|
|
457
|
+
*/
|
|
458
|
+
declare function meanAveragePrecision(relevances: boolean[]): number;
|
|
459
|
+
|
|
460
|
+
export { AnswerRelevancyMetric, AnthropicProvider, type AssayConfig, type AssertEvalOptions, type AssertEvalResult, BaseLLMProvider, BaseMetric, BiasMetric, ConsoleReporter, ContextualPrecisionMetric, ContextualRecallMetric, ContextualRelevancyMetric, type ConversationalTestCase, type EvaluateConfig, type EvaluateResult, type EvaluationDataset, type EvaluationSummary, type ExactMatchConfig, ExactMatchMetric, FaithfulnessMetric, GEval, type GEvalConfig, type Golden, HallucinationMetric, type JsonCorrectnessConfig, JsonCorrectnessMetric, type LLMTestCase, type Limiter, type MetricConfig, type MetricResult, OllamaProvider, OpenAIProvider, type ParseJsonOptions, type ProviderConfig, SummarizationMetric, type TestCaseResult, type ToolCall, ToxicityMetric, assertEval, createLimiter, evaluate, meanAveragePrecision, parseJson, ratio, resetConfigCache, resolveConfig, resolveProvider, tryParseJson, weightedAverage };
|