@ai-sdk/groq 4.0.0-beta.3 → 4.0.0-beta.30
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 +221 -4
- package/README.md +2 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.js +237 -282
- package/dist/index.js.map +1 -1
- package/docs/09-groq.mdx +3 -2
- package/package.json +7 -9
- package/src/convert-groq-usage.ts +2 -2
- package/src/convert-to-groq-chat-messages.ts +9 -3
- package/src/groq-chat-language-model.ts +76 -165
- package/src/groq-chat-options.ts +2 -1
- package/src/groq-config.ts +1 -1
- package/src/groq-prepare-tools.ts +6 -6
- package/src/groq-provider.ts +8 -8
- package/src/groq-transcription-model.ts +25 -8
- package/src/map-groq-finish-reason.ts +2 -2
- package/dist/index.d.mts +0 -112
- package/dist/index.mjs +0 -1049
- package/dist/index.mjs.map +0 -1
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
|
+
StreamingToolCallTracker,
|
|
14
|
+
combineHeaders,
|
|
15
|
+
createEventSourceResponseHandler,
|
|
16
|
+
createJsonResponseHandler,
|
|
17
|
+
generateId,
|
|
18
|
+
isCustomReasoning,
|
|
19
|
+
mapReasoningToProviderEffort,
|
|
20
|
+
parseProviderOptions,
|
|
21
|
+
postJsonToApi,
|
|
22
|
+
serializeModelOptions,
|
|
23
|
+
WORKFLOW_SERIALIZE,
|
|
24
|
+
WORKFLOW_DESERIALIZE
|
|
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,8 +91,13 @@ function convertToGroqChatMessages(prompt) {
|
|
|
100
91
|
return { type: "text", text: part.text };
|
|
101
92
|
}
|
|
102
93
|
case "file": {
|
|
94
|
+
if (isProviderReference(part.data)) {
|
|
95
|
+
throw new UnsupportedFunctionalityError({
|
|
96
|
+
functionality: "file parts with provider references"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
103
99
|
if (!part.mediaType.startsWith("image/")) {
|
|
104
|
-
throw new
|
|
100
|
+
throw new UnsupportedFunctionalityError({
|
|
105
101
|
functionality: "Non-image file content parts"
|
|
106
102
|
});
|
|
107
103
|
}
|
|
@@ -109,7 +105,7 @@ function convertToGroqChatMessages(prompt) {
|
|
|
109
105
|
return {
|
|
110
106
|
type: "image_url",
|
|
111
107
|
image_url: {
|
|
112
|
-
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)}`
|
|
113
109
|
}
|
|
114
110
|
};
|
|
115
111
|
}
|
|
@@ -207,29 +203,29 @@ function getResponseMetadata({
|
|
|
207
203
|
}
|
|
208
204
|
|
|
209
205
|
// src/groq-chat-options.ts
|
|
210
|
-
|
|
211
|
-
var groqLanguageModelOptions =
|
|
212
|
-
reasoningFormat:
|
|
206
|
+
import { z } from "zod/v4";
|
|
207
|
+
var groqLanguageModelOptions = z.object({
|
|
208
|
+
reasoningFormat: z.enum(["parsed", "raw", "hidden"]).optional(),
|
|
213
209
|
/**
|
|
214
210
|
* Specifies the reasoning effort level for model inference.
|
|
215
211
|
* @see https://console.groq.com/docs/reasoning#reasoning-effort
|
|
216
212
|
*/
|
|
217
|
-
reasoningEffort:
|
|
213
|
+
reasoningEffort: z.enum(["none", "default", "low", "medium", "high"]).optional(),
|
|
218
214
|
/**
|
|
219
215
|
* Whether to enable parallel function calling during tool use. Default to true.
|
|
220
216
|
*/
|
|
221
|
-
parallelToolCalls:
|
|
217
|
+
parallelToolCalls: z.boolean().optional(),
|
|
222
218
|
/**
|
|
223
219
|
* A unique identifier representing your end-user, which can help OpenAI to
|
|
224
220
|
* monitor and detect abuse. Learn more.
|
|
225
221
|
*/
|
|
226
|
-
user:
|
|
222
|
+
user: z.string().optional(),
|
|
227
223
|
/**
|
|
228
224
|
* Whether to use structured outputs.
|
|
229
225
|
*
|
|
230
226
|
* @default true
|
|
231
227
|
*/
|
|
232
|
-
structuredOutputs:
|
|
228
|
+
structuredOutputs: z.boolean().optional(),
|
|
233
229
|
/**
|
|
234
230
|
* Whether to use strict JSON schema validation.
|
|
235
231
|
* When true, the model uses constrained decoding to guarantee schema compliance.
|
|
@@ -237,34 +233,37 @@ var groqLanguageModelOptions = import_v4.z.object({
|
|
|
237
233
|
*
|
|
238
234
|
* @default true
|
|
239
235
|
*/
|
|
240
|
-
strictJsonSchema:
|
|
236
|
+
strictJsonSchema: z.boolean().optional(),
|
|
241
237
|
/**
|
|
242
238
|
* Service tier for the request.
|
|
243
239
|
* - 'on_demand': Default tier with consistent performance and fairness
|
|
240
|
+
* - 'performance': Prioritized tier for latency-sensitive workloads
|
|
244
241
|
* - 'flex': Higher throughput tier optimized for workloads that can handle occasional request failures
|
|
245
242
|
* - 'auto': Uses on_demand rate limits, then falls back to flex tier if exceeded
|
|
246
243
|
*
|
|
247
244
|
* @default 'on_demand'
|
|
248
245
|
*/
|
|
249
|
-
serviceTier:
|
|
246
|
+
serviceTier: z.enum(["on_demand", "performance", "flex", "auto"]).optional()
|
|
250
247
|
});
|
|
251
248
|
|
|
252
249
|
// src/groq-error.ts
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
var groqErrorDataSchema =
|
|
256
|
-
error:
|
|
257
|
-
message:
|
|
258
|
-
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()
|
|
259
256
|
})
|
|
260
257
|
});
|
|
261
|
-
var groqFailedResponseHandler =
|
|
258
|
+
var groqFailedResponseHandler = createJsonErrorResponseHandler({
|
|
262
259
|
errorSchema: groqErrorDataSchema,
|
|
263
260
|
errorToMessage: (data) => data.error.message
|
|
264
261
|
});
|
|
265
262
|
|
|
266
263
|
// src/groq-prepare-tools.ts
|
|
267
|
-
|
|
264
|
+
import {
|
|
265
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
266
|
+
} from "@ai-sdk/provider";
|
|
268
267
|
|
|
269
268
|
// src/groq-browser-search-models.ts
|
|
270
269
|
var BROWSER_SEARCH_SUPPORTED_MODELS = [
|
|
@@ -344,7 +343,7 @@ function prepareTools({
|
|
|
344
343
|
};
|
|
345
344
|
default: {
|
|
346
345
|
const _exhaustiveCheck = type;
|
|
347
|
-
throw new
|
|
346
|
+
throw new UnsupportedFunctionalityError2({
|
|
348
347
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
349
348
|
});
|
|
350
349
|
}
|
|
@@ -369,15 +368,24 @@ function mapGroqFinishReason(finishReason) {
|
|
|
369
368
|
}
|
|
370
369
|
|
|
371
370
|
// src/groq-chat-language-model.ts
|
|
372
|
-
var GroqChatLanguageModel = class {
|
|
371
|
+
var GroqChatLanguageModel = class _GroqChatLanguageModel {
|
|
373
372
|
constructor(modelId, config) {
|
|
374
|
-
this.specificationVersion = "
|
|
373
|
+
this.specificationVersion = "v4";
|
|
375
374
|
this.supportedUrls = {
|
|
376
375
|
"image/*": [/^https?:\/\/.*$/]
|
|
377
376
|
};
|
|
378
377
|
this.modelId = modelId;
|
|
379
378
|
this.config = config;
|
|
380
379
|
}
|
|
380
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
381
|
+
return serializeModelOptions({
|
|
382
|
+
modelId: model.modelId,
|
|
383
|
+
config: model.config
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
387
|
+
return new _GroqChatLanguageModel(options.modelId, options.config);
|
|
388
|
+
}
|
|
381
389
|
get provider() {
|
|
382
390
|
return this.config.provider;
|
|
383
391
|
}
|
|
@@ -392,14 +400,14 @@ var GroqChatLanguageModel = class {
|
|
|
392
400
|
stopSequences,
|
|
393
401
|
responseFormat,
|
|
394
402
|
seed,
|
|
395
|
-
|
|
403
|
+
reasoning,
|
|
396
404
|
tools,
|
|
397
405
|
toolChoice,
|
|
398
406
|
providerOptions
|
|
399
407
|
}) {
|
|
400
|
-
var _a, _b, _c;
|
|
408
|
+
var _a, _b, _c, _d;
|
|
401
409
|
const warnings = [];
|
|
402
|
-
const groqOptions = await
|
|
410
|
+
const groqOptions = await parseProviderOptions({
|
|
403
411
|
provider: "groq",
|
|
404
412
|
providerOptions,
|
|
405
413
|
schema: groqLanguageModelOptions
|
|
@@ -448,7 +456,17 @@ var GroqChatLanguageModel = class {
|
|
|
448
456
|
} : { type: "json_object" } : void 0,
|
|
449
457
|
// provider options:
|
|
450
458
|
reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
|
|
451
|
-
reasoning_effort: groqOptions == null ? void 0 : groqOptions.reasoningEffort
|
|
459
|
+
reasoning_effort: (_d = groqOptions == null ? void 0 : groqOptions.reasoningEffort) != null ? _d : isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
|
|
460
|
+
reasoning,
|
|
461
|
+
effortMap: {
|
|
462
|
+
minimal: "low",
|
|
463
|
+
low: "low",
|
|
464
|
+
medium: "medium",
|
|
465
|
+
high: "high",
|
|
466
|
+
xhigh: "high"
|
|
467
|
+
},
|
|
468
|
+
warnings
|
|
469
|
+
}) : void 0,
|
|
452
470
|
service_tier: groqOptions == null ? void 0 : groqOptions.serviceTier,
|
|
453
471
|
// messages:
|
|
454
472
|
messages: convertToGroqChatMessages(prompt),
|
|
@@ -460,25 +478,22 @@ var GroqChatLanguageModel = class {
|
|
|
460
478
|
};
|
|
461
479
|
}
|
|
462
480
|
async doGenerate(options) {
|
|
463
|
-
var _a, _b;
|
|
464
|
-
const { args, warnings } = await this.getArgs(
|
|
465
|
-
...options,
|
|
466
|
-
stream: false
|
|
467
|
-
});
|
|
481
|
+
var _a, _b, _c, _d;
|
|
482
|
+
const { args, warnings } = await this.getArgs(options);
|
|
468
483
|
const body = JSON.stringify(args);
|
|
469
484
|
const {
|
|
470
485
|
responseHeaders,
|
|
471
486
|
value: response,
|
|
472
487
|
rawValue: rawResponse
|
|
473
|
-
} = await
|
|
488
|
+
} = await postJsonToApi({
|
|
474
489
|
url: this.config.url({
|
|
475
490
|
path: "/chat/completions",
|
|
476
491
|
modelId: this.modelId
|
|
477
492
|
}),
|
|
478
|
-
headers: (
|
|
493
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
479
494
|
body: args,
|
|
480
495
|
failedResponseHandler: groqFailedResponseHandler,
|
|
481
|
-
successfulResponseHandler:
|
|
496
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
482
497
|
groqChatResponseSchema
|
|
483
498
|
),
|
|
484
499
|
abortSignal: options.abortSignal,
|
|
@@ -501,7 +516,7 @@ var GroqChatLanguageModel = class {
|
|
|
501
516
|
for (const toolCall of choice.message.tool_calls) {
|
|
502
517
|
content.push({
|
|
503
518
|
type: "tool-call",
|
|
504
|
-
toolCallId: (
|
|
519
|
+
toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
|
|
505
520
|
toolName: toolCall.function.name,
|
|
506
521
|
input: toolCall.function.arguments
|
|
507
522
|
});
|
|
@@ -511,7 +526,7 @@ var GroqChatLanguageModel = class {
|
|
|
511
526
|
content,
|
|
512
527
|
finishReason: {
|
|
513
528
|
unified: mapGroqFinishReason(choice.finish_reason),
|
|
514
|
-
raw: (
|
|
529
|
+
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
515
530
|
},
|
|
516
531
|
usage: convertGroqUsage(response.usage),
|
|
517
532
|
response: {
|
|
@@ -524,24 +539,25 @@ var GroqChatLanguageModel = class {
|
|
|
524
539
|
};
|
|
525
540
|
}
|
|
526
541
|
async doStream(options) {
|
|
527
|
-
|
|
528
|
-
const
|
|
529
|
-
const {
|
|
542
|
+
var _a, _b;
|
|
543
|
+
const { args, warnings } = await this.getArgs(options);
|
|
544
|
+
const body = { ...args, stream: true };
|
|
545
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
530
546
|
url: this.config.url({
|
|
531
547
|
path: "/chat/completions",
|
|
532
548
|
modelId: this.modelId
|
|
533
549
|
}),
|
|
534
|
-
headers: (
|
|
535
|
-
body
|
|
536
|
-
...args,
|
|
537
|
-
stream: true
|
|
538
|
-
},
|
|
550
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
551
|
+
body,
|
|
539
552
|
failedResponseHandler: groqFailedResponseHandler,
|
|
540
|
-
successfulResponseHandler:
|
|
553
|
+
successfulResponseHandler: createEventSourceResponseHandler(groqChatChunkSchema),
|
|
541
554
|
abortSignal: options.abortSignal,
|
|
542
555
|
fetch: this.config.fetch
|
|
543
556
|
});
|
|
544
|
-
const
|
|
557
|
+
const toolCallTracker = new StreamingToolCallTracker({
|
|
558
|
+
generateId,
|
|
559
|
+
typeValidation: "required"
|
|
560
|
+
});
|
|
545
561
|
let finishReason = {
|
|
546
562
|
unified: "other",
|
|
547
563
|
raw: void 0
|
|
@@ -558,7 +574,7 @@ var GroqChatLanguageModel = class {
|
|
|
558
574
|
controller.enqueue({ type: "stream-start", warnings });
|
|
559
575
|
},
|
|
560
576
|
transform(chunk, controller) {
|
|
561
|
-
var
|
|
577
|
+
var _a2;
|
|
562
578
|
if (options.includeRawChunks) {
|
|
563
579
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
564
580
|
}
|
|
@@ -586,7 +602,7 @@ var GroqChatLanguageModel = class {
|
|
|
586
602
|
...getResponseMetadata(value)
|
|
587
603
|
});
|
|
588
604
|
}
|
|
589
|
-
if (((
|
|
605
|
+
if (((_a2 = value.x_groq) == null ? void 0 : _a2.usage) != null) {
|
|
590
606
|
usage = value.x_groq.usage;
|
|
591
607
|
}
|
|
592
608
|
const choice = value.choices[0];
|
|
@@ -641,90 +657,10 @@ var GroqChatLanguageModel = class {
|
|
|
641
657
|
isActiveReasoning = false;
|
|
642
658
|
}
|
|
643
659
|
for (const toolCallDelta of delta.tool_calls) {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
data: toolCallDelta,
|
|
649
|
-
message: `Expected 'function' type.`
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
if (toolCallDelta.id == null) {
|
|
653
|
-
throw new import_provider3.InvalidResponseDataError({
|
|
654
|
-
data: toolCallDelta,
|
|
655
|
-
message: `Expected 'id' to be a string.`
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
|
|
659
|
-
throw new import_provider3.InvalidResponseDataError({
|
|
660
|
-
data: toolCallDelta,
|
|
661
|
-
message: `Expected 'function.name' to be a string.`
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
controller.enqueue({
|
|
665
|
-
type: "tool-input-start",
|
|
666
|
-
id: toolCallDelta.id,
|
|
667
|
-
toolName: toolCallDelta.function.name
|
|
668
|
-
});
|
|
669
|
-
toolCalls[index] = {
|
|
670
|
-
id: toolCallDelta.id,
|
|
671
|
-
type: "function",
|
|
672
|
-
function: {
|
|
673
|
-
name: toolCallDelta.function.name,
|
|
674
|
-
arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
|
|
675
|
-
},
|
|
676
|
-
hasFinished: false
|
|
677
|
-
};
|
|
678
|
-
const toolCall2 = toolCalls[index];
|
|
679
|
-
if (((_d = toolCall2.function) == null ? void 0 : _d.name) != null && ((_e = toolCall2.function) == null ? void 0 : _e.arguments) != null) {
|
|
680
|
-
if (toolCall2.function.arguments.length > 0) {
|
|
681
|
-
controller.enqueue({
|
|
682
|
-
type: "tool-input-delta",
|
|
683
|
-
id: toolCall2.id,
|
|
684
|
-
delta: toolCall2.function.arguments
|
|
685
|
-
});
|
|
686
|
-
}
|
|
687
|
-
if ((0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) {
|
|
688
|
-
controller.enqueue({
|
|
689
|
-
type: "tool-input-end",
|
|
690
|
-
id: toolCall2.id
|
|
691
|
-
});
|
|
692
|
-
controller.enqueue({
|
|
693
|
-
type: "tool-call",
|
|
694
|
-
toolCallId: (_f = toolCall2.id) != null ? _f : (0, import_provider_utils3.generateId)(),
|
|
695
|
-
toolName: toolCall2.function.name,
|
|
696
|
-
input: toolCall2.function.arguments
|
|
697
|
-
});
|
|
698
|
-
toolCall2.hasFinished = true;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
continue;
|
|
702
|
-
}
|
|
703
|
-
const toolCall = toolCalls[index];
|
|
704
|
-
if (toolCall.hasFinished) {
|
|
705
|
-
continue;
|
|
706
|
-
}
|
|
707
|
-
if (((_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null) {
|
|
708
|
-
toolCall.function.arguments += (_i = (_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null ? _i : "";
|
|
709
|
-
}
|
|
710
|
-
controller.enqueue({
|
|
711
|
-
type: "tool-input-delta",
|
|
712
|
-
id: toolCall.id,
|
|
713
|
-
delta: (_j = toolCallDelta.function.arguments) != null ? _j : ""
|
|
714
|
-
});
|
|
715
|
-
if (((_k = toolCall.function) == null ? void 0 : _k.name) != null && ((_l = toolCall.function) == null ? void 0 : _l.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) {
|
|
716
|
-
controller.enqueue({
|
|
717
|
-
type: "tool-input-end",
|
|
718
|
-
id: toolCall.id
|
|
719
|
-
});
|
|
720
|
-
controller.enqueue({
|
|
721
|
-
type: "tool-call",
|
|
722
|
-
toolCallId: (_m = toolCall.id) != null ? _m : (0, import_provider_utils3.generateId)(),
|
|
723
|
-
toolName: toolCall.function.name,
|
|
724
|
-
input: toolCall.function.arguments
|
|
725
|
-
});
|
|
726
|
-
toolCall.hasFinished = true;
|
|
727
|
-
}
|
|
660
|
+
toolCallTracker.processDelta(
|
|
661
|
+
toolCallDelta,
|
|
662
|
+
controller.enqueue.bind(controller)
|
|
663
|
+
);
|
|
728
664
|
}
|
|
729
665
|
}
|
|
730
666
|
},
|
|
@@ -735,6 +671,7 @@ var GroqChatLanguageModel = class {
|
|
|
735
671
|
if (isActiveText) {
|
|
736
672
|
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
737
673
|
}
|
|
674
|
+
toolCallTracker.flush(controller.enqueue.bind(controller));
|
|
738
675
|
controller.enqueue({
|
|
739
676
|
type: "finish",
|
|
740
677
|
finishReason,
|
|
@@ -744,83 +681,83 @@ var GroqChatLanguageModel = class {
|
|
|
744
681
|
}
|
|
745
682
|
})
|
|
746
683
|
),
|
|
747
|
-
request: { body },
|
|
684
|
+
request: { body: JSON.stringify(body) },
|
|
748
685
|
response: { headers: responseHeaders }
|
|
749
686
|
};
|
|
750
687
|
}
|
|
751
688
|
};
|
|
752
|
-
var groqChatResponseSchema =
|
|
753
|
-
id:
|
|
754
|
-
created:
|
|
755
|
-
model:
|
|
756
|
-
choices:
|
|
757
|
-
|
|
758
|
-
message:
|
|
759
|
-
content:
|
|
760
|
-
reasoning:
|
|
761
|
-
tool_calls:
|
|
762
|
-
|
|
763
|
-
id:
|
|
764
|
-
type:
|
|
765
|
-
function:
|
|
766
|
-
name:
|
|
767
|
-
arguments:
|
|
689
|
+
var groqChatResponseSchema = z3.object({
|
|
690
|
+
id: z3.string().nullish(),
|
|
691
|
+
created: z3.number().nullish(),
|
|
692
|
+
model: z3.string().nullish(),
|
|
693
|
+
choices: z3.array(
|
|
694
|
+
z3.object({
|
|
695
|
+
message: z3.object({
|
|
696
|
+
content: z3.string().nullish(),
|
|
697
|
+
reasoning: z3.string().nullish(),
|
|
698
|
+
tool_calls: z3.array(
|
|
699
|
+
z3.object({
|
|
700
|
+
id: z3.string().nullish(),
|
|
701
|
+
type: z3.literal("function"),
|
|
702
|
+
function: z3.object({
|
|
703
|
+
name: z3.string(),
|
|
704
|
+
arguments: z3.string()
|
|
768
705
|
})
|
|
769
706
|
})
|
|
770
707
|
).nullish()
|
|
771
708
|
}),
|
|
772
|
-
index:
|
|
773
|
-
finish_reason:
|
|
709
|
+
index: z3.number(),
|
|
710
|
+
finish_reason: z3.string().nullish()
|
|
774
711
|
})
|
|
775
712
|
),
|
|
776
|
-
usage:
|
|
777
|
-
prompt_tokens:
|
|
778
|
-
completion_tokens:
|
|
779
|
-
total_tokens:
|
|
780
|
-
prompt_tokens_details:
|
|
781
|
-
cached_tokens:
|
|
713
|
+
usage: z3.object({
|
|
714
|
+
prompt_tokens: z3.number().nullish(),
|
|
715
|
+
completion_tokens: z3.number().nullish(),
|
|
716
|
+
total_tokens: z3.number().nullish(),
|
|
717
|
+
prompt_tokens_details: z3.object({
|
|
718
|
+
cached_tokens: z3.number().nullish()
|
|
782
719
|
}).nullish(),
|
|
783
|
-
completion_tokens_details:
|
|
784
|
-
reasoning_tokens:
|
|
720
|
+
completion_tokens_details: z3.object({
|
|
721
|
+
reasoning_tokens: z3.number().nullish()
|
|
785
722
|
}).nullish()
|
|
786
723
|
}).nullish()
|
|
787
724
|
});
|
|
788
|
-
var groqChatChunkSchema =
|
|
789
|
-
|
|
790
|
-
id:
|
|
791
|
-
created:
|
|
792
|
-
model:
|
|
793
|
-
choices:
|
|
794
|
-
|
|
795
|
-
delta:
|
|
796
|
-
content:
|
|
797
|
-
reasoning:
|
|
798
|
-
tool_calls:
|
|
799
|
-
|
|
800
|
-
index:
|
|
801
|
-
id:
|
|
802
|
-
type:
|
|
803
|
-
function:
|
|
804
|
-
name:
|
|
805
|
-
arguments:
|
|
725
|
+
var groqChatChunkSchema = z3.union([
|
|
726
|
+
z3.object({
|
|
727
|
+
id: z3.string().nullish(),
|
|
728
|
+
created: z3.number().nullish(),
|
|
729
|
+
model: z3.string().nullish(),
|
|
730
|
+
choices: z3.array(
|
|
731
|
+
z3.object({
|
|
732
|
+
delta: z3.object({
|
|
733
|
+
content: z3.string().nullish(),
|
|
734
|
+
reasoning: z3.string().nullish(),
|
|
735
|
+
tool_calls: z3.array(
|
|
736
|
+
z3.object({
|
|
737
|
+
index: z3.number(),
|
|
738
|
+
id: z3.string().nullish(),
|
|
739
|
+
type: z3.literal("function").optional(),
|
|
740
|
+
function: z3.object({
|
|
741
|
+
name: z3.string().nullish(),
|
|
742
|
+
arguments: z3.string().nullish()
|
|
806
743
|
})
|
|
807
744
|
})
|
|
808
745
|
).nullish()
|
|
809
746
|
}).nullish(),
|
|
810
|
-
finish_reason:
|
|
811
|
-
index:
|
|
747
|
+
finish_reason: z3.string().nullable().optional(),
|
|
748
|
+
index: z3.number()
|
|
812
749
|
})
|
|
813
750
|
),
|
|
814
|
-
x_groq:
|
|
815
|
-
usage:
|
|
816
|
-
prompt_tokens:
|
|
817
|
-
completion_tokens:
|
|
818
|
-
total_tokens:
|
|
819
|
-
prompt_tokens_details:
|
|
820
|
-
cached_tokens:
|
|
751
|
+
x_groq: z3.object({
|
|
752
|
+
usage: z3.object({
|
|
753
|
+
prompt_tokens: z3.number().nullish(),
|
|
754
|
+
completion_tokens: z3.number().nullish(),
|
|
755
|
+
total_tokens: z3.number().nullish(),
|
|
756
|
+
prompt_tokens_details: z3.object({
|
|
757
|
+
cached_tokens: z3.number().nullish()
|
|
821
758
|
}).nullish(),
|
|
822
|
-
completion_tokens_details:
|
|
823
|
-
reasoning_tokens:
|
|
759
|
+
completion_tokens_details: z3.object({
|
|
760
|
+
reasoning_tokens: z3.number().nullish()
|
|
824
761
|
}).nullish()
|
|
825
762
|
}).nullish()
|
|
826
763
|
}).nullish()
|
|
@@ -829,34 +766,53 @@ var groqChatChunkSchema = import_v43.z.union([
|
|
|
829
766
|
]);
|
|
830
767
|
|
|
831
768
|
// src/groq-transcription-model.ts
|
|
832
|
-
|
|
833
|
-
|
|
769
|
+
import {
|
|
770
|
+
combineHeaders as combineHeaders2,
|
|
771
|
+
convertBase64ToUint8Array,
|
|
772
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
773
|
+
mediaTypeToExtension,
|
|
774
|
+
parseProviderOptions as parseProviderOptions2,
|
|
775
|
+
postFormDataToApi,
|
|
776
|
+
serializeModelOptions as serializeModelOptions2,
|
|
777
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
778
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
779
|
+
} from "@ai-sdk/provider-utils";
|
|
780
|
+
import { z as z5 } from "zod/v4";
|
|
834
781
|
|
|
835
782
|
// src/groq-transcription-options.ts
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
var groqTranscriptionModelOptions =
|
|
839
|
-
() =>
|
|
840
|
-
|
|
841
|
-
language:
|
|
842
|
-
prompt:
|
|
843
|
-
responseFormat:
|
|
844
|
-
temperature:
|
|
845
|
-
timestampGranularities:
|
|
783
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
784
|
+
import { z as z4 } from "zod/v4";
|
|
785
|
+
var groqTranscriptionModelOptions = lazySchema(
|
|
786
|
+
() => zodSchema(
|
|
787
|
+
z4.object({
|
|
788
|
+
language: z4.string().nullish(),
|
|
789
|
+
prompt: z4.string().nullish(),
|
|
790
|
+
responseFormat: z4.string().nullish(),
|
|
791
|
+
temperature: z4.number().min(0).max(1).nullish(),
|
|
792
|
+
timestampGranularities: z4.array(z4.string()).nullish()
|
|
846
793
|
})
|
|
847
794
|
)
|
|
848
795
|
);
|
|
849
796
|
|
|
850
797
|
// src/groq-transcription-model.ts
|
|
851
|
-
var GroqTranscriptionModel = class {
|
|
798
|
+
var GroqTranscriptionModel = class _GroqTranscriptionModel {
|
|
852
799
|
constructor(modelId, config) {
|
|
853
800
|
this.modelId = modelId;
|
|
854
801
|
this.config = config;
|
|
855
|
-
this.specificationVersion = "
|
|
802
|
+
this.specificationVersion = "v4";
|
|
856
803
|
}
|
|
857
804
|
get provider() {
|
|
858
805
|
return this.config.provider;
|
|
859
806
|
}
|
|
807
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
808
|
+
return serializeModelOptions2({
|
|
809
|
+
modelId: model.modelId,
|
|
810
|
+
config: model.config
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
814
|
+
return new _GroqTranscriptionModel(options.modelId, options.config);
|
|
815
|
+
}
|
|
860
816
|
async getArgs({
|
|
861
817
|
audio,
|
|
862
818
|
mediaType,
|
|
@@ -864,15 +820,15 @@ var GroqTranscriptionModel = class {
|
|
|
864
820
|
}) {
|
|
865
821
|
var _a, _b, _c, _d, _e;
|
|
866
822
|
const warnings = [];
|
|
867
|
-
const groqOptions = await (
|
|
823
|
+
const groqOptions = await parseProviderOptions2({
|
|
868
824
|
provider: "groq",
|
|
869
825
|
providerOptions,
|
|
870
826
|
schema: groqTranscriptionModelOptions
|
|
871
827
|
});
|
|
872
828
|
const formData = new FormData();
|
|
873
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([
|
|
829
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
874
830
|
formData.append("model", this.modelId);
|
|
875
|
-
const fileExtension =
|
|
831
|
+
const fileExtension = mediaTypeToExtension(mediaType);
|
|
876
832
|
formData.append(
|
|
877
833
|
"file",
|
|
878
834
|
new File([blob], "audio", { type: mediaType }),
|
|
@@ -905,22 +861,22 @@ var GroqTranscriptionModel = class {
|
|
|
905
861
|
};
|
|
906
862
|
}
|
|
907
863
|
async doGenerate(options) {
|
|
908
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
864
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
909
865
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
910
866
|
const { formData, warnings } = await this.getArgs(options);
|
|
911
867
|
const {
|
|
912
868
|
value: response,
|
|
913
869
|
responseHeaders,
|
|
914
870
|
rawValue: rawResponse
|
|
915
|
-
} = await
|
|
871
|
+
} = await postFormDataToApi({
|
|
916
872
|
url: this.config.url({
|
|
917
873
|
path: "/audio/transcriptions",
|
|
918
874
|
modelId: this.modelId
|
|
919
875
|
}),
|
|
920
|
-
headers: (
|
|
876
|
+
headers: combineHeaders2((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
|
|
921
877
|
formData,
|
|
922
878
|
failedResponseHandler: groqFailedResponseHandler,
|
|
923
|
-
successfulResponseHandler: (
|
|
879
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
924
880
|
groqTranscriptionResponseSchema
|
|
925
881
|
),
|
|
926
882
|
abortSignal: options.abortSignal,
|
|
@@ -928,13 +884,13 @@ var GroqTranscriptionModel = class {
|
|
|
928
884
|
});
|
|
929
885
|
return {
|
|
930
886
|
text: response.text,
|
|
931
|
-
segments: (
|
|
887
|
+
segments: (_g = (_f = response.segments) == null ? void 0 : _f.map((segment) => ({
|
|
932
888
|
text: segment.text,
|
|
933
889
|
startSecond: segment.start,
|
|
934
890
|
endSecond: segment.end
|
|
935
|
-
}))) != null ?
|
|
936
|
-
language: (
|
|
937
|
-
durationInSeconds: (
|
|
891
|
+
}))) != null ? _g : [],
|
|
892
|
+
language: (_h = response.language) != null ? _h : void 0,
|
|
893
|
+
durationInSeconds: (_i = response.duration) != null ? _i : void 0,
|
|
938
894
|
warnings,
|
|
939
895
|
response: {
|
|
940
896
|
timestamp: currentDate,
|
|
@@ -945,37 +901,37 @@ var GroqTranscriptionModel = class {
|
|
|
945
901
|
};
|
|
946
902
|
}
|
|
947
903
|
};
|
|
948
|
-
var groqTranscriptionResponseSchema =
|
|
949
|
-
text:
|
|
950
|
-
x_groq:
|
|
951
|
-
id:
|
|
904
|
+
var groqTranscriptionResponseSchema = z5.object({
|
|
905
|
+
text: z5.string(),
|
|
906
|
+
x_groq: z5.object({
|
|
907
|
+
id: z5.string()
|
|
952
908
|
}),
|
|
953
909
|
// additional properties are returned when `response_format: 'verbose_json'` is
|
|
954
|
-
task:
|
|
955
|
-
language:
|
|
956
|
-
duration:
|
|
957
|
-
segments:
|
|
958
|
-
|
|
959
|
-
id:
|
|
960
|
-
seek:
|
|
961
|
-
start:
|
|
962
|
-
end:
|
|
963
|
-
text:
|
|
964
|
-
tokens:
|
|
965
|
-
temperature:
|
|
966
|
-
avg_logprob:
|
|
967
|
-
compression_ratio:
|
|
968
|
-
no_speech_prob:
|
|
910
|
+
task: z5.string().nullish(),
|
|
911
|
+
language: z5.string().nullish(),
|
|
912
|
+
duration: z5.number().nullish(),
|
|
913
|
+
segments: z5.array(
|
|
914
|
+
z5.object({
|
|
915
|
+
id: z5.number(),
|
|
916
|
+
seek: z5.number(),
|
|
917
|
+
start: z5.number(),
|
|
918
|
+
end: z5.number(),
|
|
919
|
+
text: z5.string(),
|
|
920
|
+
tokens: z5.array(z5.number()),
|
|
921
|
+
temperature: z5.number(),
|
|
922
|
+
avg_logprob: z5.number(),
|
|
923
|
+
compression_ratio: z5.number(),
|
|
924
|
+
no_speech_prob: z5.number()
|
|
969
925
|
})
|
|
970
926
|
).nullish()
|
|
971
927
|
});
|
|
972
928
|
|
|
973
929
|
// src/tool/browser-search.ts
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
var browserSearch =
|
|
930
|
+
import { createProviderToolFactory } from "@ai-sdk/provider-utils";
|
|
931
|
+
import { z as z6 } from "zod/v4";
|
|
932
|
+
var browserSearch = createProviderToolFactory({
|
|
977
933
|
id: "groq.browser_search",
|
|
978
|
-
inputSchema:
|
|
934
|
+
inputSchema: z6.object({})
|
|
979
935
|
});
|
|
980
936
|
|
|
981
937
|
// src/groq-tools.ts
|
|
@@ -984,15 +940,15 @@ var groqTools = {
|
|
|
984
940
|
};
|
|
985
941
|
|
|
986
942
|
// src/version.ts
|
|
987
|
-
var VERSION = true ? "4.0.0-beta.
|
|
943
|
+
var VERSION = true ? "4.0.0-beta.30" : "0.0.0-test";
|
|
988
944
|
|
|
989
945
|
// src/groq-provider.ts
|
|
990
946
|
function createGroq(options = {}) {
|
|
991
947
|
var _a;
|
|
992
|
-
const baseURL = (_a =
|
|
993
|
-
const getHeaders = () =>
|
|
948
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
|
|
949
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
994
950
|
{
|
|
995
|
-
Authorization: `Bearer ${
|
|
951
|
+
Authorization: `Bearer ${loadApiKey({
|
|
996
952
|
apiKey: options.apiKey,
|
|
997
953
|
environmentVariableName: "GROQ_API_KEY",
|
|
998
954
|
description: "Groq"
|
|
@@ -1026,15 +982,15 @@ function createGroq(options = {}) {
|
|
|
1026
982
|
const provider = function(modelId) {
|
|
1027
983
|
return createLanguageModel(modelId);
|
|
1028
984
|
};
|
|
1029
|
-
provider.specificationVersion = "
|
|
985
|
+
provider.specificationVersion = "v4";
|
|
1030
986
|
provider.languageModel = createLanguageModel;
|
|
1031
987
|
provider.chat = createChatModel;
|
|
1032
988
|
provider.embeddingModel = (modelId) => {
|
|
1033
|
-
throw new
|
|
989
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
1034
990
|
};
|
|
1035
991
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
1036
992
|
provider.imageModel = (modelId) => {
|
|
1037
|
-
throw new
|
|
993
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1038
994
|
};
|
|
1039
995
|
provider.transcription = createTranscriptionModel;
|
|
1040
996
|
provider.transcriptionModel = createTranscriptionModel;
|
|
@@ -1042,11 +998,10 @@ function createGroq(options = {}) {
|
|
|
1042
998
|
return provider;
|
|
1043
999
|
}
|
|
1044
1000
|
var groq = createGroq();
|
|
1045
|
-
|
|
1046
|
-
0 && (module.exports = {
|
|
1001
|
+
export {
|
|
1047
1002
|
VERSION,
|
|
1048
1003
|
browserSearch,
|
|
1049
1004
|
createGroq,
|
|
1050
1005
|
groq
|
|
1051
|
-
}
|
|
1006
|
+
};
|
|
1052
1007
|
//# sourceMappingURL=index.js.map
|