-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
serde.ts
49 lines (46 loc) · 1.81 KB
/
serde.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
39
40
41
42
43
44
45
46
47
48
49
import { MessageContent } from "../messages/index.js";
import type { TemplateFormat } from "./template.js";
/**
* Represents a serialized version of a prompt template. This type is used
* to create dynamic prompts for language models. It contains an optional
* `_type` field which, if present, is set to 'prompt'. It also includes
* `input_variables`, an array of strings representing the variables to be
* used in the prompt, an optional `template_format` specifying the format
* of the template, and an optional `template` which is the actual
* template string.
*/
export type SerializedPromptTemplate = {
_type?: "prompt";
input_variables: string[];
template_format?: TemplateFormat;
template?: MessageContent;
};
/**
* Represents a serialized version of a few-shot template. This type
* includes an `_type` field set to 'few_shot', `input_variables` which
* are an array of strings representing the variables to be used in the
* template, `examples` which can be a string or an array of Example
* objects, an optional `example_prompt` which is a
* SerializedPromptTemplate, `example_separator` which is a string,
* optional `prefix` and `suffix` strings, and `template_format` which
* specifies the format of the template.
*/
export type SerializedFewShotTemplate = {
_type: "few_shot";
input_variables: string[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
examples: string | any[];
example_prompt?: SerializedPromptTemplate;
example_separator: string;
prefix?: string;
suffix?: string;
template_format: TemplateFormat;
};
/**
* Represents a serialized version of a base prompt template. This type
* can be either a SerializedFewShotTemplate or a
* SerializedPromptTemplate.
*/
export type SerializedBasePromptTemplate =
| SerializedFewShotTemplate
| SerializedPromptTemplate;