-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
208 lines (179 loc) · 5.06 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
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
import { SummaryLanguage } from "../common/types";
import { Query } from "./apiTypes";
export type { Query } from "./apiTypes";
export type GenerationConfig = {
// The preferred prompt to use, if applicable
generationPresetName?: string;
// The number of search results to include in creating the summary
maxUsedSearchResults?: number;
// Custom prompt for summarization.
promptTemplate?: string;
maxResponseCharacters?: number;
// The language the summary should be in.
responseLanguage?: SummaryLanguage;
modelParameters?: {
maxTokens: number;
temperature: number;
frequencyPenalty: number;
presencePenalty: number;
};
citations?:
| {
style: "none" | "numeric";
}
| {
style: "html" | "markdown";
urlPattern: string;
textPattern: string;
};
enableFactualConsistencyScore?: boolean;
};
export type Reranker =
| { type: "none" }
| { type: "customer_reranker"; rerankerId: string }
| { type: "mmr"; diversityBias: number }
| { type: "userfn"; userFunction?: string };
export type StreamQueryConfig = {
// The customer ID of the Vectara corpora owner.
customerId: string;
// The Vectara query API key that has access to the corpora you're querying.
apiKey?: string;
// Alternatively specify the JWT token to use for authentication.
authToken?: string;
// An optional domain to send the query to. Useful for proxying API requests.
// Expects specific endpoints to be available at <domain>/v2/query,
// <domain>/v2/chats/:chatId/turns, and <domain>/v2/chats
domain?: string;
// The query to send to the API. This is the user input.
query: string;
corpusKey: string;
search: {
metadataFilter: string;
// A number from 0.0 -> 1.0 that determines how much to leverage neural search and keyword search.
// A value of 0.0 is purely neural search, where a value of 1.0 is purely keyword search.
// Numbers in between are a combination of the two, leaning one way or another.
lexicalInterpolation?: number;
customDimensions?: Record<string, number>;
semantics?: "default" | "query" | "response";
offset: number;
limit?: number;
contextConfiguration?: {
charactersBefore?: number;
charactersAfter?: number;
// For summary references, this is the number of sentences to include before
// relevant reference snippets.
sentencesBefore?: number;
// For summary references, this is the number of sentences to include after
// relevant reference snippets.
sentencesAfter?: number;
startTag?: string;
endTag?: string;
};
reranker?:
| { type: "none" }
| {
type: "customer_reranker";
rerankerId: string;
}
| {
type: "mmr";
// Diversity bias ranges from 0 to 1.
// 0 will optimize for results that are as closely related to the query as possible.
// 1 will optimize for results that are as diverse as possible.
diversityBias: number;
}
| {
type: "userfn";
userFunction?: string;
}
| {
type: "chain";
rerankers: Reranker[];
};
};
generation?: GenerationConfig;
chat?: {
store?: boolean;
conversationId?: string;
};
};
export type StreamQueryRequestHeaders = {
["customer-id"]: string;
["Content-Type"]: string;
["x-api-key"]?: string;
["Authorization"]?: string;
};
export type StreamQueryRequest = {
method: string;
url: string;
headers: StreamQueryRequestHeaders;
body: Query.Body;
};
export type StreamEvent =
| ErrorEvent
| SearchResultsEvent
| ChatInfoEvent
| GenerationChunkEvent
| GenerationInfoEvent
| GenerationEndEvent
| FactualConsistencyScoreEvent
| EndEvent
| UnexpectedEvent
| RequestErrorEvent
| GenericErrorEvent
| UnexpectedErrorEvent;
type BaseEvent = {
raw?: any;
};
export type ErrorEvent = BaseEvent & {
type: "error";
messages: string[];
};
export type SearchResultsEvent = BaseEvent & {
type: "searchResults";
searchResults: Query.SearchResult[];
};
export type ChatInfoEvent = BaseEvent & {
type: "chatInfo";
chatId: string;
turnId: string;
};
export type GenerationChunkEvent = BaseEvent & {
type: "generationChunk";
updatedText: string;
generationChunk: string;
};
export type GenerationInfoEvent = BaseEvent & {
type: "generationInfo";
renderedPrompt?: string;
rephrasedQuery?: string;
};
export type GenerationEndEvent = BaseEvent & {
type: "generationEnd";
};
export type FactualConsistencyScoreEvent = BaseEvent & {
type: "factualConsistencyScore";
factualConsistencyScore: number;
};
export type EndEvent = BaseEvent & {
type: "end";
};
export type UnexpectedEvent = {
type: "unexpectedEvent";
rawType: string;
raw: any;
};
export type RequestErrorEvent = {
type: "requestError";
status: number;
raw: any;
};
export type GenericErrorEvent = {
type: "genericError";
error: Error;
};
export type UnexpectedErrorEvent = {
type: "unexpectedError";
raw: any;
};
export type StreamEventHandler = (event: StreamEvent) => void;