@ai-sdk/openai-compatible 1.0.0-canary.1 → 1.0.0-canary.11

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,122 @@
1
1
  # @ai-sdk/openai-compatible
2
2
 
3
+ ## 1.0.0-canary.11
4
+
5
+ ### Patch Changes
6
+
7
+ - db72adc: chore(providers/openai): update completion model to use providerOptions
8
+ - 42e32b0: feat(providers/xai): add reasoningEffort provider option
9
+ - 66962ed: fix(packages): export node10 compatible types
10
+ - 9301f86: refactor (image-model): rename `ImageModelV1` to `ImageModelV2`
11
+ - Updated dependencies [66962ed]
12
+ - Updated dependencies [9301f86]
13
+ - Updated dependencies [a3f768e]
14
+ - @ai-sdk/provider-utils@3.0.0-canary.11
15
+ - @ai-sdk/provider@2.0.0-canary.10
16
+
17
+ ## 1.0.0-canary.10
18
+
19
+ ### Patch Changes
20
+
21
+ - cf8280e: fix(providers/xai): return actual usage when streaming instead of NaN
22
+ - Updated dependencies [e86be6f]
23
+ - @ai-sdk/provider@2.0.0-canary.9
24
+ - @ai-sdk/provider-utils@3.0.0-canary.10
25
+
26
+ ## 1.0.0-canary.9
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [95857aa]
31
+ - Updated dependencies [7ea4132]
32
+ - @ai-sdk/provider@2.0.0-canary.8
33
+ - @ai-sdk/provider-utils@3.0.0-canary.9
34
+
35
+ ## 1.0.0-canary.8
36
+
37
+ ### Patch Changes
38
+
39
+ - b9a6121: fix (provider/openai-compatible): change tool_call type schema to nullish
40
+ - Updated dependencies [5d142ab]
41
+ - Updated dependencies [b6b43c7]
42
+ - Updated dependencies [8aa9e20]
43
+ - Updated dependencies [3795467]
44
+ - @ai-sdk/provider-utils@3.0.0-canary.8
45
+ - @ai-sdk/provider@2.0.0-canary.7
46
+
47
+ ## 1.0.0-canary.7
48
+
49
+ ### Patch Changes
50
+
51
+ - fa49207: feat(providers/openai-compatible): convert to providerOptions
52
+ - 26735b5: chore(embedding-model): add v2 interface
53
+ - 443d8ec: feat(embedding-model-v2): add response body field
54
+ - fd65bc6: chore(embedding-model-v2): rename rawResponse to response
55
+ - Updated dependencies [26735b5]
56
+ - Updated dependencies [443d8ec]
57
+ - Updated dependencies [14c9410]
58
+ - Updated dependencies [d9c98f4]
59
+ - Updated dependencies [c4a2fec]
60
+ - Updated dependencies [0054544]
61
+ - Updated dependencies [9e9c809]
62
+ - Updated dependencies [32831c6]
63
+ - Updated dependencies [d0f9495]
64
+ - Updated dependencies [fd65bc6]
65
+ - Updated dependencies [393138b]
66
+ - Updated dependencies [7182d14]
67
+ - @ai-sdk/provider@2.0.0-canary.6
68
+ - @ai-sdk/provider-utils@3.0.0-canary.7
69
+
70
+ ## 1.0.0-canary.6
71
+
72
+ ### Patch Changes
73
+
74
+ - 6db02c9: chore(openai-compatible): remove simulateStreaming
75
+ - Updated dependencies [411e483]
76
+ - Updated dependencies [79457bd]
77
+ - Updated dependencies [ad80501]
78
+ - Updated dependencies [1766ede]
79
+ - Updated dependencies [f10304b]
80
+ - @ai-sdk/provider@2.0.0-canary.5
81
+ - @ai-sdk/provider-utils@3.0.0-canary.6
82
+
83
+ ## 1.0.0-canary.5
84
+
85
+ ### Patch Changes
86
+
87
+ - Updated dependencies [6f6bb89]
88
+ - @ai-sdk/provider@2.0.0-canary.4
89
+ - @ai-sdk/provider-utils@3.0.0-canary.5
90
+
91
+ ## 1.0.0-canary.4
92
+
93
+ ### Patch Changes
94
+
95
+ - Updated dependencies [d1a1aa1]
96
+ - @ai-sdk/provider@2.0.0-canary.3
97
+ - @ai-sdk/provider-utils@3.0.0-canary.4
98
+
99
+ ## 1.0.0-canary.3
100
+
101
+ ### Patch Changes
102
+
103
+ - Updated dependencies [a166433]
104
+ - Updated dependencies [abf9a79]
105
+ - Updated dependencies [9f95b35]
106
+ - Updated dependencies [0a87932]
107
+ - Updated dependencies [6dc848c]
108
+ - @ai-sdk/provider-utils@3.0.0-canary.3
109
+ - @ai-sdk/provider@2.0.0-canary.2
110
+
111
+ ## 1.0.0-canary.2
112
+
113
+ ### Patch Changes
114
+
115
+ - Updated dependencies [c57e248]
116
+ - Updated dependencies [33f4a6a]
117
+ - @ai-sdk/provider@2.0.0-canary.1
118
+ - @ai-sdk/provider-utils@3.0.0-canary.2
119
+
3
120
  ## 1.0.0-canary.1
