forked from mongodb/chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestCase.ts
38 lines (32 loc) · 894 Bytes
/
TestCase.ts
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
import { z } from "zod";
export interface BaseTestCase {
name: string;
data: Record<string, unknown>;
}
export const ConversationTestCaseDataSchema = z.object({
name: z.string(),
expectation: z.string(),
messages: z
.array(
z.object({
role: z.enum(["assistant", "user"]),
content: z.string(),
})
)
.min(1),
tags: z.array(z.string()).optional(),
skip: z.boolean().optional(),
});
export type ConversationTestCaseData = z.infer<
typeof ConversationTestCaseDataSchema
>;
export interface ConversationTestCase extends BaseTestCase {
data: ConversationTestCaseData;
name: "conversation";
}
export type SomeTestCase = ConversationTestCase | BaseTestCase;
export function isConversationTestCase(
testCase: SomeTestCase
): testCase is ConversationTestCase {
return ConversationTestCaseDataSchema.safeParse(testCase.data).success;
}