-
Notifications
You must be signed in to change notification settings - Fork 14
/
types.ts
173 lines (153 loc) · 3.32 KB
/
types.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
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
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;
question: string;
answer: string;
results: SearchResultWithSnippet[];
factualConsistencyScore?: number;
};
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 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%";