@outputai/evals 0.1.2-dev.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/verify.js DELETED
@@ -1,18 +0,0 @@
1
- import { evaluator, z } from '@outputai/core';
2
- export const verify = (options, fn) => {
3
- const inputSchema = z.object({
4
- input: options.input ?? z.any(),
5
- output: options.output ?? z.any(),
6
- ground_truth: z.record(z.string(), z.unknown()).optional()
7
- });
8
- const wrappedFn = async (data) => {
9
- const groundTruth = data.ground_truth ?? {};
10
- return fn({ input: data.input, output: data.output, context: { ground_truth: groundTruth } });
11
- };
12
- return evaluator({
13
- name: options.name,
14
- description: options.name,
15
- inputSchema,
16
- fn: wrappedFn
17
- });
18
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,70 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { verify } from './verify.js';
3
- import { getMetadata } from '@outputai/core/sdk_utils';
4
- import { EvaluationBooleanResult, z } from '@outputai/core';
5
- import { Verdict } from './verdict.js';
6
- describe('verify', () => {
7
- it('returns a function with metadata matching the given name', () => {
8
- const ev = verify({ name: 'my_eval' }, () => Verdict.isTrue(true));
9
- const meta = getMetadata(ev);
10
- expect(meta).not.toBeNull();
11
- expect(meta.name).toBe('my_eval');
12
- expect(meta.description).toBe('my_eval');
13
- });
14
- it('passes input and output to the user function', async () => {
15
- const captured = [];
16
- const ev = verify({ name: 'capture_test' }, ctx => {
17
- captured.push(ctx);
18
- return Verdict.isTrue(true);
19
- });
20
- await ev({
21
- input: { values: [1, 2] },
22
- output: { result: 3 },
23
- ground_truth: { key: 'val' }
24
- });
25
- expect(captured).toHaveLength(1);
26
- expect(captured[0].input).toEqual({ values: [1, 2] });
27
- expect(captured[0].output).toEqual({ result: 3 });
28
- expect(captured[0].context.ground_truth).toEqual({ key: 'val' });
29
- });
30
- it('defaults ground_truth to empty object when undefined', async () => {
31
- const captured = [];
32
- const ev = verify({ name: 'default_ground_truth_test' }, ({ context }) => {
33
- captured.push(context.ground_truth);
34
- return Verdict.isTrue(true);
35
- });
36
- await ev({ input: {}, output: {} });
37
- expect(captured[0]).toEqual({});
38
- });
39
- it('returns EvaluationResult from user fn as-is', async () => {
40
- const ev = verify({
41
- name: 'return_test',
42
- input: z.object({ x: z.number() }),
43
- output: z.object({ result: z.number() })
44
- }, ({ input, output }) => Verdict.equals(output.result, input.x));
45
- const result = await ev({ input: { x: 5 }, output: { result: 5 } });
46
- expect(result).toBeInstanceOf(EvaluationBooleanResult);
47
- expect(result.value).toBe(true);
48
- expect(result.confidence).toBe(1.0);
49
- });
50
- it('returns failing result when assertion fails', async () => {
51
- const ev = verify({
52
- name: 'fail_test',
53
- input: z.object({ x: z.number() }),
54
- output: z.object({ result: z.number() })
55
- }, ({ input, output }) => Verdict.equals(output.result, input.x));
56
- const result = await ev({ input: { x: 5 }, output: { result: 10 } });
57
- expect(result).toBeInstanceOf(EvaluationBooleanResult);
58
- expect(result.value).toBe(false);
59
- expect(result.confidence).toBe(1.0);
60
- });
61
- it('provides type inference via Zod schemas without as-casts', async () => {
62
- const ev = verify({
63
- name: 'typed_test',
64
- input: z.object({ values: z.array(z.number()) }),
65
- output: z.object({ sum: z.number() })
66
- }, ({ input, output }) => Verdict.equals(output.sum, input.values.reduce((a, b) => a + b, 0)));
67
- const result = await ev({ input: { values: [1, 2, 3] }, output: { sum: 6 } });
68
- expect(result.value).toBe(true);
69
- });
70
- });