-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompletions.ts
More file actions
222 lines (192 loc) · 6.94 KB
/
completions.ts
File metadata and controls
222 lines (192 loc) · 6.94 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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../core/resource';
import * as CompletionsAPI from './completions';
import * as Shared from './shared';
import { APIPromise } from '../core/api-promise';
import { Stream } from '../core/streaming';
import { RequestOptions } from '../internal/request-options';
export class Completions extends APIResource {
/**
* Generate text completions using the specified model and prompt. This endpoint is
* useful for text generation tasks that don't require conversational context.
*
* @example
* ```ts
* const completion = await client.completions.create({
* model: 'palmyra-x-003-instruct',
* prompt: 'Write me an SEO article about...',
* });
* ```
*/
create(body: CompletionCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Completion>;
create(
body: CompletionCreateParamsStreaming,
options?: RequestOptions,
): APIPromise<Stream<CompletionChunk>>;
create(
body: CompletionCreateParamsBase,
options?: RequestOptions,
): APIPromise<Stream<CompletionChunk> | Completion>;
create(
body: CompletionCreateParams,
options?: RequestOptions,
): APIPromise<Completion> | APIPromise<Stream<CompletionChunk>> {
return this._client.post('/v1/completions', { body, ...options, stream: body.stream ?? false }) as
| APIPromise<Completion>
| APIPromise<Stream<CompletionChunk>>;
}
}
export interface Completion {
/**
* A list of choices generated by the model, each containing the text of the
* completion and associated metadata such as log probabilities.
*/
choices: Array<Completion.Choice>;
/**
* The identifier of the model that was used to generate the responses in the
* 'choices' array.
*/
model?: string;
}
export namespace Completion {
export interface Choice {
/**
* The generated text output from the model, which forms the main content of the
* response.
*/
text: string;
log_probs?: Shared.Logprobs | null;
}
}
export interface CompletionChunk {
value: string;
}
export interface CompletionParams {
/**
* The [ID of the model](https://dev.writer.com/home/models) to use for generating
* text. Supports `palmyra-x5`, `palmyra-x4`, `palmyra-fin`, `palmyra-med`,
* `palmyra-creative`, and `palmyra-x-003-instruct`.
*/
model: string;
/**
* The input text that the model will process to generate a response.
*/
prompt: string;
/**
* Specifies the number of completions to generate and return the best one. Useful
* for generating multiple outputs and choosing the best based on some criteria.
*/
best_of?: number;
/**
* The maximum number of tokens that the model can generate in the response.
*/
max_tokens?: number;
/**
* A seed used to initialize the random number generator for the model, ensuring
* reproducibility of the output when the same inputs are provided.
*/
random_seed?: number;
/**
* Specifies stopping conditions for the model's output generation. This can be an
* array of strings or a single string that the model will look for as a signal to
* stop generating further tokens.
*/
stop?: Array<string> | string;
/**
* Determines whether the model's output should be streamed. If true, the output is
* generated and sent incrementally, which can be useful for real-time
* applications.
*/
stream?: boolean;
/**
* Controls the randomness of the model's outputs. Higher values lead to more
* random outputs, while lower values make the model more deterministic.
*/
temperature?: number;
/**
* Used to control the nucleus sampling, where only the most probable tokens with a
* cumulative probability of top_p are considered for sampling, providing a way to
* fine-tune the randomness of predictions.
*/
top_p?: number;
}
export type CompletionCreateParams = CompletionCreateParamsNonStreaming | CompletionCreateParamsStreaming;
export interface CompletionCreateParamsBase {
/**
* The [ID of the model](https://dev.writer.com/home/models) to use for generating
* text. Supports `palmyra-x5`, `palmyra-x4`, `palmyra-fin`, `palmyra-med`,
* `palmyra-creative`, and `palmyra-x-003-instruct`.
*/
model: string;
/**
* The input text that the model will process to generate a response.
*/
prompt: string;
/**
* Specifies the number of completions to generate and return the best one. Useful
* for generating multiple outputs and choosing the best based on some criteria.
*/
best_of?: number;
/**
* The maximum number of tokens that the model can generate in the response.
*/
max_tokens?: number;
/**
* A seed used to initialize the random number generator for the model, ensuring
* reproducibility of the output when the same inputs are provided.
*/
random_seed?: number;
/**
* Specifies stopping conditions for the model's output generation. This can be an
* array of strings or a single string that the model will look for as a signal to
* stop generating further tokens.
*/
stop?: Array<string> | string;
/**
* Determines whether the model's output should be streamed. If true, the output is
* generated and sent incrementally, which can be useful for real-time
* applications.
*/
stream?: boolean;
/**
* Controls the randomness of the model's outputs. Higher values lead to more
* random outputs, while lower values make the model more deterministic.
*/
temperature?: number;
/**
* Used to control the nucleus sampling, where only the most probable tokens with a
* cumulative probability of top_p are considered for sampling, providing a way to
* fine-tune the randomness of predictions.
*/
top_p?: number;
}
export namespace CompletionCreateParams {
export type CompletionCreateParamsNonStreaming = CompletionsAPI.CompletionCreateParamsNonStreaming;
export type CompletionCreateParamsStreaming = CompletionsAPI.CompletionCreateParamsStreaming;
}
export interface CompletionCreateParamsNonStreaming extends CompletionCreateParamsBase {
/**
* Determines whether the model's output should be streamed. If true, the output is
* generated and sent incrementally, which can be useful for real-time
* applications.
*/
stream?: false;
}
export interface CompletionCreateParamsStreaming extends CompletionCreateParamsBase {
/**
* Determines whether the model's output should be streamed. If true, the output is
* generated and sent incrementally, which can be useful for real-time
* applications.
*/
stream: true;
}
export declare namespace Completions {
export {
type Completion as Completion,
type CompletionChunk as CompletionChunk,
type CompletionParams as CompletionParams,
type CompletionCreateParams as CompletionCreateParams,
type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
};
}