@ai-sdk/openai 0.0.0-85f9a635-20240518005312

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,255 @@
1
+ import { LanguageModelV1, EmbeddingModelV1 } from '@ai-sdk/provider';
2
+
3
+ type OpenAIChatModelId = 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k-0613' | (string & {});
4
+ interface OpenAIChatSettings {
5
+ /**
6
+ Modify the likelihood of specified tokens appearing in the completion.
7
+
8
+ Accepts a JSON object that maps tokens (specified by their token ID in
9
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
10
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
11
+ the bias is added to the logits generated by the model prior to sampling.
12
+ The exact effect will vary per model, but values between -1 and 1 should
13
+ decrease or increase likelihood of selection; values like -100 or 100
14
+ should result in a ban or exclusive selection of the relevant token.
15
+
16
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
17
+ token from being generated.
18
+ */
19
+ logitBias?: Record<number, number>;
20
+ /**
21
+ Return the log probabilities of the tokens. Including logprobs will increase
22
+ the response size and can slow down response times. However, it can
23
+ be useful to better understand how the model is behaving.
24
+
25
+ Setting to true will return the log probabilities of the tokens that
26
+ were generated.
27
+
28
+ Setting to a number will return the log probabilities of the top n
29
+ tokens that were generated.
30
+ */
31
+ logprobs?: boolean | number;
32
+ /**
33
+ A unique identifier representing your end-user, which can help OpenAI to
34
+ monitor and detect abuse. Learn more.
35
+ */
36
+ user?: string;
37
+ }
38
+
39
+ type OpenAIChatConfig = {
40
+ provider: string;
41
+ baseURL: string;
42
+ compatibility: 'strict' | 'compatible';
43
+ headers: () => Record<string, string | undefined>;
44
+ };
45
+ declare class OpenAIChatLanguageModel implements LanguageModelV1 {
46
+ readonly specificationVersion = "v1";
47
+ readonly defaultObjectGenerationMode = "tool";
48
+ readonly modelId: OpenAIChatModelId;
49
+ readonly settings: OpenAIChatSettings;
50
+ private readonly config;
51
+ constructor(modelId: OpenAIChatModelId, settings: OpenAIChatSettings, config: OpenAIChatConfig);
52
+ get provider(): string;
53
+ private getArgs;
54
+ doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
55
+ doRawStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Omit<Awaited<ReturnType<LanguageModelV1['doStream']>>, 'stream'> & {
56
+ stream: ReadableStream<Uint8Array>;
57
+ }>;
58
+ doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
59
+ }
60
+
61
+ type OpenAICompletionModelId = 'gpt-3.5-turbo-instruct' | (string & {});
62
+ interface OpenAICompletionSettings {
63
+ /**
64
+ Echo back the prompt in addition to the completion.
65
+ */
66
+ echo?: boolean;
67
+ /**
68
+ Modify the likelihood of specified tokens appearing in the completion.
69
+
70
+ Accepts a JSON object that maps tokens (specified by their token ID in
71
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
72
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
73
+ the bias is added to the logits generated by the model prior to sampling.
74
+ The exact effect will vary per model, but values between -1 and 1 should
75
+ decrease or increase likelihood of selection; values like -100 or 100
76
+ should result in a ban or exclusive selection of the relevant token.
77
+
78
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
79
+ token from being generated.
80
+ */
81
+ logitBias?: Record<number, number>;
82
+ /**
83
+ Return the log probabilities of the tokens. Including logprobs will increase
84
+ the response size and can slow down response times. However, it can
85
+ be useful to better understand how the model is behaving.
86
+
87
+ Setting to true will return the log probabilities of the tokens that
88
+ were generated.
89
+
90
+ Setting to a number will return the log probabilities of the top n
91
+ tokens that were generated.
92
+ */
93
+ logprobs?: boolean | number;
94
+ /**
95
+ The suffix that comes after a completion of inserted text.
96
+ */
97
+ suffix?: string;
98
+ /**
99
+ A unique identifier representing your end-user, which can help OpenAI to
100
+ monitor and detect abuse. Learn more.
101
+ */
102
+ user?: string;
103
+ }
104
+
105
+ type OpenAICompletionConfig = {
106
+ provider: string;
107
+ baseURL: string;
108
+ compatibility: 'strict' | 'compatible';
109
+ headers: () => Record<string, string | undefined>;
110
+ };
111
+ declare class OpenAICompletionLanguageModel implements LanguageModelV1 {
112
+ readonly specificationVersion = "v1";
113
+ readonly defaultObjectGenerationMode: undefined;
114
+ readonly modelId: OpenAICompletionModelId;
115
+ readonly settings: OpenAICompletionSettings;
116
+ private readonly config;
117
+ constructor(modelId: OpenAICompletionModelId, settings: OpenAICompletionSettings, config: OpenAICompletionConfig);
118
+ get provider(): string;
119
+ private getArgs;
120
+ doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
121
+ doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
122
+ }
123
+
124
+ type OpenAIEmbeddingModelId = 'text-embedding-3-small' | 'text-embedding-3-large' | 'text-embedding-ada-002' | (string & {});
125
+ interface OpenAIEmbeddingSettings {
126
+ /**
127
+ Override the maximum number of embeddings per call.
128
+ */
129
+ maxEmbeddingsPerCall?: number;
130
+ /**
131
+ Override the parallelism of embedding calls.
132
+ */
133
+ supportsParallelCalls?: boolean;
134
+ /**
135
+ The number of dimensions the resulting output embeddings should have.
136
+ Only supported in text-embedding-3 and later models.
137
+ */
138
+ dimensions?: number;
139
+ /**
140
+ A unique identifier representing your end-user, which can help OpenAI to
141
+ monitor and detect abuse. Learn more.
142
+ */
143
+ user?: string;
144
+ }
145
+
146
+ type OpenAIEmbeddingConfig = {
147
+ provider: string;
148
+ baseURL: string;
149
+ headers: () => Record<string, string | undefined>;
150
+ };
151
+ declare class OpenAIEmbeddingModel implements EmbeddingModelV1<string> {
152
+ readonly specificationVersion = "v1";
153
+ readonly modelId: OpenAIEmbeddingModelId;
154
+ private readonly config;
155
+ private readonly settings;
156
+ get provider(): string;
157
+ get maxEmbeddingsPerCall(): number;
158
+ get supportsParallelCalls(): boolean;
159
+ constructor(modelId: OpenAIEmbeddingModelId, settings: OpenAIEmbeddingSettings, config: OpenAIEmbeddingConfig);
160
+ doEmbed({ values, abortSignal, }: Parameters<EmbeddingModelV1<string>['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV1<string>['doEmbed']>>>;
161
+ }
162
+
163
+ interface OpenAIProvider {
164
+ (modelId: 'gpt-3.5-turbo-instruct', settings?: OpenAICompletionSettings): OpenAICompletionLanguageModel;
165
+ (modelId: OpenAIChatModelId, settings?: OpenAIChatSettings): OpenAIChatLanguageModel;
166
+ /**
167
+ Creates an OpenAI chat model for text generation.
168
+ */
169
+ chat(modelId: OpenAIChatModelId, settings?: OpenAIChatSettings): OpenAIChatLanguageModel;
170
+ /**
171
+ Creates an OpenAI completion model for text generation.
172
+ */
173
+ completion(modelId: OpenAICompletionModelId, settings?: OpenAICompletionSettings): OpenAICompletionLanguageModel;
174
+ /**
175
+ Creates a model for text embeddings.
176
+ */
177
+ embedding(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings): OpenAIEmbeddingModel;
178
+ }
179
+ interface OpenAIProviderSettings {
180
+ /**
181
+ Base URL for the OpenAI API calls.
182
+ */
183
+ baseURL?: string;
184
+ /**
185
+ @deprecated Use `baseURL` instead.
186
+ */
187
+ baseUrl?: string;
188
+ /**
189
+ API key for authenticating requests.
190
+ */
191
+ apiKey?: string;
192
+ /**
193
+ OpenAI Organization.
194
+ */
195
+ organization?: string;
196
+ /**
197
+ OpenAI project.
198
+ */
199
+ project?: string;
200
+ /**
201
+ Custom headers to include in the requests.
202
+ */
203
+ headers?: Record<string, string>;
204
+ /**
205
+ OpenAI compatibility mode. Should be set to `strict` when using the OpenAI API,
206
+ and `compatible` when using 3rd party providers. In `compatible` mode, newer
207
+ information such as streamOptions are not being sent. Defaults to 'compatible'.
208
+ */
209
+ compatibility?: 'strict' | 'compatible';
210
+ }
211
+ /**
212
+ Create an OpenAI provider instance.
213
+ */
214
+ declare function createOpenAI(options?: OpenAIProviderSettings): OpenAIProvider;
215
+ /**
216
+ Default OpenAI provider instance. It uses 'strict' compatibility mode.
217
+ */
218
+ declare const openai: OpenAIProvider;
219
+
220
+ /**
221
+ @deprecated Use `createOpenAI` instead.
222
+ */
223
+ declare class OpenAI {
224
+ /**
225
+ Use a different URL prefix for API calls, e.g. to use proxy servers.
226
+ The default prefix is `https://api.openai.com/v1`.
227
+ */
228
+ readonly baseURL: string;
229
+ /**
230
+ API key that is being send using the `Authorization` header.
231
+ It defaults to the `OPENAI_API_KEY` environment variable.
232
+ */
233
+ readonly apiKey?: string;
234
+ /**
235
+ OpenAI Organization.
236
+ */
237
+ readonly organization?: string;
238
+ /**
239
+ OpenAI project.
240
+ */
241
+ readonly project?: string;
242
+ /**
243
+ Custom headers to include in the requests.
244
+ */
245
+ readonly headers?: Record<string, string>;
246
+ /**
247
+ * Creates a new OpenAI provider instance.
248
+ */
249
+ constructor(options?: OpenAIProviderSettings);
250
+ private get baseConfig();
251
+ chat(modelId: OpenAIChatModelId, settings?: OpenAIChatSettings): OpenAIChatLanguageModel;
252
+ completion(modelId: OpenAICompletionModelId, settings?: OpenAICompletionSettings): OpenAICompletionLanguageModel;
253
+ }
254
+
255
+ export { OpenAI, type OpenAIProvider, type OpenAIProviderSettings, createOpenAI, openai };