4
121
 
5
122
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,22 +1,26 @@
1
- import { LanguageModelV2ProviderMetadata, LanguageModelV2, LanguageModelV2ObjectGenerationMode, EmbeddingModelV1, ImageModelV1, ProviderV2 } from '@ai-sdk/provider';
1
+ import { SharedV2ProviderMetadata, LanguageModelV2, EmbeddingModelV2, ImageModelV2, ProviderV2 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
3
  import { z, ZodSchema } from 'zod';
4
4
 
5
5
  type OpenAICompatibleChatModelId = string;
6
- interface OpenAICompatibleChatSettings {
6
+ declare const openaiCompatibleProviderOptions: z.ZodObject<{
7
7
  /**
8
- A unique identifier representing your end-user, which can help the provider to
9
- monitor and detect abuse.
10
- */
11
- user?: string;
8
+ * A unique identifier representing your end-user, which can help the provider to
9
+ * monitor and detect abuse.
10
+ */
11
+ user: z.ZodOptional<z.ZodString>;
12
12
  /**
13
- Simulates streaming by using a normal generate call and returning it as a stream.
14
- Enable this if the model that you are using does not support streaming.
15
-
16
- Defaults to `false`.
13
+ * Reasoning effort for reasoning models. Defaults to `medium`.
17
14
  */
18
- simulateStreaming?: boolean;
19
- }
15
+ reasoningEffort: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
16
+ }, "strip", z.ZodTypeAny, {
17
+ user?: string | undefined;
18
+ reasoningEffort?: "low" | "medium" | "high" | undefined;
19
+ }, {
20
+ user?: string | undefined;
21
+ reasoningEffort?: "low" | "medium" | "high" | undefined;
22
+ }>;
23
+ type OpenAICompatibleProviderOptions = z.infer<typeof openaiCompatibleProviderOptions>;
20
24
 
21
25
  declare const openaiCompatibleErrorDataSchema: z.ZodObject<{
22
26
  error: z.ZodObject<{
@@ -73,7 +77,7 @@ type MetadataExtractor = {
73
77
  */
74
78
  extractMetadata: ({ parsedBody, }: {
75
79
  parsedBody: unknown;
76
- }) => LanguageModelV2ProviderMetadata | undefined;
80
+ }) => Promise<SharedV2ProviderMetadata | undefined>;
77
81
  /**
78
82
  * Creates an extractor for handling streaming responses. The returned object provides
79
83
  * methods to process individual chunks and build the final metadata from the accumulated
@@ -96,7 +100,7 @@ type MetadataExtractor = {
96
100
  * @returns Provider-specific metadata or undefined if no metadata is available.
97
101
  * The metadata should be under a key indicating the provider id.
98
102
  */
99
- buildMetadata(): LanguageModelV2ProviderMetadata | undefined;
103
+ buildMetadata(): SharedV2ProviderMetadata | undefined;
100
104
  };
101
105
  };
102
106
 
@@ -108,70 +112,72 @@ type OpenAICompatibleChatConfig = {
108
112
  path: string;
109
113
  }) => string;
110
114
  fetch?: FetchFunction;
115
+ includeUsage?: boolean;
111
116
  errorStructure?: ProviderErrorStructure<any>;
112
117
  metadataExtractor?: MetadataExtractor;
113
118
  /**
114
- Default object generation mode that should be used with this model when
115
- no mode is specified. Should be the mode with the best results for this
116
- model. `undefined` can be specified if object generation is not supported.
117
- */
118
- defaultObjectGenerationMode?: LanguageModelV2ObjectGenerationMode;
119
- /**
120
119
  * Whether the model supports structured outputs.
121
120
  */
122
121
  supportsStructuredOutputs?: boolean;
