-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtypes.ts
More file actions
240 lines (206 loc) · 5.22 KB
/
types.ts
File metadata and controls
240 lines (206 loc) · 5.22 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
export type SearchResult = {
document_id: string;
document_metadata: Record<string, unknown>;
part_metadata: Record<string, unknown>;
score: number;
text: string;
};
export type SearchResultWithSnippet = SearchResult & {
snippet: {
pre: string;
text: string;
post: string;
};
};
export const SUMMARY_LANGUAGES = [
"auto",
"eng",
"deu",
"fra",
"zho",
"kor",
"ara",
"rus",
"tha",
"nld",
"ita",
"por",
"spa",
"jpn",
"pol",
"tur",
"heb",
"vie",
"ind",
"ces",
"ukr",
"ell",
"fas",
"hin",
"urd",
"swe",
"ben",
"msa",
"ron"
] as const;
export type SummaryLanguage = (typeof SUMMARY_LANGUAGES)[number];
export type SearchError = {
message?: string;
response?: {
data?: {
message?: string;
};
};
};
export type ChatTurn = {
id: string;
type: "turn";
question: string;
answer: string;
results: SearchResultWithSnippet[];
factualConsistencyScore?: number;
};
export type ChatAction = {
id: string;
type: "action";
options: Array<ChatActionOption>;
};
export type ChatActionOption = {
label: string;
// An optional message to send to the chatbot when the user selects this action.
message?: string;
// An optional link to send the user to when they select this action.
url?: string;
onSelect?: () => void;
};
export type MessageHistoryItem = ChatTurn | ChatAction;
export type NoneReranker = { type: "none" };
export type CustomerSpecificReranker = {
type: "customer_reranker";
reranker_id: string;
};
export type MmrReranker = {
type: "mmr";
diversity_bias: number;
};
export type SearchConfiguration = {
corpora: {
corpus_key: string;
metadata_filter?: string;
lexical_interpolation?: number;
custom_dimensions?: Record<string, number>;
semantics?: "default" | "query" | "response";
}[];
offset: number;
limit?: number;
context_configuration?: {
characters_before?: number;
characters_after?: number;
sentences_before?: number;
sentences_after?: number;
start_tag?: string;
end_tag?: string;
};
reranker?: NoneReranker | CustomerSpecificReranker | MmrReranker;
};
export type NoneCitations = {
style: "none";
};
export type NumericCitations = {
style: "numeric";
};
export type HtmlCitations = {
style: "html";
url_pattern: string;
text_pattern: string;
};
export type MarkdownCitations = {
style: "markdown";
url_pattern: string;
text_pattern: string;
};
export type GenerationConfiguration = {
prompt_name?: string;
max_used_search_results?: number;
prompt_text?: string;
max_response_characters?: number;
response_language?: SummaryLanguage;
model_parameters?: {
max_tokens: number;
temperature: number;
frequency_penalty: number;
presence_penalty: number;
};
citations?: NoneCitations | NumericCitations | HtmlCitations | MarkdownCitations;
enable_factual_consistency_score?: boolean;
};
export type ChatConfiguration = {
store?: boolean;
conversation_id?: string;
};
export type ChatQueryBody = {
query: string;
search: SearchConfiguration;
stream_response?: boolean;
generation?: GenerationConfiguration;
chat?: ChatConfiguration;
};
export type ChatQueryRequestHeaders = {
["customer-id"]: string;
["Content-Type"]: string;
["x-api-key"]?: string;
["Authorization"]?: string;
};
export type ChatQueryResponse = {
chat_id: string;
turn_id: string;
answer: string;
search_results: SearchResult[];
factual_consistency_score: number;
response_language: string;
rendered_prompt: string;
rephrased_query: string;
};
export type AgenticMessageHistoryItem = {
role: "user" | "chatbot";
message: string;
};
export type AgenticResponse = {
// Any string that corresponds to an event.
// Useful for specifying behaviors to be executed in the agentic configuration callback.
event: string;
// An optional message from the service
message?: AgenticMessage;
};
export type AgenticMessage = {
content?: string;
post?: string;
};
/**
* Configuration for connecting to an agentic service.
* Use the `onAgenticResponse` callback to execute any side effects in parent component.
* Notes:
* - The chat history, including the user's most recent message is sent to the service.
* - The service response must conform to the AgenticResponse type.
*/
export type AgenticConfiguration = {
// The URL of the web service that responds in the form of the AgenticResponse type.
url: string;
// A callback for handling the web service response.
// Can return an AgenticResponseActionConfiguration to display a message and optional actions for the user to take.
onAgenticResponse: (response: AgenticResponse) => AgenticResponseActionConfiguration | undefined;
};
/**
* An configuration that can be returned by the agentic response handler.
*/
export type AgenticResponseActionConfiguration = {
// The message that the chatbot should show the user.
message: AgenticMessage;
// An optional array of actions that the user can take to respond.
userActionOptions?: Array<ChatActionOption>;
};
export type RerankerId = 272725719 | 272725718;
export const mmrRerankerId = 272725718;
export const DEFAULT_DOMAIN = "https://api.vectara.io";
export const START_TAG = "%START_SNIPPET%";
export const END_TAG = "%END_SNIPPET%";