@ai-sdk/groq 4.0.0-beta.22 → 4.0.0-beta.24
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 +29 -0
- package/dist/index.js +215 -191
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/groq-chat-language-model.ts +20 -3
- package/src/groq-config.ts +1 -1
- package/src/groq-transcription-model.ts +18 -1
- package/dist/index.d.mts +0 -113
- package/dist/index.mjs +0 -1061
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,40 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
browserSearch: () => browserSearch,
|
|
25
|
-
createGroq: () => createGroq,
|
|
26
|
-
groq: () => groq
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
|
|
30
1
|
// src/groq-provider.ts
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
loadApiKey,
|
|
7
|
+
withoutTrailingSlash,
|
|
8
|
+
withUserAgentSuffix
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
33
10
|
|
|
34
11
|
// src/groq-chat-language-model.ts
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
12
|
+
import {
|
|
13
|
+
InvalidResponseDataError
|
|
14
|
+
} from "@ai-sdk/provider";
|
|
15
|
+
import {
|
|
16
|
+
combineHeaders,
|
|
17
|
+
createEventSourceResponseHandler,
|
|
18
|
+
createJsonResponseHandler,
|
|
19
|
+
generateId,
|
|
20
|
+
isCustomReasoning,
|
|
21
|
+
isParsableJson,
|
|
22
|
+
mapReasoningToProviderEffort,
|
|
23
|
+
parseProviderOptions,
|
|
24
|
+
postJsonToApi,
|
|
25
|
+
serializeModelOptions,
|
|
26
|
+
WORKFLOW_SERIALIZE,
|
|
27
|
+
WORKFLOW_DESERIALIZE
|
|
28
|
+
} from "@ai-sdk/provider-utils";
|
|
29
|
+
import { z as z3 } from "zod/v4";
|
|
38
30
|
|
|
39
31
|
// src/convert-groq-usage.ts
|
|
40
32
|
function convertGroqUsage(usage) {
|
|
@@ -76,8 +68,10 @@ function convertGroqUsage(usage) {
|
|
|
76
68
|
}
|
|
77
69
|
|
|
78
70
|
// src/convert-to-groq-chat-messages.ts
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
import {
|
|
72
|
+
UnsupportedFunctionalityError
|
|
73
|
+
} from "@ai-sdk/provider";
|
|
74
|
+
import { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
|
|
81
75
|
function convertToGroqChatMessages(prompt) {
|
|
82
76
|
var _a;
|
|
83
77
|
const messages = [];
|
|
@@ -100,13 +94,13 @@ function convertToGroqChatMessages(prompt) {
|
|
|
100
94
|
return { type: "text", text: part.text };
|
|
101
95
|
}
|
|
102
96
|
case "file": {
|
|
103
|
-
if (
|
|
104
|
-
throw new
|
|
97
|
+
if (isProviderReference(part.data)) {
|
|
98
|
+
throw new UnsupportedFunctionalityError({
|
|
105
99
|
functionality: "file parts with provider references"
|
|
106
100
|
});
|
|
107
101
|
}
|
|
108
102
|
if (!part.mediaType.startsWith("image/")) {
|
|
109
|
-
throw new
|
|
103
|
+
throw new UnsupportedFunctionalityError({
|
|
110
104
|
functionality: "Non-image file content parts"
|
|
111
105
|
});
|
|
112
106
|
}
|
|
@@ -114,7 +108,7 @@ function convertToGroqChatMessages(prompt) {
|
|
|
114
108
|
return {
|
|
115
109
|
type: "image_url",
|
|
116
110
|
image_url: {
|
|
117
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
111
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
118
112
|
}
|
|
119
113
|
};
|
|
120
114
|
}
|
|
@@ -212,29 +206,29 @@ function getResponseMetadata({
|
|
|
212
206
|
}
|
|
213
207
|
|
|
214
208
|
// src/groq-chat-options.ts
|
|
215
|
-
|
|
216
|
-
var groqLanguageModelOptions =
|
|
217
|
-
reasoningFormat:
|
|
209
|
+
import { z } from "zod/v4";
|
|
210
|
+
var groqLanguageModelOptions = z.object({
|
|
211
|
+
reasoningFormat: z.enum(["parsed", "raw", "hidden"]).optional(),
|
|
218
212
|
/**
|
|
219
213
|
* Specifies the reasoning effort level for model inference.
|
|
220
214
|
* @see https://console.groq.com/docs/reasoning#reasoning-effort
|
|
221
215
|
*/
|
|
222
|
-
reasoningEffort:
|
|
216
|
+
reasoningEffort: z.enum(["none", "default", "low", "medium", "high"]).optional(),
|
|
223
217
|
/**
|
|
224
218
|
* Whether to enable parallel function calling during tool use. Default to true.
|
|
225
219
|
*/
|
|
226
|
-
parallelToolCalls:
|
|
220
|
+
parallelToolCalls: z.boolean().optional(),
|
|
227
221
|
/**
|
|
228
222
|
* A unique identifier representing your end-user, which can help OpenAI to
|
|
229
223
|
* monitor and detect abuse. Learn more.
|
|
230
224
|
*/
|
|
231
|
-
user:
|
|
225
|
+
user: z.string().optional(),
|
|
232
226
|
/**
|
|
233
227
|
* Whether to use structured outputs.
|
|
234
228
|
*
|
|
235
229
|
* @default true
|
|
236
230
|
*/
|
|
237
|
-
structuredOutputs:
|
|
231
|
+
structuredOutputs: z.boolean().optional(),
|
|
238
232
|
/**
|
|
239
233
|
* Whether to use strict JSON schema validation.
|
|
240
234
|
* When true, the model uses constrained decoding to guarantee schema compliance.
|
|
@@ -242,7 +236,7 @@ var groqLanguageModelOptions = import_v4.z.object({
|
|
|
242
236
|
*
|
|
243
237
|
* @default true
|
|
244
238
|
*/
|
|
245
|
-
strictJsonSchema:
|
|
239
|
+
strictJsonSchema: z.boolean().optional(),
|
|
246
240
|
/**
|
|
247
241
|
* Service tier for the request.
|
|
248
242
|
* - 'on_demand': Default tier with consistent performance and fairness
|
|
@@ -252,25 +246,27 @@ var groqLanguageModelOptions = import_v4.z.object({
|
|
|
252
246
|
*
|
|
253
247
|
* @default 'on_demand'
|
|
254
248
|
*/
|
|
255
|
-
serviceTier:
|
|
249
|
+
serviceTier: z.enum(["on_demand", "performance", "flex", "auto"]).optional()
|
|
256
250
|
});
|
|
257
251
|
|
|
258
252
|
// src/groq-error.ts
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
var groqErrorDataSchema =
|
|
262
|
-
error:
|
|
263
|
-
message:
|
|
264
|
-
type:
|
|
253
|
+
import { z as z2 } from "zod/v4";
|
|
254
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
255
|
+
var groqErrorDataSchema = z2.object({
|
|
256
|
+
error: z2.object({
|
|
257
|
+
message: z2.string(),
|
|
258
|
+
type: z2.string()
|
|
265
259
|
})
|
|
266
260
|
});
|
|
267
|
-
var groqFailedResponseHandler =
|
|
261
|
+
var groqFailedResponseHandler = createJsonErrorResponseHandler({
|
|
268
262
|
errorSchema: groqErrorDataSchema,
|
|
269
263
|
errorToMessage: (data) => data.error.message
|
|
270
264
|
});
|
|
271
265
|
|
|
272
266
|
// src/groq-prepare-tools.ts
|
|
273
|
-
|
|
267
|
+
import {
|
|
268
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
269
|
+
} from "@ai-sdk/provider";
|
|
274
270
|
|
|
275
271
|
// src/groq-browser-search-models.ts
|
|
276
272
|
var BROWSER_SEARCH_SUPPORTED_MODELS = [
|
|
@@ -350,7 +346,7 @@ function prepareTools({
|
|
|
350
346
|
};
|
|
351
347
|
default: {
|
|
352
348
|
const _exhaustiveCheck = type;
|
|
353
|
-
throw new
|
|
349
|
+
throw new UnsupportedFunctionalityError2({
|
|
354
350
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
355
351
|
});
|
|
356
352
|
}
|
|
@@ -375,7 +371,7 @@ function mapGroqFinishReason(finishReason) {
|
|
|
375
371
|
}
|
|
376
372
|
|
|
377
373
|
// src/groq-chat-language-model.ts
|
|
378
|
-
var GroqChatLanguageModel = class {
|
|
374
|
+
var GroqChatLanguageModel = class _GroqChatLanguageModel {
|
|
379
375
|
constructor(modelId, config) {
|
|
380
376
|
this.specificationVersion = "v4";
|
|
381
377
|
this.supportedUrls = {
|
|
@@ -384,6 +380,15 @@ var GroqChatLanguageModel = class {
|
|
|
384
380
|
this.modelId = modelId;
|
|
385
381
|
this.config = config;
|
|
386
382
|
}
|
|
383
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
384
|
+
return serializeModelOptions({
|
|
385
|
+
modelId: model.modelId,
|
|
386
|
+
config: model.config
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
390
|
+
return new _GroqChatLanguageModel(options.modelId, options.config);
|
|
391
|
+
}
|
|
387
392
|
get provider() {
|
|
388
393
|
return this.config.provider;
|
|
389
394
|
}
|
|
@@ -405,7 +410,7 @@ var GroqChatLanguageModel = class {
|
|
|
405
410
|
}) {
|
|
406
411
|
var _a, _b, _c, _d;
|
|
407
412
|
const warnings = [];
|
|
408
|
-
const groqOptions = await
|
|
413
|
+
const groqOptions = await parseProviderOptions({
|
|
409
414
|
provider: "groq",
|
|
410
415
|
providerOptions,
|
|
411
416
|
schema: groqLanguageModelOptions
|
|
@@ -454,7 +459,7 @@ var GroqChatLanguageModel = class {
|
|
|
454
459
|
} : { type: "json_object" } : void 0,
|
|
455
460
|
// provider options:
|
|
456
461
|
reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
|
|
457
|
-
reasoning_effort: (_d = groqOptions == null ? void 0 : groqOptions.reasoningEffort) != null ? _d :
|
|
462
|
+
reasoning_effort: (_d = groqOptions == null ? void 0 : groqOptions.reasoningEffort) != null ? _d : isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
|
|
458
463
|
reasoning,
|
|
459
464
|
effortMap: {
|
|
460
465
|
minimal: "low",
|
|
@@ -476,22 +481,22 @@ var GroqChatLanguageModel = class {
|
|
|
476
481
|
};
|
|
477
482
|
}
|
|
478
483
|
async doGenerate(options) {
|
|
479
|
-
var _a, _b;
|
|
484
|
+
var _a, _b, _c, _d;
|
|
480
485
|
const { args, warnings } = await this.getArgs(options);
|
|
481
486
|
const body = JSON.stringify(args);
|
|
482
487
|
const {
|
|
483
488
|
responseHeaders,
|
|
484
489
|
value: response,
|
|
485
490
|
rawValue: rawResponse
|
|
486
|
-
} = await
|
|
491
|
+
} = await postJsonToApi({
|
|
487
492
|
url: this.config.url({
|
|
488
493
|
path: "/chat/completions",
|
|
489
494
|
modelId: this.modelId
|
|
490
495
|
}),
|
|
491
|
-
headers: (
|
|
496
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
492
497
|
body: args,
|
|
493
498
|
failedResponseHandler: groqFailedResponseHandler,
|
|
494
|
-
successfulResponseHandler:
|
|
499
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
495
500
|
groqChatResponseSchema
|
|
496
501
|
),
|
|
497
502
|
abortSignal: options.abortSignal,
|
|
@@ -514,7 +519,7 @@ var GroqChatLanguageModel = class {
|
|
|
514
519
|
for (const toolCall of choice.message.tool_calls) {
|
|
515
520
|
content.push({
|
|
516
521
|
type: "tool-call",
|
|
517
|
-
toolCallId: (
|
|
522
|
+
toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
|
|
518
523
|
toolName: toolCall.function.name,
|
|
519
524
|
input: toolCall.function.arguments
|
|
520
525
|
});
|
|
@@ -524,7 +529,7 @@ var GroqChatLanguageModel = class {
|
|
|
524
529
|
content,
|
|
525
530
|
finishReason: {
|
|
526
531
|
unified: mapGroqFinishReason(choice.finish_reason),
|
|
527
|
-
raw: (
|
|
532
|
+
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
528
533
|
},
|
|
529
534
|
usage: convertGroqUsage(response.usage),
|
|
530
535
|
response: {
|
|
@@ -537,17 +542,18 @@ var GroqChatLanguageModel = class {
|
|
|
537
542
|
};
|
|
538
543
|
}
|
|
539
544
|
async doStream(options) {
|
|
545
|
+
var _a, _b;
|
|
540
546
|
const { args, warnings } = await this.getArgs(options);
|
|
541
547
|
const body = { ...args, stream: true };
|
|
542
|
-
const { responseHeaders, value: response } = await
|
|
548
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
543
549
|
url: this.config.url({
|
|
544
550
|
path: "/chat/completions",
|
|
545
551
|
modelId: this.modelId
|
|
546
552
|
}),
|
|
547
|
-
headers: (
|
|
553
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
548
554
|
body,
|
|
549
555
|
failedResponseHandler: groqFailedResponseHandler,
|
|
550
|
-
successfulResponseHandler:
|
|
556
|
+
successfulResponseHandler: createEventSourceResponseHandler(groqChatChunkSchema),
|
|
551
557
|
abortSignal: options.abortSignal,
|
|
552
558
|
fetch: this.config.fetch
|
|
553
559
|
});
|
|
@@ -568,7 +574,7 @@ var GroqChatLanguageModel = class {
|
|
|
568
574
|
controller.enqueue({ type: "stream-start", warnings });
|
|
569
575
|
},
|
|
570
576
|
transform(chunk, controller) {
|
|
571
|
-
var
|
|
577
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
572
578
|
if (options.includeRawChunks) {
|
|
573
579
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
574
580
|
}
|
|
@@ -596,7 +602,7 @@ var GroqChatLanguageModel = class {
|
|
|
596
602
|
...getResponseMetadata(value)
|
|
597
603
|
});
|
|
598
604
|
}
|
|
599
|
-
if (((
|
|
605
|
+
if (((_a2 = value.x_groq) == null ? void 0 : _a2.usage) != null) {
|
|
600
606
|
usage = value.x_groq.usage;
|
|
601
607
|
}
|
|
602
608
|
const choice = value.choices[0];
|
|
@@ -654,19 +660,19 @@ var GroqChatLanguageModel = class {
|
|
|
654
660
|
const index = toolCallDelta.index;
|
|
655
661
|
if (toolCalls[index] == null) {
|
|
656
662
|
if (toolCallDelta.type !== "function") {
|
|
657
|
-
throw new
|
|
663
|
+
throw new InvalidResponseDataError({
|
|
658
664
|
data: toolCallDelta,
|
|
659
665
|
message: `Expected 'function' type.`
|
|
660
666
|
});
|
|
661
667
|
}
|
|
662
668
|
if (toolCallDelta.id == null) {
|
|
663
|
-
throw new
|
|
669
|
+
throw new InvalidResponseDataError({
|
|
664
670
|
data: toolCallDelta,
|
|
665
671
|
message: `Expected 'id' to be a string.`
|
|
666
672
|
});
|
|
667
673
|
}
|
|
668
|
-
if (((
|
|
669
|
-
throw new
|
|
674
|
+
if (((_b2 = toolCallDelta.function) == null ? void 0 : _b2.name) == null) {
|
|
675
|
+
throw new InvalidResponseDataError({
|
|
670
676
|
data: toolCallDelta,
|
|
671
677
|
message: `Expected 'function.name' to be a string.`
|
|
672
678
|
});
|
|
@@ -694,14 +700,14 @@ var GroqChatLanguageModel = class {
|
|
|
694
700
|
delta: toolCall2.function.arguments
|
|
695
701
|
});
|
|
696
702
|
}
|
|
697
|
-
if (
|
|
703
|
+
if (isParsableJson(toolCall2.function.arguments)) {
|
|
698
704
|
controller.enqueue({
|
|
699
705
|
type: "tool-input-end",
|
|
700
706
|
id: toolCall2.id
|
|
701
707
|
});
|
|
702
708
|
controller.enqueue({
|
|
703
709
|
type: "tool-call",
|
|
704
|
-
toolCallId: (_f = toolCall2.id) != null ? _f :
|
|
710
|
+
toolCallId: (_f = toolCall2.id) != null ? _f : generateId(),
|
|
705
711
|
toolName: toolCall2.function.name,
|
|
706
712
|
input: toolCall2.function.arguments
|
|
707
713
|
});
|
|
@@ -722,14 +728,14 @@ var GroqChatLanguageModel = class {
|
|
|
722
728
|
id: toolCall.id,
|
|
723
729
|
delta: (_j = toolCallDelta.function.arguments) != null ? _j : ""
|
|
724
730
|
});
|
|
725
|
-
if (((_k = toolCall.function) == null ? void 0 : _k.name) != null && ((_l = toolCall.function) == null ? void 0 : _l.arguments) != null &&
|
|
731
|
+
if (((_k = toolCall.function) == null ? void 0 : _k.name) != null && ((_l = toolCall.function) == null ? void 0 : _l.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
726
732
|
controller.enqueue({
|
|
727
733
|
type: "tool-input-end",
|
|
728
734
|
id: toolCall.id
|
|
729
735
|
});
|
|
730
736
|
controller.enqueue({
|
|
731
737
|
type: "tool-call",
|
|
732
|
-
toolCallId: (_m = toolCall.id) != null ? _m :
|
|
738
|
+
toolCallId: (_m = toolCall.id) != null ? _m : generateId(),
|
|
733
739
|
toolName: toolCall.function.name,
|
|
734
740
|
input: toolCall.function.arguments
|
|
735
741
|
});
|
|
@@ -759,78 +765,78 @@ var GroqChatLanguageModel = class {
|
|
|
759
765
|
};
|
|
760
766
|
}
|
|
761
767
|
};
|
|
762
|
-
var groqChatResponseSchema =
|
|
763
|
-
id:
|
|
764
|
-
created:
|
|
765
|
-
model:
|
|
766
|
-
choices:
|
|
767
|
-
|
|
768
|
-
message:
|
|
769
|
-
content:
|
|
770
|
-
reasoning:
|
|
771
|
-
tool_calls:
|
|
772
|
-
|
|
773
|
-
id:
|
|
774
|
-
type:
|
|
775
|
-
function:
|
|
776
|
-
name:
|
|
777
|
-
arguments:
|
|
768
|
+
var groqChatResponseSchema = z3.object({
|
|
769
|
+
id: z3.string().nullish(),
|
|
770
|
+
created: z3.number().nullish(),
|
|
771
|
+
model: z3.string().nullish(),
|
|
772
|
+
choices: z3.array(
|
|
773
|
+
z3.object({
|
|
774
|
+
message: z3.object({
|
|
775
|
+
content: z3.string().nullish(),
|
|
776
|
+
reasoning: z3.string().nullish(),
|
|
777
|
+
tool_calls: z3.array(
|
|
778
|
+
z3.object({
|
|
779
|
+
id: z3.string().nullish(),
|
|
780
|
+
type: z3.literal("function"),
|
|
781
|
+
function: z3.object({
|
|
782
|
+
name: z3.string(),
|
|
783
|
+
arguments: z3.string()
|
|
778
784
|
})
|
|
779
785
|
})
|
|
780
786
|
).nullish()
|
|
781
787
|
}),
|
|
782
|
-
index:
|
|
783
|
-
finish_reason:
|
|
788
|
+
index: z3.number(),
|
|
789
|
+
finish_reason: z3.string().nullish()
|
|
784
790
|
})
|
|
785
791
|
),
|
|
786
|
-
usage:
|
|
787
|
-
prompt_tokens:
|
|
788
|
-
completion_tokens:
|
|
789
|
-
total_tokens:
|
|
790
|
-
prompt_tokens_details:
|
|
791
|
-
cached_tokens:
|
|
792
|
+
usage: z3.object({
|
|
793
|
+
prompt_tokens: z3.number().nullish(),
|
|
794
|
+
completion_tokens: z3.number().nullish(),
|
|
795
|
+
total_tokens: z3.number().nullish(),
|
|
796
|
+
prompt_tokens_details: z3.object({
|
|
797
|
+
cached_tokens: z3.number().nullish()
|
|
792
798
|
}).nullish(),
|
|
793
|
-
completion_tokens_details:
|
|
794
|
-
reasoning_tokens:
|
|
799
|
+
completion_tokens_details: z3.object({
|
|
800
|
+
reasoning_tokens: z3.number().nullish()
|
|
795
801
|
}).nullish()
|
|
796
802
|
}).nullish()
|
|
797
803
|
});
|
|
798
|
-
var groqChatChunkSchema =
|
|
799
|
-
|
|
800
|
-
id:
|
|
801
|
-
created:
|
|
802
|
-
model:
|
|
803
|
-
choices:
|
|
804
|
-
|
|
805
|
-
delta:
|
|
806
|
-
content:
|
|
807
|
-
reasoning:
|
|
808
|
-
tool_calls:
|
|
809
|
-
|
|
810
|
-
index:
|
|
811
|
-
id:
|
|
812
|
-
type:
|
|
813
|
-
function:
|
|
814
|
-
name:
|
|
815
|
-
arguments:
|
|
804
|
+
var groqChatChunkSchema = z3.union([
|
|
805
|
+
z3.object({
|
|
806
|
+
id: z3.string().nullish(),
|
|
807
|
+
created: z3.number().nullish(),
|
|
808
|
+
model: z3.string().nullish(),
|
|
809
|
+
choices: z3.array(
|
|
810
|
+
z3.object({
|
|
811
|
+
delta: z3.object({
|
|
812
|
+
content: z3.string().nullish(),
|
|
813
|
+
reasoning: z3.string().nullish(),
|
|
814
|
+
tool_calls: z3.array(
|
|
815
|
+
z3.object({
|
|
816
|
+
index: z3.number(),
|
|
817
|
+
id: z3.string().nullish(),
|
|
818
|
+
type: z3.literal("function").optional(),
|
|
819
|
+
function: z3.object({
|
|
820
|
+
name: z3.string().nullish(),
|
|
821
|
+
arguments: z3.string().nullish()
|
|
816
822
|
})
|
|
817
823
|
})
|
|
818
824
|
).nullish()
|
|
819
825
|
}).nullish(),
|
|
820
|
-
finish_reason:
|
|
821
|
-
index:
|
|
826
|
+
finish_reason: z3.string().nullable().optional(),
|
|
827
|
+
index: z3.number()
|
|
822
828
|
})
|
|
823
829
|
),
|
|
824
|
-
x_groq:
|
|
825
|
-
usage:
|
|
826
|
-
prompt_tokens:
|
|
827
|
-
completion_tokens:
|
|
828
|
-
total_tokens:
|
|
829
|
-
prompt_tokens_details:
|
|
830
|
-
cached_tokens:
|
|
830
|
+
x_groq: z3.object({
|
|
831
|
+
usage: z3.object({
|
|
832
|
+
prompt_tokens: z3.number().nullish(),
|
|
833
|
+
completion_tokens: z3.number().nullish(),
|
|
834
|
+
total_tokens: z3.number().nullish(),
|
|
835
|
+
prompt_tokens_details: z3.object({
|
|
836
|
+
cached_tokens: z3.number().nullish()
|
|
831
837
|
}).nullish(),
|
|
832
|
-
completion_tokens_details:
|
|
833
|
-
reasoning_tokens:
|
|
838
|
+
completion_tokens_details: z3.object({
|
|
839
|
+
reasoning_tokens: z3.number().nullish()
|
|
834
840
|
}).nullish()
|
|
835
841
|
}).nullish()
|
|
836
842
|
}).nullish()
|
|
@@ -839,26 +845,36 @@ var groqChatChunkSchema = import_v43.z.union([
|
|
|
839
845
|
]);
|
|
840
846
|
|
|
841
847
|
// src/groq-transcription-model.ts
|
|
842
|
-
|
|
843
|
-
|
|
848
|
+
import {
|
|
849
|
+
combineHeaders as combineHeaders2,
|
|
850
|
+
convertBase64ToUint8Array,
|
|
851
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
852
|
+
mediaTypeToExtension,
|
|
853
|
+
parseProviderOptions as parseProviderOptions2,
|
|
854
|
+
postFormDataToApi,
|
|
855
|
+
serializeModelOptions as serializeModelOptions2,
|
|
856
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
857
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
858
|
+
} from "@ai-sdk/provider-utils";
|
|
859
|
+
import { z as z5 } from "zod/v4";
|
|
844
860
|
|
|
845
861
|
// src/groq-transcription-options.ts
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
var groqTranscriptionModelOptions =
|
|
849
|
-
() =>
|
|
850
|
-
|
|
851
|
-
language:
|
|
852
|
-
prompt:
|
|
853
|
-
responseFormat:
|
|
854
|
-
temperature:
|
|
855
|
-
timestampGranularities:
|
|
862
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
863
|
+
import { z as z4 } from "zod/v4";
|
|
864
|
+
var groqTranscriptionModelOptions = lazySchema(
|
|
865
|
+
() => zodSchema(
|
|
866
|
+
z4.object({
|
|
867
|
+
language: z4.string().nullish(),
|
|
868
|
+
prompt: z4.string().nullish(),
|
|
869
|
+
responseFormat: z4.string().nullish(),
|
|
870
|
+
temperature: z4.number().min(0).max(1).nullish(),
|
|
871
|
+
timestampGranularities: z4.array(z4.string()).nullish()
|
|
856
872
|
})
|
|
857
873
|
)
|
|
858
874
|
);
|
|
859
875
|
|
|
860
876
|
// src/groq-transcription-model.ts
|
|
861
|
-
var GroqTranscriptionModel = class {
|
|
877
|
+
var GroqTranscriptionModel = class _GroqTranscriptionModel {
|
|
862
878
|
constructor(modelId, config) {
|
|
863
879
|
this.modelId = modelId;
|
|
864
880
|
this.config = config;
|
|
@@ -867,6 +883,15 @@ var GroqTranscriptionModel = class {
|
|
|
867
883
|
get provider() {
|
|
868
884
|
return this.config.provider;
|
|
869
885
|
}
|
|
886
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
887
|
+
return serializeModelOptions2({
|
|
888
|
+
modelId: model.modelId,
|
|
889
|
+
config: model.config
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
893
|
+
return new _GroqTranscriptionModel(options.modelId, options.config);
|
|
894
|
+
}
|
|
870
895
|
async getArgs({
|
|
871
896
|
audio,
|
|
872
897
|
mediaType,
|
|
@@ -874,15 +899,15 @@ var GroqTranscriptionModel = class {
|
|
|
874
899
|
}) {
|
|
875
900
|
var _a, _b, _c, _d, _e;
|
|
876
901
|
const warnings = [];
|
|
877
|
-
const groqOptions = await (
|
|
902
|
+
const groqOptions = await parseProviderOptions2({
|
|
878
903
|
provider: "groq",
|
|
879
904
|
providerOptions,
|
|
880
905
|
schema: groqTranscriptionModelOptions
|
|
881
906
|
});
|
|
882
907
|
const formData = new FormData();
|
|
883
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([
|
|
908
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
884
909
|
formData.append("model", this.modelId);
|
|
885
|
-
const fileExtension =
|
|
910
|
+
const fileExtension = mediaTypeToExtension(mediaType);
|
|
886
911
|
formData.append(
|
|
887
912
|
"file",
|
|
888
913
|
new File([blob], "audio", { type: mediaType }),
|
|
@@ -915,22 +940,22 @@ var GroqTranscriptionModel = class {
|
|
|
915
940
|
};
|
|
916
941
|
}
|
|
917
942
|
async doGenerate(options) {
|
|
918
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
943
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
919
944
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
920
945
|
const { formData, warnings } = await this.getArgs(options);
|
|
921
946
|
const {
|
|
922
947
|
value: response,
|
|
923
948
|
responseHeaders,
|
|
924
949
|
rawValue: rawResponse
|
|
925
|
-
} = await
|
|
950
|
+
} = await postFormDataToApi({
|
|
926
951
|
url: this.config.url({
|
|
927
952
|
path: "/audio/transcriptions",
|
|
928
953
|
modelId: this.modelId
|
|
929
954
|
}),
|
|
930
|
-
headers: (
|
|
955
|
+
headers: combineHeaders2((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
|
|
931
956
|
formData,
|
|
932
957
|
failedResponseHandler: groqFailedResponseHandler,
|
|
933
|
-
successfulResponseHandler: (
|
|
958
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
934
959
|
groqTranscriptionResponseSchema
|
|
935
960
|
),
|
|
936
961
|
abortSignal: options.abortSignal,
|
|
@@ -938,13 +963,13 @@ var GroqTranscriptionModel = class {
|
|
|
938
963
|
});
|
|
939
964
|
return {
|
|
940
965
|
text: response.text,
|
|
941
|
-
segments: (
|
|
966
|
+
segments: (_g = (_f = response.segments) == null ? void 0 : _f.map((segment) => ({
|
|
942
967
|
text: segment.text,
|
|
943
968
|
startSecond: segment.start,
|
|
944
969
|
endSecond: segment.end
|
|
945
|
-
}))) != null ?
|
|
946
|
-
language: (
|
|
947
|
-
durationInSeconds: (
|
|
970
|
+
}))) != null ? _g : [],
|
|
971
|
+
language: (_h = response.language) != null ? _h : void 0,
|
|
972
|
+
durationInSeconds: (_i = response.duration) != null ? _i : void 0,
|
|
948
973
|
warnings,
|
|
949
974
|
response: {
|
|
950
975
|
timestamp: currentDate,
|
|
@@ -955,37 +980,37 @@ var GroqTranscriptionModel = class {
|
|
|
955
980
|
};
|
|
956
981
|
}
|
|
957
982
|
};
|
|
958
|
-
var groqTranscriptionResponseSchema =
|
|
959
|
-
text:
|
|
960
|
-
x_groq:
|
|
961
|
-
id:
|
|
983
|
+
var groqTranscriptionResponseSchema = z5.object({
|
|
984
|
+
text: z5.string(),
|
|
985
|
+
x_groq: z5.object({
|
|
986
|
+
id: z5.string()
|
|
962
987
|
}),
|
|
963
988
|
// additional properties are returned when `response_format: 'verbose_json'` is
|
|
964
|
-
task:
|
|
965
|
-
language:
|
|
966
|
-
duration:
|
|
967
|
-
segments:
|
|
968
|
-
|
|
969
|
-
id:
|
|
970
|
-
seek:
|
|
971
|
-
start:
|
|
972
|
-
end:
|
|
973
|
-
text:
|
|
974
|
-
tokens:
|
|
975
|
-
temperature:
|
|
976
|
-
avg_logprob:
|
|
977
|
-
compression_ratio:
|
|
978
|
-
no_speech_prob:
|
|
989
|
+
task: z5.string().nullish(),
|
|
990
|
+
language: z5.string().nullish(),
|
|
991
|
+
duration: z5.number().nullish(),
|
|
992
|
+
segments: z5.array(
|
|
993
|
+
z5.object({
|
|
994
|
+
id: z5.number(),
|
|
995
|
+
seek: z5.number(),
|
|
996
|
+
start: z5.number(),
|
|
997
|
+
end: z5.number(),
|
|
998
|
+
text: z5.string(),
|
|
999
|
+
tokens: z5.array(z5.number()),
|
|
1000
|
+
temperature: z5.number(),
|
|
1001
|
+
avg_logprob: z5.number(),
|
|
1002
|
+
compression_ratio: z5.number(),
|
|
1003
|
+
no_speech_prob: z5.number()
|
|
979
1004
|
})
|
|
980
1005
|
).nullish()
|
|
981
1006
|
});
|
|
982
1007
|
|
|
983
1008
|
// src/tool/browser-search.ts
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
var browserSearch =
|
|
1009
|
+
import { createProviderToolFactory } from "@ai-sdk/provider-utils";
|
|
1010
|
+
import { z as z6 } from "zod/v4";
|
|
1011
|
+
var browserSearch = createProviderToolFactory({
|
|
987
1012
|
id: "groq.browser_search",
|
|
988
|
-
inputSchema:
|
|
1013
|
+
inputSchema: z6.object({})
|
|
989
1014
|
});
|
|
990
1015
|
|
|
991
1016
|
// src/groq-tools.ts
|
|
@@ -994,15 +1019,15 @@ var groqTools = {
|
|
|
994
1019
|
};
|
|
995
1020
|
|
|
996
1021
|
// src/version.ts
|
|
997
|
-
var VERSION = true ? "4.0.0-beta.
|
|
1022
|
+
var VERSION = true ? "4.0.0-beta.24" : "0.0.0-test";
|
|
998
1023
|
|
|
999
1024
|
// src/groq-provider.ts
|
|
1000
1025
|
function createGroq(options = {}) {
|
|
1001
1026
|
var _a;
|
|
1002
|
-
const baseURL = (_a =
|
|
1003
|
-
const getHeaders = () =>
|
|
1027
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
|
|
1028
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
1004
1029
|
{
|
|
1005
|
-
Authorization: `Bearer ${
|
|
1030
|
+
Authorization: `Bearer ${loadApiKey({
|
|
1006
1031
|
apiKey: options.apiKey,
|
|
1007
1032
|
environmentVariableName: "GROQ_API_KEY",
|
|
1008
1033
|
description: "Groq"
|
|
@@ -1040,11 +1065,11 @@ function createGroq(options = {}) {
|
|
|
1040
1065
|
provider.languageModel = createLanguageModel;
|
|
1041
1066
|
provider.chat = createChatModel;
|
|
1042
1067
|
provider.embeddingModel = (modelId) => {
|
|
1043
|
-
throw new
|
|
1068
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
1044
1069
|
};
|
|
1045
1070
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
1046
1071
|
provider.imageModel = (modelId) => {
|
|
1047
|
-
throw new
|
|
1072
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1048
1073
|
};
|
|
1049
1074
|
provider.transcription = createTranscriptionModel;
|
|
1050
1075
|
provider.transcriptionModel = createTranscriptionModel;
|
|
@@ -1052,11 +1077,10 @@ function createGroq(options = {}) {
|
|
|
1052
1077
|
return provider;
|
|
1053
1078
|
}
|
|
1054
1079
|
var groq = createGroq();
|
|
1055
|
-
|
|
1056
|
-
0 && (module.exports = {
|
|
1080
|
+
export {
|
|
1057
1081
|
VERSION,
|
|
1058
1082
|
browserSearch,
|
|
1059
1083
|
createGroq,
|
|
1060
1084
|
groq
|
|
1061
|
-
}
|
|
1085
|
+
};
|
|
1062
1086
|
//# sourceMappingURL=index.js.map
|