-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtypes.ts
More file actions
123 lines (105 loc) · 3.47 KB
/
Copy pathtypes.ts
File metadata and controls
123 lines (105 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import {
FunctionId as functionIdSchema,
InvokeParent as invokeParentSchema,
RunEval as runEvalSchema,
PromptData as promptDataSchema,
} from "../src/generated_types";
import { z } from "zod/v3";
import { EvaluatorDef } from "../src/framework";
import { BaseMetadata } from "../src/logger";
export const evalBodySchema = z.object({
name: z.string(),
parameters: z.record(z.string(), z.unknown()).nullish(),
data: runEvalSchema.shape.data,
scores: z
.array(
z.object({
function_id: functionIdSchema,
name: z.string(),
}),
)
.nullish(),
experiment_name: z.string().nullish(),
project_id: z.string().nullish(),
on_complete_webhook: z.string().nullish(),
parent: invokeParentSchema.optional(),
stream: z.boolean().optional(),
});
export type EvaluatorManifest = Record<
string,
EvaluatorDef<unknown, unknown, unknown, BaseMetadata>
>;
export const staticParametersSchema = z.record(
z.string(),
z.union([
z.object({
type: z.literal("prompt"),
default: promptDataSchema.optional(),
description: z.string().optional(),
}),
z.object({
type: z.literal("model"),
default: z.string().optional(),
description: z.string().optional(),
}),
z.object({
type: z.literal("data"),
schema: z.record(z.unknown()),
default: z.unknown().optional(),
description: z.string().optional(),
}),
]),
);
export type StaticParametersSchema = z.infer<typeof staticParametersSchema>;
const evalParametersSerializedSchema = staticParametersSchema;
export type EvalParameterSerializedSchema = z.infer<
typeof evalParametersSerializedSchema
>;
export const parametersSchema = z.object({
type: z.literal("object"),
properties: z.record(z.string(), z.record(z.unknown())),
required: z.array(z.string()).optional(),
additionalProperties: z.boolean().optional(),
});
export type ParametersSchema = z.infer<typeof parametersSchema>;
const parametersSourceSchema = z.object({
parametersId: z.string().optional(),
slug: z.string(),
name: z.string(),
projectId: z.string().optional(),
version: z.string().optional(),
});
export type ParametersSource = z.infer<typeof parametersSourceSchema>;
const parametersContainerSchema = z.object({
type: z.literal("braintrust.parameters"),
schema: parametersSchema,
source: parametersSourceSchema,
});
export type ParametersContainer = z.infer<typeof parametersContainerSchema>;
const staticParametersContainerSchema = z.object({
type: z.literal("braintrust.staticParameters"),
schema: staticParametersSchema,
source: z.null(),
});
export type StaticParametersContainer = z.infer<
typeof staticParametersContainerSchema
>;
export const serializedParametersContainerSchema = z.union([
parametersContainerSchema,
staticParametersContainerSchema,
// keeping this type here since old versions of the SDK will still pass the unwrapped schema and we need to handle this in the app
staticParametersSchema,
]);
export type SerializedParametersContainer = z.infer<
typeof serializedParametersContainerSchema
>;
export const evaluatorDefinitionSchema = z.object({
parameters: serializedParametersContainerSchema.optional(),
scores: z.array(z.object({ name: z.string() })).optional(),
});
export type EvaluatorDefinition = z.infer<typeof evaluatorDefinitionSchema>;
export const evaluatorDefinitionsSchema = z.record(
z.string(),
evaluatorDefinitionSchema,
);
export type EvaluatorDefinitions = z.infer<typeof evaluatorDefinitionsSchema>;