122
+ /**
123
+ * The supported URLs for the model.
124
+ */
125
+ getSupportedUrls?: () => Promise<Record<string, RegExp[]>>;
123
126
  };
124
127
  declare class OpenAICompatibleChatLanguageModel implements LanguageModelV2 {
125
128
  readonly specificationVersion = "v2";
126
129
  readonly supportsStructuredOutputs: boolean;
127
130
  readonly modelId: OpenAICompatibleChatModelId;
128
- readonly settings: OpenAICompatibleChatSettings;
129
131
  private readonly config;
130
132
  private readonly failedResponseHandler;
131
133
  private readonly chunkSchema;
132
- constructor(modelId: OpenAICompatibleChatModelId, settings: OpenAICompatibleChatSettings, config: OpenAICompatibleChatConfig);
133
- get defaultObjectGenerationMode(): 'json' | 'tool' | undefined;
134
+ constructor(modelId: OpenAICompatibleChatModelId, config: OpenAICompatibleChatConfig);
134
135
  get provider(): string;
135
136
  private get providerOptionsName();
137
+ getSupportedUrls(): Promise<Record<string, RegExp[]>>;
136
138
  private getArgs;
137
139
  doGenerate(options: Parameters<LanguageModelV2['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
138
140
  doStream(options: Parameters<LanguageModelV2['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
139
141
  }
140
142
 
141
143
  type OpenAICompatibleCompletionModelId = string;
142
- interface OpenAICompatibleCompletionSettings {
144
+ declare const openaiCompatibleCompletionProviderOptions: z.ZodObject<{
143
145
  /**
144
- Echo back the prompt in addition to the completion.
146
+ * Echo back the prompt in addition to the completion.
145
147
  */
146
- echo?: boolean;
148
+ echo: z.ZodOptional<z.ZodBoolean>;
147
149
  /**
148
- Modify the likelihood of specified tokens appearing in the completion.
149
-
150
- Accepts a JSON object that maps tokens (specified by their token ID in
151
- the GPT tokenizer) to an associated bias value from -100 to 100. You
152
- can use this tokenizer tool to convert text to token IDs. Mathematically,
153
- the bias is added to the logits generated by the model prior to sampling.
154
- The exact effect will vary per model, but values between -1 and 1 should
155
- decrease or increase likelihood of selection; values like -100 or 100
156
- should result in a ban or exclusive selection of the relevant token.
157
-
158
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
159
- token from being generated.
150
+ * Modify the likelihood of specified tokens appearing in the completion.
151
+ *
152
+ * Accepts a JSON object that maps tokens (specified by their token ID in
153
+ * the GPT tokenizer) to an associated bias value from -100 to 100.
160
154
  */
161
- logitBias?: Record<number, number>;
155
+ logitBias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
162
156
  /**
163
- The suffix that comes after a completion of inserted text.
157
+ * The suffix that comes after a completion of inserted text.
164
158
  */
165
- suffix?: string;
159
+ suffix: z.ZodOptional<z.ZodString>;
166
160
  /**
167
- A unique identifier representing your end-user, which can help OpenAI to
168
- monitor and detect abuse. Learn more.
161
+ * A unique identifier representing your end-user, which can help providers to
162
+ * monitor and detect abuse.
169
163
  */
170
- user?: string;
171
- }
164
+ user: z.ZodOptional<z.ZodString>;
165
+ }, "strip", z.ZodTypeAny, {
166
+ user?: string | undefined;
167
+ echo?: boolean | undefined;
168
+ logitBias?: Record<string, number> | undefined;
169
+ suffix?: string | undefined;
170
+ }, {
171
+ user?: string | undefined;
172
+ echo?: boolean | undefined;
173
+ logitBias?: Record<string, number> | undefined;
174
+ suffix?: string | undefined;
175
+ }>;
176
+ type OpenAICompatibleCompletionProviderOptions = z.infer<typeof openaiCompatibleCompletionProviderOptions>;
172
177
 
173
178
  type OpenAICompatibleCompletionConfig = {
174
179
  provider: string;
180
+ includeUsage?: boolean;
175
181
  headers: () => Record<string, string | undefined>;
176
182
  url: (options: {
177
183
  modelId: string;
@@ -179,36 +185,46 @@ type OpenAICompatibleCompletionConfig = {
179
185
  }) => string;
180
186
  fetch?: FetchFunction;
181
187
  errorStructure?: ProviderErrorStructure<any>;
188
+ /**
189
+ * The supported URLs for the model.
190
+ */
191
+ getSupportedUrls?: () => Promise<Record<string, RegExp[]>>;
182
192
  };
183
193
  declare class OpenAICompatibleCompletionLanguageModel implements LanguageModelV2 {
184
194
  readonly specificationVersion = "v2";
185
- readonly defaultObjectGenerationMode: undefined;
186
195
  readonly modelId: OpenAICompatibleCompletionModelId;
187
- readonly settings: OpenAICompatibleCompletionSettings;
188
196
  private readonly config;
189
197
  private readonly failedResponseHandler;
190
198
  private readonly chunkSchema;
191
- constructor(modelId: OpenAICompatibleCompletionModelId, settings: OpenAICompatibleCompletionSettings, config: OpenAICompatibleCompletionConfig);
199
+ constructor(modelId: OpenAICompatibleCompletionModelId, config: OpenAICompatibleCompletionConfig);
192
200
  get provider(): string;
193
201
  private get providerOptionsName();
202
+ getSupportedUrls(): Promise<Record<string, RegExp[]>>;
194
203
  private getArgs;
195
204
  doGenerate(options: Parameters<LanguageModelV2['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
196
205
  doStream(options: Parameters<LanguageModelV2['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
197
206
  }
198
207
 
199
208
  type OpenAICompatibleEmbeddingModelId = string;
200
- interface OpenAICompatibleEmbeddingSettings {
209
+ declare const openaiCompatibleEmbeddingProviderOptions: z.ZodObject<{
201
210
  /**
202
- The number of dimensions the resulting output embeddings should have.
203
- Only supported in text-embedding-3 and later models.
211
+ * The number of dimensions the resulting output embeddings should have.
212
+ * Only supported in text-embedding-3 and later models.
204
213
  */
205
- dimensions?: number;
214
+ dimensions: z.ZodOptional<z.ZodNumber>;
206
215
  /**
207
- A unique identifier representing your end-user, which can help OpenAI to
208
- monitor and detect abuse. Learn more.
209
- */
210
- user?: string;
211
- }
216
+ * A unique identifier representing your end-user, which can help providers to
217
+ * monitor and detect abuse.
218
+ */
219
+ user: z.ZodOptional<z.ZodString>;
220
+ }, "strip", z.ZodTypeAny, {
221
+ user?: string | undefined;
222
+ dimensions?: number | undefined;
223
+ }, {
224
+ user?: string | undefined;
225
+ dimensions?: number | undefined;
226
+ }>;
227
+ type OpenAICompatibleEmbeddingProviderOptions = z.infer<typeof openaiCompatibleEmbeddingProviderOptions>;
212
228
 
213
229
  type OpenAICompatibleEmbeddingConfig = {
214
230
  /**
@@ -228,16 +244,16 @@ type OpenAICompatibleEmbeddingConfig = {
228
244
  fetch?: FetchFunction;
229
245
  errorStructure?: ProviderErrorStructure<any>;
230
246
  };
231
- declare class OpenAICompatibleEmbeddingModel implements EmbeddingModelV1<string> {
232
- readonly specificationVersion = "v1";
247
+ declare class OpenAICompatibleEmbeddingModel implements EmbeddingModelV2<string> {
248
+ readonly specificationVersion = "v2";
233
249
  readonly modelId: OpenAICompatibleEmbeddingModelId;
234
250
  private readonly config;
235
- private readonly settings;
236
251
  get provider(): string;
237
252
  get maxEmbeddingsPerCall(): number;
238
253
  get supportsParallelCalls(): boolean;
239
- constructor(modelId: OpenAICompatibleEmbeddingModelId, settings: OpenAICompatibleEmbeddingSettings, config: OpenAICompatibleEmbeddingConfig);
240
- doEmbed({ values, headers, abortSignal, }: Parameters<EmbeddingModelV1<string>['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV1<string>['doEmbed']>>>;
254
+ constructor(modelId: OpenAICompatibleEmbeddingModelId, config: OpenAICompatibleEmbeddingConfig);
255
+ private get providerOptionsName();
256
+ doEmbed({ values, headers, abortSignal, providerOptions, }: Parameters<EmbeddingModelV2<string>['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV2<string>['doEmbed']>>>;
241
257
  }
242
258
 
243
259
  type OpenAICompatibleImageModelId = string;
@@ -266,7 +282,7 @@ type OpenAICompatibleImageModelConfig = {
266
282
  currentDate?: () => Date;
267
283
  };
268
284
  };
269
- declare class OpenAICompatibleImageModel implements ImageModelV1 {
285
+ declare class OpenAICompatibleImageModel implements ImageModelV2 {
270
286
  readonly modelId: OpenAICompatibleImageModelId;
271
287
  private readonly settings;
272
288
  private readonly config;
@@ -274,16 +290,16 @@ declare class OpenAICompatibleImageModel implements ImageModelV1 {
274
290
  get maxImagesPerCall(): number;
275
291
  get provider(): string;
276
292
  constructor(modelId: OpenAICompatibleImageModelId, settings: OpenAICompatibleImageSettings, config: OpenAICompatibleImageModelConfig);
277
- doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal, }: Parameters<ImageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<ImageModelV1['doGenerate']>>>;
293
+ doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal, }: Parameters<ImageModelV2['doGenerate']>[0]): Promise<Awaited<ReturnType<ImageModelV2['doGenerate']>>>;
278
294
  }
279
295
 
280
296
  interface OpenAICompatibleProvider<CHAT_MODEL_IDS extends string = string, COMPLETION_MODEL_IDS extends string = string, EMBEDDING_MODEL_IDS extends string = string, IMAGE_MODEL_IDS extends string = string> extends Omit<ProviderV2, 'imageModel'> {
281
- (modelId: CHAT_MODEL_IDS, settings?: OpenAICompatibleChatSettings): LanguageModelV2;
282
- languageModel(modelId: CHAT_MODEL_IDS, settings?: OpenAICompatibleChatSettings): LanguageModelV2;
283
- chatModel(modelId: CHAT_MODEL_IDS, settings?: OpenAICompatibleChatSettings): LanguageModelV2;
284
- completionModel(modelId: COMPLETION_MODEL_IDS, settings?: OpenAICompatibleCompletionSettings): LanguageModelV2;
285
- textEmbeddingModel(modelId: EMBEDDING_MODEL_IDS, settings?: OpenAICompatibleEmbeddingSettings): EmbeddingModelV1<string>;
286
- imageModel(modelId: IMAGE_MODEL_IDS, settings?: OpenAICompatibleImageSettings): ImageModelV1;
297
+ (modelId: CHAT_MODEL_IDS): LanguageModelV2;
298
+ languageModel(modelId: CHAT_MODEL_IDS): LanguageModelV2;
299
+ chatModel(modelId: CHAT_MODEL_IDS): LanguageModelV2;
300
+ completionModel(modelId: COMPLETION_MODEL_IDS): LanguageModelV2;
301
+ textEmbeddingModel(modelId: EMBEDDING_MODEL_IDS): EmbeddingModelV2<string>;
302
+ imageModel(modelId: IMAGE_MODEL_IDS): ImageModelV2;
287
303
  }
288
304
  interface OpenAICompatibleProviderSettings {
289
305
  /**
@@ -320,4 +336,4 @@ Create an OpenAICompatible provider instance.
320
336
  */
321
337
  declare function createOpenAICompatible<CHAT_MODEL_IDS extends string, COMPLETION_MODEL_IDS extends string, EMBEDDING_MODEL_IDS extends string, IMAGE_MODEL_IDS extends string>(options: OpenAICompatibleProviderSettings): OpenAICompatibleProvider<CHAT_MODEL_IDS, COMPLETION_MODEL_IDS, EMBEDDING_MODEL_IDS, IMAGE_MODEL_IDS>;
322
338
 
323
- export { type MetadataExtractor, OpenAICompatibleChatLanguageModel, type OpenAICompatibleChatSettings, OpenAICompatibleCompletionLanguageModel, type OpenAICompatibleCompletionSettings, OpenAICompatibleEmbeddingModel, type OpenAICompatibleEmbeddingSettings, type OpenAICompatibleErrorData, OpenAICompatibleImageModel, type OpenAICompatibleImageSettings, type OpenAICompatibleProvider, type OpenAICompatibleProviderSettings, type ProviderErrorStructure, createOpenAICompatible };
339
+ export { type MetadataExtractor, OpenAICompatibleChatLanguageModel, type OpenAICompatibleChatModelId, OpenAICompatibleCompletionLanguageModel, type OpenAICompatibleCompletionModelId, type OpenAICompatibleCompletionProviderOptions, OpenAICompatibleEmbeddingModel, type OpenAICompatibleEmbeddingModelId, type OpenAICompatibleEmbeddingProviderOptions, type OpenAICompatibleErrorData, OpenAICompatibleImageModel, type OpenAICompatibleImageSettings, type OpenAICompatibleProvider, type OpenAICompatibleProviderOptions, type OpenAICompatibleProviderSettings, type ProviderErrorStructure, createOpenAICompatible };