-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcompletions.ts
More file actions
350 lines (297 loc) · 8.02 KB
/
Copy pathcompletions.ts
File metadata and controls
350 lines (297 loc) · 8.02 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
// Copyright (c) The OGX Contributors.
// All rights reserved.
//
// This source code is licensed under the terms described in the LICENSE file in
// the root directory of this source tree.
//
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../resource';
import { APIPromise } from '../core';
import * as Core from '../core';
import * as CompletionsAPI from './completions';
import { Stream } from '../streaming';
/**
* OGX Inference API for generating completions, chat completions, and embeddings.
*
* This API provides the raw interface to the underlying models. Three kinds of models are supported:
* - LLM models: these models generate "raw" and "chat" (conversational) completions.
* - Embedding models: these models generate embeddings to be used for semantic search.
* - Rerank models: these models reorder the documents based on their relevance to a query.
*/
export class Completions extends APIResource {
/**
* Generate an OpenAI-compatible completion for the given prompt using the
* specified model.
*/
create(
body: CompletionCreateParamsNonStreaming,
options?: Core.RequestOptions,
): APIPromise<CompletionCreateResponse>;
create(
body: CompletionCreateParamsStreaming,
options?: Core.RequestOptions,
): APIPromise<Stream<CompletionCreateResponse>>;
create(
body: CompletionCreateParamsBase,
options?: Core.RequestOptions,
): APIPromise<Stream<CompletionCreateResponse> | CompletionCreateResponse>;
create(
body: CompletionCreateParams,
options?: Core.RequestOptions,
): APIPromise<CompletionCreateResponse> | APIPromise<Stream<CompletionCreateResponse>> {
return this._client.post('/v1/completions', { body, ...options, stream: body.stream ?? false }) as
| APIPromise<CompletionCreateResponse>
| APIPromise<Stream<CompletionCreateResponse>>;
}
}
/**
* Response from an OpenAI-compatible completion request.
*/
export interface CompletionCreateResponse {
/**
* The ID of the completion.
*/
id: string;
/**
* List of choices.
*/
choices: Array<CompletionCreateResponse.Choice>;
/**
* The Unix timestamp in seconds when the completion was created.
*/
created: number;
/**
* The model that was used to generate the completion.
*/
model: string;
/**
* The object type.
*/
object?: 'text_completion';
}
export namespace CompletionCreateResponse {
/**
* A choice from an OpenAI-compatible completion response.
*/
export interface Choice {
/**
* The reason the model stopped generating.
*/
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
/**
* The index of the choice.
*/
index: number;
/**
* The text of the choice.
*/
text: string;
/**
* The log probabilities for the tokens in the choice.
*/
logprobs?: Choice.Logprobs | null;
}
export namespace Choice {
/**
* The log probabilities for the tokens in the choice.
*/
export interface Logprobs {
/**
* The log probabilities for the tokens in the message.
*/
content?: Array<Logprobs.Content> | null;
/**
* The log probabilities for the refusal tokens.
*/
refusal?: Array<Logprobs.Refusal> | null;
}
export namespace Logprobs {
/**
* The log probability for a token from an OpenAI-compatible chat completion
* response.
*/
export interface Content {
/**
* The token.
*/
token: string;
/**
* The log probability of the token.
*/
logprob: number;
/**
* The bytes for the token.
*/
bytes?: Array<number> | null;
/**
* The top log probabilities for the token.
*/
top_logprobs?: Array<Content.TopLogprob> | null;
}
export namespace Content {
/**
* The top log probability for a token from an OpenAI-compatible chat completion
* response.
*/
export interface TopLogprob {
/**
* The token.
*/
token: string;
/**
* The log probability of the token.
*/
logprob: number;
/**
* The bytes for the token.
*/
bytes?: Array<number> | null;
}
}
/**
* The log probability for a token from an OpenAI-compatible chat completion
* response.
*/
export interface Refusal {
/**
* The token.
*/
token: string;
/**
* The log probability of the token.
*/
logprob: number;
/**
* The bytes for the token.
*/
bytes?: Array<number> | null;
/**
* The top log probabilities for the token.
*/
top_logprobs?: Array<Refusal.TopLogprob> | null;
}
export namespace Refusal {
/**
* The top log probability for a token from an OpenAI-compatible chat completion
* response.
*/
export interface TopLogprob {
/**
* The token.
*/
token: string;
/**
* The log probability of the token.
*/
logprob: number;
/**
* The bytes for the token.
*/
bytes?: Array<number> | null;
}
}
}
}
}
export type CompletionCreateParams = CompletionCreateParamsNonStreaming | CompletionCreateParamsStreaming;
export interface CompletionCreateParamsBase {
/**
* The identifier of the model to use.
*/
model: string;
/**
* The prompt to generate a completion for.
*/
prompt: string | Array<string> | Array<number> | Array<Array<number>>;
/**
* The number of completions to generate.
*/
best_of?: number | null;
/**
* Whether to echo the prompt.
*/
echo?: boolean | null;
/**
* The penalty for repeated tokens.
*/
frequency_penalty?: number | null;
/**
* The logit bias to use.
*/
logit_bias?: { [key: string]: number } | null;
/**
* Include the log probabilities on the logprobs most likely output tokens.
*/
logprobs?: number | null;
/**
* The maximum number of tokens to generate.
*/
max_tokens?: number | null;
/**
* The number of completions to generate.
*/
n?: number | null;
/**
* The penalty for repeated tokens.
*/
presence_penalty?: number | null;
/**
* The seed to use.
*/
seed?: number | null;
/**
* The stop tokens to use.
*/
stop?: string | Array<string> | null;
/**
* Whether to stream the response.
*/
stream?: boolean | null;
/**
* The stream options to use.
*/
stream_options?: { [key: string]: unknown } | null;
/**
* The suffix that should be appended to the completion.
*/
suffix?: string | null;
/**
* The temperature to use.
*/
temperature?: number | null;
/**
* The top p to use.
*/
top_p?: number | null;
/**
* The user to use.
*/
user?: string | null;
[k: string]: unknown;
}
export namespace CompletionCreateParams {
export type CompletionCreateParamsNonStreaming = CompletionsAPI.CompletionCreateParamsNonStreaming;
export type CompletionCreateParamsStreaming = CompletionsAPI.CompletionCreateParamsStreaming;
}
export interface CompletionCreateParamsNonStreaming extends CompletionCreateParamsBase {
/**
* Whether to stream the response.
*/
stream?: false | null;
[k: string]: unknown;
}
export interface CompletionCreateParamsStreaming extends CompletionCreateParamsBase {
/**
* Whether to stream the response.
*/
stream: true;
[k: string]: unknown;
}
export declare namespace Completions {
export {
type CompletionCreateResponse as CompletionCreateResponse,
type CompletionCreateParams as CompletionCreateParams,
type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
};
}