@ai-sdk/openai-compatible 3.0.74 → 3.0.75
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 +9 -0
- package/dist/index.d.ts +24 -46
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -25
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/chat/openai-compatible-chat-language-model.ts +126 -114
- package/src/completion/openai-compatible-completion-language-model-options.ts +32 -23
- package/src/completion/openai-compatible-completion-language-model.ts +22 -15
- package/src/embedding/openai-compatible-embedding-model-options.ts +22 -13
- package/src/embedding/openai-compatible-embedding-model.ts +13 -7
- package/src/image/openai-compatible-image-model-options.ts +40 -31
- package/src/image/openai-compatible-image-model.ts +27 -20
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
warnIfDeprecatedProviderOptionsKey,
|
|
12
12
|
} from '../utils/to-camel-case';
|
|
13
13
|
import {
|
|
14
|
+
lazySchema,
|
|
15
|
+
zodSchema,
|
|
16
|
+
type InferSchema,
|
|
14
17
|
combineHeaders,
|
|
15
18
|
convertBase64ToUint8Array,
|
|
16
19
|
convertToFormData,
|
|
@@ -213,7 +216,7 @@ export class OpenAICompatibleImageModel implements ImageModelV4 {
|
|
|
213
216
|
}
|
|
214
217
|
|
|
215
218
|
private async getImages(
|
|
216
|
-
data:
|
|
219
|
+
data: InferSchema<typeof openaiCompatibleImageResponseSchema>['data'],
|
|
217
220
|
options: {
|
|
218
221
|
url: string;
|
|
219
222
|
headers: Record<string, string | undefined>;
|
|
@@ -258,7 +261,7 @@ export class OpenAICompatibleImageModel implements ImageModelV4 {
|
|
|
258
261
|
// Providers that omit `usage` are not warned about: many OpenAI-compatible
|
|
259
262
|
// backends legitimately do not report token counts for image generation.
|
|
260
263
|
function mapImageUsage(
|
|
261
|
-
usage:
|
|
264
|
+
usage: InferSchema<typeof openaiCompatibleImageResponseSchema>['usage'],
|
|
262
265
|
): ImageModelV4Usage | undefined {
|
|
263
266
|
return usage == null
|
|
264
267
|
? undefined
|
|
@@ -271,25 +274,29 @@ function mapImageUsage(
|
|
|
271
274
|
|
|
272
275
|
// minimal version of the schema, focussed on what is needed for the implementation
|
|
273
276
|
// this approach limits breakages when the API changes and increases efficiency
|
|
274
|
-
const openaiCompatibleImageResponseSchema =
|
|
275
|
-
|
|
276
|
-
z
|
|
277
|
-
.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
277
|
+
const openaiCompatibleImageResponseSchema = lazySchema(() =>
|
|
278
|
+
zodSchema(
|
|
279
|
+
z.object({
|
|
280
|
+
data: z.array(
|
|
281
|
+
z
|
|
282
|
+
.object({
|
|
283
|
+
b64_json: z.string().nullish(),
|
|
284
|
+
url: z.string().nullish(),
|
|
285
|
+
})
|
|
286
|
+
.refine(image => image.b64_json != null || image.url != null, {
|
|
287
|
+
message: 'Expected b64_json or url in the image response',
|
|
288
|
+
}),
|
|
289
|
+
),
|
|
290
|
+
usage: z
|
|
291
|
+
.object({
|
|
292
|
+
input_tokens: z.number().nullish(),
|
|
293
|
+
output_tokens: z.number().nullish(),
|
|
294
|
+
total_tokens: z.number().nullish(),
|
|
295
|
+
})
|
|
296
|
+
.nullish(),
|
|
297
|
+
}),
|
|
284
298
|
),
|
|
285
|
-
|
|
286
|
-
.object({
|
|
287
|
-
input_tokens: z.number().nullish(),
|
|
288
|
-
output_tokens: z.number().nullish(),
|
|
289
|
-
total_tokens: z.number().nullish(),
|
|
290
|
-
})
|
|
291
|
-
.nullish(),
|
|
292
|
-
});
|
|
299
|
+
);
|
|
293
300
|
|
|
294
301
|
type OpenAICompatibleFormDataInput = {
|
|
295
302
|
model: string;
|