-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
serde.ts
148 lines (135 loc) Β· 4.25 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import type { SerializedLLM } from "../llms/base.js";
import type { SerializedBasePromptTemplate } from "../prompts/serde.js";
/**
* Represents the serialized form of an LLMChain. It includes properties
* such as `_type`, `llm`, and `prompt`.
*/
export type SerializedLLMChain = {
_type: "llm_chain";
llm?: SerializedLLM;
prompt?: SerializedBasePromptTemplate;
};
/**
* Represents the serialized form of a SequentialChain. It includes
* properties such as `_type`, `input_variables`, `output_variables`, and
* `chains`.
*/
export type SerializedSequentialChain = {
_type: "sequential_chain";
input_variables: string[];
output_variables: string[];
chains: SerializedBaseChain[];
};
/**
* Represents the serialized form of a SimpleSequentialChain. It includes
* properties such as `_type` and `chains`.
*/
export type SerializedSimpleSequentialChain = {
_type: "simple_sequential_chain";
chains: Array<SerializedBaseChain>;
};
/**
* Represents the serialized form of a VectorDBQAChain. It includes
* properties such as `_type`, `k`, and `combine_documents_chain`.
*/
export type SerializedVectorDBQAChain = {
_type: "vector_db_qa";
k: number;
combine_documents_chain: SerializedBaseChain;
};
/**
* Represents the serialized form of an APIChain. It includes properties
* such as `_type`, `api_request_chain`, `api_answer_chain`, and
* `api_docs`.
*/
export type SerializedAPIChain = {
_type: "api_chain";
api_request_chain: SerializedLLMChain;
api_answer_chain: SerializedLLMChain;
api_docs: string;
};
/**
* Represents the serialized form of a StuffDocumentsChain. It includes
* properties such as `_type` and `llm_chain`.
*/
export type SerializedStuffDocumentsChain = {
_type: "stuff_documents_chain";
llm_chain?: SerializedLLMChain;
};
/**
* Represents the serialized form of a ChatVectorDBQAChain. It includes
* properties such as `_type`, `k`, `combine_documents_chain`, and
* `question_generator`.
*/
export type SerializedChatVectorDBQAChain = {
_type: "chat-vector-db";
k: number;
combine_documents_chain: SerializedBaseChain;
question_generator: SerializedLLMChain;
};
/**
* Represents the serialized form of a MapReduceDocumentsChain. It
* includes properties such as `_type`, `llm_chain`, and
* `combine_document_chain`.
*/
export type SerializedMapReduceDocumentsChain = {
_type: "map_reduce_documents_chain";
llm_chain?: SerializedLLMChain;
combine_document_chain?: SerializedStuffDocumentsChain;
};
/**
* Represents the serialized form of a RefineDocumentsChain. It includes
* properties such as `_type`, `llm_chain`, and `refine_llm_chain`.
*/
export type SerializedRefineDocumentsChain = {
_type: "refine_documents_chain";
llm_chain?: SerializedLLMChain;
refine_llm_chain?: SerializedLLMChain;
};
/**
* Represents the serialized form of an AnalyzeDocumentChain. It includes
* properties such as `_type` and `combine_document_chain`.
*/
export type SerializedAnalyzeDocumentChain = {
_type: "analyze_document_chain";
combine_document_chain?: SerializedBaseChain;
};
/**
* Represents the serialized form of a ConstitutionalPrinciple. It
* includes properties such as `_type`, `critiqueRequest`,
* `revisionRequest`, and `name`.
*/
export type SerializedConstitutionalPrinciple = {
_type: "constitutional_principle";
critiqueRequest: string;
revisionRequest: string;
name: string;
};
/**
* Represents the serialized form of a ConstitutionalChain. It includes
* properties such as `_type`, `chain`, `critiqueChain`, `revisionChain`,
* and `ConstitutionalPrinciple`.
*/
export type SerializedConstitutionalChain = {
_type: "constitutional_chain";
chain?: SerializedLLMChain;
critiqueChain?: SerializedBaseChain;
revisionChain?: SerializedBaseChain;
ConstitutionalPrinciple?: SerializedConstitutionalPrinciple[];
};
/**
* Represents the serialized form of a BaseChain. It can be one of the
* above serialized chain types.
*/
export type SerializedBaseChain =
| SerializedLLMChain
| SerializedSequentialChain
| SerializedSimpleSequentialChain
| SerializedVectorDBQAChain
| SerializedAPIChain
| SerializedStuffDocumentsChain
| SerializedChatVectorDBQAChain
| SerializedMapReduceDocumentsChain
| SerializedAnalyzeDocumentChain
| SerializedRefineDocumentsChain
| SerializedConstitutionalChain;