@ai-sdk/groq 4.0.0-beta.22 → 4.0.0-beta.23
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 +12 -0
- package/dist/index.js +178 -179
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/index.d.mts +0 -113
- package/dist/index.mjs +0 -1061
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/groq
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.23
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [ef992f8]
|
|
12
|
+
- @ai-sdk/provider@4.0.0-beta.11
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.0-beta.19
|
|
14
|
+
|
|
3
15
|
## 4.0.0-beta.22
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,40 +1,29 @@
|
|
|
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
|
+
} from "@ai-sdk/provider-utils";
|
|
26
|
+
import { z as z3 } from "zod/v4";
|
|
38
27
|
|
|
39
28
|
// src/convert-groq-usage.ts
|
|
40
29
|
function convertGroqUsage(usage) {
|
|
@@ -76,8 +65,10 @@ function convertGroqUsage(usage) {
|
|
|
76
65
|
}
|
|
77
66
|
|
|
78
67
|
// src/convert-to-groq-chat-messages.ts
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
import {
|
|
69
|
+
UnsupportedFunctionalityError
|
|
70
|
+
} from "@ai-sdk/provider";
|
|
71
|
+
import { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
|
|
81
72
|
function convertToGroqChatMessages(prompt) {
|
|
82
73
|
var _a;
|
|
83
74
|
const messages = [];
|
|
@@ -100,13 +91,13 @@ function convertToGroqChatMessages(prompt) {
|
|
|
100
91
|
return { type: "text", text: part.text };
|
|
101
92
|
}
|
|
102
93
|
case "file": {
|
|
103
|
-
if (
|
|
104
|
-
throw new
|
|
94
|
+
if (isProviderReference(part.data)) {
|
|
95
|
+
throw new UnsupportedFunctionalityError({
|
|
105
96
|
functionality: "file parts with provider references"
|
|
106
97
|
});
|
|
107
98
|
}
|
|
108
99
|
if (!part.mediaType.startsWith("image/")) {
|
|
109
|
-
throw new
|
|
100
|
+
throw new UnsupportedFunctionalityError({
|
|
110
101
|
functionality: "Non-image file content parts"
|
|
111
102
|
});
|
|
112
103
|
}
|
|
@@ -114,7 +105,7 @@ function convertToGroqChatMessages(prompt) {
|
|
|
114
105
|
return {
|
|
115
106
|
type: "image_url",
|
|
116
107
|
image_url: {
|
|
117
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
108
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
118
109
|
}
|
|
119
110
|
};
|
|
120
111
|
}
|
|
@@ -212,29 +203,29 @@ function getResponseMetadata({
|
|
|
212
203
|
}
|
|
213
204
|
|
|
214
205
|
// src/groq-chat-options.ts
|
|
215
|
-
|
|
216
|
-
var groqLanguageModelOptions =
|
|
217
|
-
reasoningFormat:
|
|
206
|
+
import { z } from "zod/v4";
|
|
207
|
+
var groqLanguageModelOptions = z.object({
|
|
208
|
+
reasoningFormat: z.enum(["parsed", "raw", "hidden"]).optional(),
|
|
218
209
|
/**
|
|
219
210
|
* Specifies the reasoning effort level for model inference.
|
|
220
211
|
* @see https://console.groq.com/docs/reasoning#reasoning-effort
|
|
221
212
|
*/
|
|
222
|
-
reasoningEffort:
|
|
213
|
+
reasoningEffort: z.enum(["none", "default", "low", "medium", "high"]).optional(),
|
|
223
214
|
/**
|
|
224
215
|
* Whether to enable parallel function calling during tool use. Default to true.
|
|
225
216
|
*/
|
|
226
|
-
parallelToolCalls:
|
|
217
|
+
parallelToolCalls: z.boolean().optional(),
|
|
227
218
|
/**
|
|
228
219
|
* A unique identifier representing your end-user, which can help OpenAI to
|
|
229
220
|
* monitor and detect abuse. Learn more.
|
|
230
221
|
*/
|
|
231
|
-
user:
|
|
222
|
+
user: z.string().optional(),
|
|
232
223
|
/**
|
|
233
224
|
* Whether to use structured outputs.
|
|
234
225
|
*
|
|
235
226
|
* @default true
|
|
236
227
|
*/
|
|
237
|
-
structuredOutputs:
|
|
228
|
+
structuredOutputs: z.boolean().optional(),
|
|
238
229
|
/**
|
|
239
230
|
* Whether to use strict JSON schema validation.
|
|
240
231
|
* When true, the model uses constrained decoding to guarantee schema compliance.
|
|
@@ -242,7 +233,7 @@ var groqLanguageModelOptions = import_v4.z.object({
|
|
|
242
233
|
*
|
|
243
234
|
* @default true
|
|
244
235
|
*/
|
|
245
|
-
strictJsonSchema:
|
|
236
|
+
strictJsonSchema: z.boolean().optional(),
|
|
246
237
|
/**
|
|
247
238
|
* Service tier for the request.
|
|
248
239
|
* - 'on_demand': Default tier with consistent performance and fairness
|
|
@@ -252,25 +243,27 @@ var groqLanguageModelOptions = import_v4.z.object({
|
|
|
252
243
|
*
|
|
253
244
|
* @default 'on_demand'
|
|
254
245
|
*/
|
|
255
|
-
serviceTier:
|
|
246
|
+
serviceTier: z.enum(["on_demand", "performance", "flex", "auto"]).optional()
|
|
256
247
|
});
|
|
257
248
|
|
|
258
249
|
// src/groq-error.ts
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
var groqErrorDataSchema =
|
|
262
|
-
error:
|
|
263
|
-
message:
|
|
264
|
-
type:
|
|
250
|
+
import { z as z2 } from "zod/v4";
|
|
251
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
252
|
+
var groqErrorDataSchema = z2.object({
|
|
253
|
+
error: z2.object({
|
|
254
|
+
message: z2.string(),
|
|
255
|
+
type: z2.string()
|
|
265
256
|
})
|
|
266
257
|
});
|
|
267
|
-
var groqFailedResponseHandler =
|
|
258
|
+
var groqFailedResponseHandler = createJsonErrorResponseHandler({
|
|
268
259
|
errorSchema: groqErrorDataSchema,
|
|
269
260
|
errorToMessage: (data) => data.error.message
|
|
270
261
|
});
|
|
271
262
|
|
|
272
263
|
// src/groq-prepare-tools.ts
|
|
273
|
-
|
|
264
|
+
import {
|
|
265
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
266
|
+
} from "@ai-sdk/provider";
|
|
274
267
|
|
|
275
268
|
// src/groq-browser-search-models.ts
|
|
276
269
|
var BROWSER_SEARCH_SUPPORTED_MODELS = [
|
|
@@ -350,7 +343,7 @@ function prepareTools({
|
|
|
350
343
|
};
|
|
351
344
|
default: {
|
|
352
345
|
const _exhaustiveCheck = type;
|
|
353
|
-
throw new
|
|
346
|
+
throw new UnsupportedFunctionalityError2({
|
|
354
347
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
355
348
|
});
|
|
356
349
|
}
|
|
@@ -405,7 +398,7 @@ var GroqChatLanguageModel = class {
|
|
|
405
398
|
}) {
|
|
406
399
|
var _a, _b, _c, _d;
|
|
407
400
|
const warnings = [];
|
|
408
|
-
const groqOptions = await
|
|
401
|
+
const groqOptions = await parseProviderOptions({
|
|
409
402
|
provider: "groq",
|
|
410
403
|
providerOptions,
|
|
411
404
|
schema: groqLanguageModelOptions
|
|
@@ -454,7 +447,7 @@ var GroqChatLanguageModel = class {
|
|
|
454
447
|
} : { type: "json_object" } : void 0,
|
|
455
448
|
// provider options:
|
|
456
449
|
reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
|
|
457
|
-
reasoning_effort: (_d = groqOptions == null ? void 0 : groqOptions.reasoningEffort) != null ? _d :
|
|
450
|
+
reasoning_effort: (_d = groqOptions == null ? void 0 : groqOptions.reasoningEffort) != null ? _d : isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
|
|
458
451
|
reasoning,
|
|
459
452
|
effortMap: {
|
|
460
453
|
minimal: "low",
|
|
@@ -483,15 +476,15 @@ var GroqChatLanguageModel = class {
|
|
|
483
476
|
responseHeaders,
|
|
484
477
|
value: response,
|
|
485
478
|
rawValue: rawResponse
|
|
486
|
-
} = await
|
|
479
|
+
} = await postJsonToApi({
|
|
487
480
|
url: this.config.url({
|
|
488
481
|
path: "/chat/completions",
|
|
489
482
|
modelId: this.modelId
|
|
490
483
|
}),
|
|
491
|
-
headers:
|
|
484
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
492
485
|
body: args,
|
|
493
486
|
failedResponseHandler: groqFailedResponseHandler,
|
|
494
|
-
successfulResponseHandler:
|
|
487
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
495
488
|
groqChatResponseSchema
|
|
496
489
|
),
|
|
497
490
|
abortSignal: options.abortSignal,
|
|
@@ -514,7 +507,7 @@ var GroqChatLanguageModel = class {
|
|
|
514
507
|
for (const toolCall of choice.message.tool_calls) {
|
|
515
508
|
content.push({
|
|
516
509
|
type: "tool-call",
|
|
517
|
-
toolCallId: (_a = toolCall.id) != null ? _a :
|
|
510
|
+
toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
|
|
518
511
|
toolName: toolCall.function.name,
|
|
519
512
|
input: toolCall.function.arguments
|
|
520
513
|
});
|
|
@@ -539,15 +532,15 @@ var GroqChatLanguageModel = class {
|
|
|
539
532
|
async doStream(options) {
|
|
540
533
|
const { args, warnings } = await this.getArgs(options);
|
|
541
534
|
const body = { ...args, stream: true };
|
|
542
|
-
const { responseHeaders, value: response } = await
|
|
535
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
543
536
|
url: this.config.url({
|
|
544
537
|
path: "/chat/completions",
|
|
545
538
|
modelId: this.modelId
|
|
546
539
|
}),
|
|
547
|
-
headers:
|
|
540
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
548
541
|
body,
|
|
549
542
|
failedResponseHandler: groqFailedResponseHandler,
|
|
550
|
-
successfulResponseHandler:
|
|
543
|
+
successfulResponseHandler: createEventSourceResponseHandler(groqChatChunkSchema),
|
|
551
544
|
abortSignal: options.abortSignal,
|
|
552
545
|
fetch: this.config.fetch
|
|
553
546
|
});
|
|
@@ -654,19 +647,19 @@ var GroqChatLanguageModel = class {
|
|
|
654
647
|
const index = toolCallDelta.index;
|
|
655
648
|
if (toolCalls[index] == null) {
|
|
656
649
|
if (toolCallDelta.type !== "function") {
|
|
657
|
-
throw new
|
|
650
|
+
throw new InvalidResponseDataError({
|
|
658
651
|
data: toolCallDelta,
|
|
659
652
|
message: `Expected 'function' type.`
|
|
660
653
|
});
|
|
661
654
|
}
|
|
662
655
|
if (toolCallDelta.id == null) {
|
|
663
|
-
throw new
|
|
656
|
+
throw new InvalidResponseDataError({
|
|
664
657
|
data: toolCallDelta,
|
|
665
658
|
message: `Expected 'id' to be a string.`
|
|
666
659
|
});
|
|
667
660
|
}
|
|
668
661
|
if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
|
|
669
|
-
throw new
|
|
662
|
+
throw new InvalidResponseDataError({
|
|
670
663
|
data: toolCallDelta,
|
|
671
664
|
message: `Expected 'function.name' to be a string.`
|
|
672
665
|
});
|
|
@@ -694,14 +687,14 @@ var GroqChatLanguageModel = class {
|
|
|
694
687
|
delta: toolCall2.function.arguments
|
|
695
688
|
});
|
|
696
689
|
}
|
|
697
|
-
if (
|
|
690
|
+
if (isParsableJson(toolCall2.function.arguments)) {
|
|
698
691
|
controller.enqueue({
|
|
699
692
|
type: "tool-input-end",
|
|
700
693
|
id: toolCall2.id
|
|
701
694
|
});
|
|
702
695
|
controller.enqueue({
|
|
703
696
|
type: "tool-call",
|
|
704
|
-
toolCallId: (_f = toolCall2.id) != null ? _f :
|
|
697
|
+
toolCallId: (_f = toolCall2.id) != null ? _f : generateId(),
|
|
705
698
|
toolName: toolCall2.function.name,
|
|
706
699
|
input: toolCall2.function.arguments
|
|
707
700
|
});
|
|
@@ -722,14 +715,14 @@ var GroqChatLanguageModel = class {
|
|
|
722
715
|
id: toolCall.id,
|
|
723
716
|
delta: (_j = toolCallDelta.function.arguments) != null ? _j : ""
|
|
724
717
|
});
|
|
725
|
-
if (((_k = toolCall.function) == null ? void 0 : _k.name) != null && ((_l = toolCall.function) == null ? void 0 : _l.arguments) != null &&
|
|
718
|
+
if (((_k = toolCall.function) == null ? void 0 : _k.name) != null && ((_l = toolCall.function) == null ? void 0 : _l.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
726
719
|
controller.enqueue({
|
|
727
720
|
type: "tool-input-end",
|
|
728
721
|
id: toolCall.id
|
|
729
722
|
});
|
|
730
723
|
controller.enqueue({
|
|
731
724
|
type: "tool-call",
|
|
732
|
-
toolCallId: (_m = toolCall.id) != null ? _m :
|
|
725
|
+
toolCallId: (_m = toolCall.id) != null ? _m : generateId(),
|
|
733
726
|
toolName: toolCall.function.name,
|
|
734
727
|
input: toolCall.function.arguments
|
|
735
728
|
});
|
|
@@ -759,78 +752,78 @@ var GroqChatLanguageModel = class {
|
|
|
759
752
|
};
|
|
760
753
|
}
|
|
761
754
|
};
|
|
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:
|
|
755
|
+
var groqChatResponseSchema = z3.object({
|
|
756
|
+
id: z3.string().nullish(),
|
|
757
|
+
created: z3.number().nullish(),
|
|
758
|
+
model: z3.string().nullish(),
|
|
759
|
+
choices: z3.array(
|
|
760
|
+
z3.object({
|
|
761
|
+
message: z3.object({
|
|
762
|
+
content: z3.string().nullish(),
|
|
763
|
+
reasoning: z3.string().nullish(),
|
|
764
|
+
tool_calls: z3.array(
|
|
765
|
+
z3.object({
|
|
766
|
+
id: z3.string().nullish(),
|
|
767
|
+
type: z3.literal("function"),
|
|
768
|
+
function: z3.object({
|
|
769
|
+
name: z3.string(),
|
|
770
|
+
arguments: z3.string()
|
|
778
771
|
})
|
|
779
772
|
})
|
|
780
773
|
).nullish()
|
|
781
774
|
}),
|
|
782
|
-
index:
|
|
783
|
-
finish_reason:
|
|
775
|
+
index: z3.number(),
|
|
776
|
+
finish_reason: z3.string().nullish()
|
|
784
777
|
})
|
|
785
778
|
),
|
|
786
|
-
usage:
|
|
787
|
-
prompt_tokens:
|
|
788
|
-
completion_tokens:
|
|
789
|
-
total_tokens:
|
|
790
|
-
prompt_tokens_details:
|
|
791
|
-
cached_tokens:
|
|
779
|
+
usage: z3.object({
|
|
780
|
+
prompt_tokens: z3.number().nullish(),
|
|
781
|
+
completion_tokens: z3.number().nullish(),
|
|
782
|
+
total_tokens: z3.number().nullish(),
|
|
783
|
+
prompt_tokens_details: z3.object({
|
|
784
|
+
cached_tokens: z3.number().nullish()
|
|
792
785
|
}).nullish(),
|
|
793
|
-
completion_tokens_details:
|
|
794
|
-
reasoning_tokens:
|
|
786
|
+
completion_tokens_details: z3.object({
|
|
787
|
+
reasoning_tokens: z3.number().nullish()
|
|
795
788
|
}).nullish()
|
|
796
789
|
}).nullish()
|
|
797
790
|
});
|
|
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:
|
|
791
|
+
var groqChatChunkSchema = z3.union([
|
|
792
|
+
z3.object({
|
|
793
|
+
id: z3.string().nullish(),
|
|
794
|
+
created: z3.number().nullish(),
|
|
795
|
+
model: z3.string().nullish(),
|
|
796
|
+
choices: z3.array(
|
|
797
|
+
z3.object({
|
|
798
|
+
delta: z3.object({
|
|
799
|
+
content: z3.string().nullish(),
|
|
800
|
+
reasoning: z3.string().nullish(),
|
|
801
|
+
tool_calls: z3.array(
|
|
802
|
+
z3.object({
|
|
803
|
+
index: z3.number(),
|
|
804
|
+
id: z3.string().nullish(),
|
|
805
|
+
type: z3.literal("function").optional(),
|
|
806
|
+
function: z3.object({
|
|
807
|
+
name: z3.string().nullish(),
|
|
808
|
+
arguments: z3.string().nullish()
|
|
816
809
|
})
|
|
817
810
|
})
|
|
818
811
|
).nullish()
|
|
819
812
|
}).nullish(),
|
|
820
|
-
finish_reason:
|
|
821
|
-
index:
|
|
813
|
+
finish_reason: z3.string().nullable().optional(),
|
|
814
|
+
index: z3.number()
|
|
822
815
|
})
|
|
823
816
|
),
|
|
824
|
-
x_groq:
|
|
825
|
-
usage:
|
|
826
|
-
prompt_tokens:
|
|
827
|
-
completion_tokens:
|
|
828
|
-
total_tokens:
|
|
829
|
-
prompt_tokens_details:
|
|
830
|
-
cached_tokens:
|
|
817
|
+
x_groq: z3.object({
|
|
818
|
+
usage: z3.object({
|
|
819
|
+
prompt_tokens: z3.number().nullish(),
|
|
820
|
+
completion_tokens: z3.number().nullish(),
|
|
821
|
+
total_tokens: z3.number().nullish(),
|
|
822
|
+
prompt_tokens_details: z3.object({
|
|
823
|
+
cached_tokens: z3.number().nullish()
|
|
831
824
|
}).nullish(),
|
|
832
|
-
completion_tokens_details:
|
|
833
|
-
reasoning_tokens:
|
|
825
|
+
completion_tokens_details: z3.object({
|
|
826
|
+
reasoning_tokens: z3.number().nullish()
|
|
834
827
|
}).nullish()
|
|
835
828
|
}).nullish()
|
|
836
829
|
}).nullish()
|
|
@@ -839,20 +832,27 @@ var groqChatChunkSchema = import_v43.z.union([
|
|
|
839
832
|
]);
|
|
840
833
|
|
|
841
834
|
// src/groq-transcription-model.ts
|
|
842
|
-
|
|
843
|
-
|
|
835
|
+
import {
|
|
836
|
+
combineHeaders as combineHeaders2,
|
|
837
|
+
convertBase64ToUint8Array,
|
|
838
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
839
|
+
mediaTypeToExtension,
|
|
840
|
+
parseProviderOptions as parseProviderOptions2,
|
|
841
|
+
postFormDataToApi
|
|
842
|
+
} from "@ai-sdk/provider-utils";
|
|
843
|
+
import { z as z5 } from "zod/v4";
|
|
844
844
|
|
|
845
845
|
// src/groq-transcription-options.ts
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
var groqTranscriptionModelOptions =
|
|
849
|
-
() =>
|
|
850
|
-
|
|
851
|
-
language:
|
|
852
|
-
prompt:
|
|
853
|
-
responseFormat:
|
|
854
|
-
temperature:
|
|
855
|
-
timestampGranularities:
|
|
846
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
847
|
+
import { z as z4 } from "zod/v4";
|
|
848
|
+
var groqTranscriptionModelOptions = lazySchema(
|
|
849
|
+
() => zodSchema(
|
|
850
|
+
z4.object({
|
|
851
|
+
language: z4.string().nullish(),
|
|
852
|
+
prompt: z4.string().nullish(),
|
|
853
|
+
responseFormat: z4.string().nullish(),
|
|
854
|
+
temperature: z4.number().min(0).max(1).nullish(),
|
|
855
|
+
timestampGranularities: z4.array(z4.string()).nullish()
|
|
856
856
|
})
|
|
857
857
|
)
|
|
858
858
|
);
|
|
@@ -874,15 +874,15 @@ var GroqTranscriptionModel = class {
|
|
|
874
874
|
}) {
|
|
875
875
|
var _a, _b, _c, _d, _e;
|
|
876
876
|
const warnings = [];
|
|
877
|
-
const groqOptions = await (
|
|
877
|
+
const groqOptions = await parseProviderOptions2({
|
|
878
878
|
provider: "groq",
|
|
879
879
|
providerOptions,
|
|
880
880
|
schema: groqTranscriptionModelOptions
|
|
881
881
|
});
|
|
882
882
|
const formData = new FormData();
|
|
883
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([
|
|
883
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
884
884
|
formData.append("model", this.modelId);
|
|
885
|
-
const fileExtension =
|
|
885
|
+
const fileExtension = mediaTypeToExtension(mediaType);
|
|
886
886
|
formData.append(
|
|
887
887
|
"file",
|
|
888
888
|
new File([blob], "audio", { type: mediaType }),
|
|
@@ -922,15 +922,15 @@ var GroqTranscriptionModel = class {
|
|
|
922
922
|
value: response,
|
|
923
923
|
responseHeaders,
|
|
924
924
|
rawValue: rawResponse
|
|
925
|
-
} = await
|
|
925
|
+
} = await postFormDataToApi({
|
|
926
926
|
url: this.config.url({
|
|
927
927
|
path: "/audio/transcriptions",
|
|
928
928
|
modelId: this.modelId
|
|
929
929
|
}),
|
|
930
|
-
headers: (
|
|
930
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
931
931
|
formData,
|
|
932
932
|
failedResponseHandler: groqFailedResponseHandler,
|
|
933
|
-
successfulResponseHandler: (
|
|
933
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
934
934
|
groqTranscriptionResponseSchema
|
|
935
935
|
),
|
|
936
936
|
abortSignal: options.abortSignal,
|
|
@@ -955,37 +955,37 @@ var GroqTranscriptionModel = class {
|
|
|
955
955
|
};
|
|
956
956
|
}
|
|
957
957
|
};
|
|
958
|
-
var groqTranscriptionResponseSchema =
|
|
959
|
-
text:
|
|
960
|
-
x_groq:
|
|
961
|
-
id:
|
|
958
|
+
var groqTranscriptionResponseSchema = z5.object({
|
|
959
|
+
text: z5.string(),
|
|
960
|
+
x_groq: z5.object({
|
|
961
|
+
id: z5.string()
|
|
962
962
|
}),
|
|
963
963
|
// 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:
|
|
964
|
+
task: z5.string().nullish(),
|
|
965
|
+
language: z5.string().nullish(),
|
|
966
|
+
duration: z5.number().nullish(),
|
|
967
|
+
segments: z5.array(
|
|
968
|
+
z5.object({
|
|
969
|
+
id: z5.number(),
|
|
970
|
+
seek: z5.number(),
|
|
971
|
+
start: z5.number(),
|
|
972
|
+
end: z5.number(),
|
|
973
|
+
text: z5.string(),
|
|
974
|
+
tokens: z5.array(z5.number()),
|
|
975
|
+
temperature: z5.number(),
|
|
976
|
+
avg_logprob: z5.number(),
|
|
977
|
+
compression_ratio: z5.number(),
|
|
978
|
+
no_speech_prob: z5.number()
|
|
979
979
|
})
|
|
980
980
|
).nullish()
|
|
981
981
|
});
|
|
982
982
|
|
|
983
983
|
// src/tool/browser-search.ts
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
var browserSearch =
|
|
984
|
+
import { createProviderToolFactory } from "@ai-sdk/provider-utils";
|
|
985
|
+
import { z as z6 } from "zod/v4";
|
|
986
|
+
var browserSearch = createProviderToolFactory({
|
|
987
987
|
id: "groq.browser_search",
|
|
988
|
-
inputSchema:
|
|
988
|
+
inputSchema: z6.object({})
|
|
989
989
|
});
|
|
990
990
|
|
|
991
991
|
// src/groq-tools.ts
|
|
@@ -994,15 +994,15 @@ var groqTools = {
|
|
|
994
994
|
};
|
|
995
995
|
|
|
996
996
|
// src/version.ts
|
|
997
|
-
var VERSION = true ? "4.0.0-beta.
|
|
997
|
+
var VERSION = true ? "4.0.0-beta.23" : "0.0.0-test";
|
|
998
998
|
|
|
999
999
|
// src/groq-provider.ts
|
|
1000
1000
|
function createGroq(options = {}) {
|
|
1001
1001
|
var _a;
|
|
1002
|
-
const baseURL = (_a =
|
|
1003
|
-
const getHeaders = () =>
|
|
1002
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
|
|
1003
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
1004
1004
|
{
|
|
1005
|
-
Authorization: `Bearer ${
|
|
1005
|
+
Authorization: `Bearer ${loadApiKey({
|
|
1006
1006
|
apiKey: options.apiKey,
|
|
1007
1007
|
environmentVariableName: "GROQ_API_KEY",
|
|
1008
1008
|
description: "Groq"
|
|
@@ -1040,11 +1040,11 @@ function createGroq(options = {}) {
|
|
|
1040
1040
|
provider.languageModel = createLanguageModel;
|
|
1041
1041
|
provider.chat = createChatModel;
|
|
1042
1042
|
provider.embeddingModel = (modelId) => {
|
|
1043
|
-
throw new
|
|
1043
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
1044
1044
|
};
|
|
1045
1045
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
1046
1046
|
provider.imageModel = (modelId) => {
|
|
1047
|
-
throw new
|
|
1047
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1048
1048
|
};
|
|
1049
1049
|
provider.transcription = createTranscriptionModel;
|
|
1050
1050
|
provider.transcriptionModel = createTranscriptionModel;
|
|
@@ -1052,11 +1052,10 @@ function createGroq(options = {}) {
|
|
|
1052
1052
|
return provider;
|
|
1053
1053
|
}
|
|
1054
1054
|
var groq = createGroq();
|
|
1055
|
-
|
|
1056
|
-
0 && (module.exports = {
|
|
1055
|
+
export {
|
|
1057
1056
|
VERSION,
|
|
1058
1057
|
browserSearch,
|
|
1059
1058
|
createGroq,
|
|
1060
1059
|
groq
|
|
1061
|
-
}
|
|
1060
|
+
};
|
|
1062
1061
|
//# sourceMappingURL=index.js.map
|