@llmgateway/ai-sdk-provider 3.7.0 → 3.8.1

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.
@@ -1,6 +1,5 @@
1
1
  import { LanguageModelV3, LanguageModelV3CallOptions, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
2
2
  export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
3
- import { models, Provider } from '@llmgateway/models';
4
3
  export { Model, ModelDefinition, Provider, ProviderModelMapping, StabilityLevel, models } from '@llmgateway/models';
5
4
 
6
5
  type LLMGatewayProviderOptions = {
@@ -154,6 +153,70 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
154
153
  }>;
155
154
  }
156
155
 
156
+ type LLMGatewayChatModelId = string;
157
+ type LLMGatewayChatSettings = {
158
+ /**
159
+ Modify the likelihood of specified tokens appearing in the completion.
160
+
161
+ Accepts a JSON object that maps tokens (specified by their token ID in
162
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
163
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
164
+ the bias is added to the logits generated by the model prior to sampling.
165
+ The exact effect will vary per model, but values between -1 and 1 should
166
+ decrease or increase likelihood of selection; values like -100 or 100
167
+ should result in a ban or exclusive selection of the relevant token.
168
+
169
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
170
+ token from being generated.
171
+ */
172
+ logitBias?: Record<number, number>;
173
+ /**
174
+ Return the log probabilities of the tokens. Including logprobs will increase
175
+ the response size and can slow down response times. However, it can
176
+ be useful to understand better how the model is behaving.
177
+
178
+ Setting to true will return the log probabilities of the tokens that
179
+ were generated.
180
+
181
+ Setting to a number will return the log probabilities of the top n
182
+ tokens that were generated.
183
+ */
184
+ logprobs?: boolean | number;
185
+ /**
186
+ Whether to enable parallel function calling during tool use. Default to true.
187
+ */
188
+ parallelToolCalls?: boolean;
189
+ /**
190
+ A unique identifier representing your end-user, which can help LLMGateway to
191
+ monitor and detect abuse. Learn more.
192
+ */
193
+ user?: string;
194
+ } & LLMGatewaySharedSettings;
195
+
196
+ type LLMGatewayChatConfig = {
197
+ provider: string;
198
+ compatibility: 'strict' | 'compatible';
199
+ headers: () => Record<string, string | undefined>;
200
+ url: (options: {
201
+ modelId: string;
202
+ path: string;
203
+ }) => string;
204
+ fetch?: typeof fetch;
205
+ extraBody?: Record<string, unknown>;
206
+ };
207
+ declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
208
+ readonly specificationVersion: "v3";
209
+ readonly provider = "llmgateway";
210
+ readonly modelId: LLMGatewayChatModelId;
211
+ readonly supportedUrls: Record<string, RegExp[]>;
212
+ readonly settings: LLMGatewayChatSettings;
213
+ private readonly config;
214
+ constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
215
+ private getArgs;
216
+ doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
217
+ doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
218
+ }
219
+
157
220
  declare const providers: [{
158
221
  readonly id: "llmgateway";
159
222
  readonly name: "LLM Gateway";
@@ -343,68 +406,4 @@ declare const providers: [{
343
406
  }];
344
407
  type ProviderId = (typeof providers)[number]['id'];
345
408
 
346
- type LLMGatewayChatModelId = (typeof models)[number]['id'] | `${Provider}/${(typeof models)[number]['id']}` | 'test-model';
347
- type LLMGatewayChatSettings = {
348
- /**
349
- Modify the likelihood of specified tokens appearing in the completion.
350
-
351
- Accepts a JSON object that maps tokens (specified by their token ID in
352
- the GPT tokenizer) to an associated bias value from -100 to 100. You
353
- can use this tokenizer tool to convert text to token IDs. Mathematically,
354
- the bias is added to the logits generated by the model prior to sampling.
355
- The exact effect will vary per model, but values between -1 and 1 should
356
- decrease or increase likelihood of selection; values like -100 or 100
357
- should result in a ban or exclusive selection of the relevant token.
358
-
359
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
360
- token from being generated.
361
- */
362
- logitBias?: Record<number, number>;
363
- /**
364
- Return the log probabilities of the tokens. Including logprobs will increase
365
- the response size and can slow down response times. However, it can
366
- be useful to understand better how the model is behaving.
367
-
368
- Setting to true will return the log probabilities of the tokens that
369
- were generated.
370
-
371
- Setting to a number will return the log probabilities of the top n
372
- tokens that were generated.
373
- */
374
- logprobs?: boolean | number;
375
- /**
376
- Whether to enable parallel function calling during tool use. Default to true.
377
- */
378
- parallelToolCalls?: boolean;
379
- /**
380
- A unique identifier representing your end-user, which can help LLMGateway to
381
- monitor and detect abuse. Learn more.
382
- */
383
- user?: string;
384
- } & LLMGatewaySharedSettings;
385
-
386
- type LLMGatewayChatConfig = {
387
- provider: string;
388
- compatibility: 'strict' | 'compatible';
389
- headers: () => Record<string, string | undefined>;
390
- url: (options: {
391
- modelId: string;
392
- path: string;
393
- }) => string;
394
- fetch?: typeof fetch;
395
- extraBody?: Record<string, unknown>;
396
- };
397
- declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
398
- readonly specificationVersion: "v3";
399
- readonly provider = "llmgateway";
400
- readonly modelId: LLMGatewayChatModelId;
401
- readonly supportedUrls: Record<string, RegExp[]>;
402
- readonly settings: LLMGatewayChatSettings;
403
- private readonly config;
404
- constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
405
- private getArgs;
406
- doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
407
- doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
408
- }
409
-
410
409
  export { LLMGatewayChatLanguageModel, type LLMGatewayChatModelId, type LLMGatewayChatSettings, LLMGatewayCompletionLanguageModel, type LLMGatewayCompletionSettings, LLMGatewayImageModel, type LLMGatewayImageModelId, type LLMGatewayImageSettings, type LLMGatewayProviderOptions, type LLMGatewaySharedSettings, type LLMGatewayUsageAccounting, type ProviderId, providers };
@@ -1,6 +1,5 @@
1
1
  import { LanguageModelV3, LanguageModelV3CallOptions, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
2
2
  export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
3
- import { models, Provider } from '@llmgateway/models';
4
3
  export { Model, ModelDefinition, Provider, ProviderModelMapping, StabilityLevel, models } from '@llmgateway/models';
5
4
 
6
5
  type LLMGatewayProviderOptions = {
@@ -154,6 +153,70 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
154
153
  }>;
155
154
  }
156
155
 
156
+ type LLMGatewayChatModelId = string;
157
+ type LLMGatewayChatSettings = {
158
+ /**
159
+ Modify the likelihood of specified tokens appearing in the completion.
160
+
161
+ Accepts a JSON object that maps tokens (specified by their token ID in
162
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
163
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
164
+ the bias is added to the logits generated by the model prior to sampling.
165
+ The exact effect will vary per model, but values between -1 and 1 should
166
+ decrease or increase likelihood of selection; values like -100 or 100
167
+ should result in a ban or exclusive selection of the relevant token.
168
+
169
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
170
+ token from being generated.
171
+ */
172
+ logitBias?: Record<number, number>;
173
+ /**
174
+ Return the log probabilities of the tokens. Including logprobs will increase
175
+ the response size and can slow down response times. However, it can
176
+ be useful to understand better how the model is behaving.
177
+
178
+ Setting to true will return the log probabilities of the tokens that
179
+ were generated.
180
+
181
+ Setting to a number will return the log probabilities of the top n
182
+ tokens that were generated.
183
+ */
184
+ logprobs?: boolean | number;
185
+ /**
186
+ Whether to enable parallel function calling during tool use. Default to true.
187
+ */
188
+ parallelToolCalls?: boolean;
189
+ /**
190
+ A unique identifier representing your end-user, which can help LLMGateway to
191
+ monitor and detect abuse. Learn more.
192
+ */
193
+ user?: string;
194
+ } & LLMGatewaySharedSettings;
195
+
196
+ type LLMGatewayChatConfig = {
197
+ provider: string;
198
+ compatibility: 'strict' | 'compatible';
199
+ headers: () => Record<string, string | undefined>;
200
+ url: (options: {
201
+ modelId: string;
202
+ path: string;
203
+ }) => string;
204
+ fetch?: typeof fetch;
205
+ extraBody?: Record<string, unknown>;
206
+ };
207
+ declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
208
+ readonly specificationVersion: "v3";
209
+ readonly provider = "llmgateway";
210
+ readonly modelId: LLMGatewayChatModelId;
211
+ readonly supportedUrls: Record<string, RegExp[]>;
212
+ readonly settings: LLMGatewayChatSettings;
213
+ private readonly config;
214
+ constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
215
+ private getArgs;
216
+ doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
217
+ doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
218
+ }
219
+
157
220
  declare const providers: [{
158
221
  readonly id: "llmgateway";
159
222
  readonly name: "LLM Gateway";
@@ -343,68 +406,4 @@ declare const providers: [{
343
406
  }];
344
407
  type ProviderId = (typeof providers)[number]['id'];
345
408
 
346
- type LLMGatewayChatModelId = (typeof models)[number]['id'] | `${Provider}/${(typeof models)[number]['id']}` | 'test-model';
347
- type LLMGatewayChatSettings = {
348
- /**
349
- Modify the likelihood of specified tokens appearing in the completion.
350
-
351
- Accepts a JSON object that maps tokens (specified by their token ID in
352
- the GPT tokenizer) to an associated bias value from -100 to 100. You
353
- can use this tokenizer tool to convert text to token IDs. Mathematically,
354
- the bias is added to the logits generated by the model prior to sampling.
355
- The exact effect will vary per model, but values between -1 and 1 should
356
- decrease or increase likelihood of selection; values like -100 or 100
357
- should result in a ban or exclusive selection of the relevant token.
358
-
359
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
360
- token from being generated.
361
- */
362
- logitBias?: Record<number, number>;
363
- /**
364
- Return the log probabilities of the tokens. Including logprobs will increase
365
- the response size and can slow down response times. However, it can
366
- be useful to understand better how the model is behaving.
367
-
368
- Setting to true will return the log probabilities of the tokens that
369
- were generated.
370
-
371
- Setting to a number will return the log probabilities of the top n
372
- tokens that were generated.
373
- */
374
- logprobs?: boolean | number;
375
- /**
376
- Whether to enable parallel function calling during tool use. Default to true.
377
- */
378
- parallelToolCalls?: boolean;
379
- /**
380
- A unique identifier representing your end-user, which can help LLMGateway to
381
- monitor and detect abuse. Learn more.
382
- */
383
- user?: string;
384
- } & LLMGatewaySharedSettings;
385
-
386
- type LLMGatewayChatConfig = {
387
- provider: string;
388
- compatibility: 'strict' | 'compatible';
389
- headers: () => Record<string, string | undefined>;
390
- url: (options: {
391
- modelId: string;
392
- path: string;
393
- }) => string;
394
- fetch?: typeof fetch;
395
- extraBody?: Record<string, unknown>;
396
- };
397
- declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
398
- readonly specificationVersion: "v3";
399
- readonly provider = "llmgateway";
400
- readonly modelId: LLMGatewayChatModelId;
401
- readonly supportedUrls: Record<string, RegExp[]>;
402
- readonly settings: LLMGatewayChatSettings;
403
- private readonly config;
404
- constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
405
- private getArgs;
406
- doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
407
- doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
408
- }
409
-
410
409
  export { LLMGatewayChatLanguageModel, type LLMGatewayChatModelId, type LLMGatewayChatSettings, LLMGatewayCompletionLanguageModel, type LLMGatewayCompletionSettings, LLMGatewayImageModel, type LLMGatewayImageModelId, type LLMGatewayImageSettings, type LLMGatewayProviderOptions, type LLMGatewaySharedSettings, type LLMGatewayUsageAccounting, type ProviderId, providers };
@@ -2275,6 +2275,29 @@ function getBase64FromDataUrl(dataUrl) {
2275
2275
  }
2276
2276
 
2277
2277
  // src/chat/convert-to-llmgateway-chat-messages.ts
2278
+ var AUDIO_FORMAT_BY_MIME = {
2279
+ "audio/wav": "wav",
2280
+ "audio/wave": "wav",
2281
+ "audio/x-wav": "wav",
2282
+ "audio/mpeg": "mp3",
2283
+ "audio/mp3": "mp3",
2284
+ "audio/mp4": "mp4",
2285
+ "audio/m4a": "m4a",
2286
+ "audio/x-m4a": "m4a",
2287
+ "audio/aac": "aac",
2288
+ "audio/ogg": "ogg",
2289
+ "audio/flac": "flac",
2290
+ "audio/aiff": "aiff",
2291
+ "audio/x-aiff": "aiff",
2292
+ "audio/webm": "webm"
2293
+ };
2294
+ function audioFormatFromMime(mime) {
2295
+ var _a16;
2296
+ if (!mime) return void 0;
2297
+ const lower = (_a16 = mime.toLowerCase().split(";")[0]) == null ? void 0 : _a16.trim();
2298
+ if (!lower) return void 0;
2299
+ return AUDIO_FORMAT_BY_MIME[lower];
2300
+ }
2278
2301
  function getCacheControl(providerOptions) {
2279
2302
  var _a16, _b16, _c;
2280
2303
  const anthropic = providerOptions == null ? void 0 : providerOptions.anthropic;
@@ -2313,7 +2336,7 @@ function convertToLLMGatewayChatMessages(prompt) {
2313
2336
  const messageCacheControl = getCacheControl(providerOptions);
2314
2337
  const contentParts = content.map(
2315
2338
  (part) => {
2316
- var _a17, _b17, _c2, _d, _e, _f;
2339
+ var _a17, _b17, _c2, _d, _e, _f, _g;
2317
2340
  const cacheControl = (_a17 = getCacheControl(part.providerOptions)) != null ? _a17 : messageCacheControl;
2318
2341
  switch (part.type) {
2319
2342
  case "text":
@@ -2338,8 +2361,27 @@ function convertToLLMGatewayChatMessages(prompt) {
2338
2361
  cache_control: cacheControl
2339
2362
  };
2340
2363
  }
2364
+ if ((_c2 = part.mediaType) == null ? void 0 : _c2.startsWith("audio/")) {
2365
+ const format = audioFormatFromMime(part.mediaType);
2366
+ if (format) {
2367
+ const fileUrl = getFileUrl({
2368
+ part,
2369
+ defaultMediaType: part.mediaType
2370
+ });
2371
+ if (fileUrl.startsWith("data:")) {
2372
+ return {
2373
+ type: "input_audio",
2374
+ input_audio: {
2375
+ data: getBase64FromDataUrl(fileUrl),
2376
+ format
2377
+ },
2378
+ cache_control: cacheControl
2379
+ };
2380
+ }
2381
+ }
2382
+ }
2341
2383
  const fileName = String(
2342
- (_f = (_e = (_d = (_c2 = part.providerOptions) == null ? void 0 : _c2.llmgateway) == null ? void 0 : _d.filename) != null ? _e : part.filename) != null ? _f : ""
2384
+ (_g = (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.llmgateway) == null ? void 0 : _e.filename) != null ? _f : part.filename) != null ? _g : ""
2343
2385
  );
2344
2386
  const fileData = getFileUrl({
2345
2387
  part,