@ai-sdk/groq 4.0.0-beta.4 → 4.0.0-beta.54
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 +413 -4
- package/README.md +3 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.js +269 -295
- package/dist/index.js.map +1 -1
- package/docs/09-groq.mdx +15 -14
- package/package.json +14 -14
- package/src/convert-groq-usage.ts +2 -2
- package/src/convert-to-groq-chat-messages.ts +38 -22
- package/src/groq-browser-search-models.ts +1 -1
- package/src/{groq-chat-options.ts → groq-chat-language-model-options.ts} +6 -3
- package/src/groq-chat-language-model.ts +82 -170
- package/src/groq-config.ts +2 -2
- package/src/groq-prepare-tools.ts +7 -7
- package/src/groq-provider.ts +11 -11
- package/src/{groq-transcription-options.ts → groq-transcription-model-options.ts} +5 -1
- package/src/groq-transcription-model.ts +29 -12
- package/src/index.ts +7 -5
- package/src/map-groq-finish-reason.ts +2 -2
- package/src/tool/browser-search.ts +11 -3
- 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,14 @@ 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 {
|
|
72
|
+
convertToBase64,
|
|
73
|
+
getTopLevelMediaType,
|
|
74
|
+
resolveFullMediaType
|
|
75
|
+
} from "@ai-sdk/provider-utils";
|
|
81
76
|
function convertToGroqChatMessages(prompt) {
|
|
82
77
|
var _a;
|
|
83
78
|
const messages = [];
|
|
@@ -100,18 +95,32 @@ function convertToGroqChatMessages(prompt) {
|
|
|
100
95
|
return { type: "text", text: part.text };
|
|
101
96
|
}
|
|
102
97
|
case "file": {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
98
|
+
switch (part.data.type) {
|
|
99
|
+
case "reference": {
|
|
100
|
+
throw new UnsupportedFunctionalityError({
|
|
101
|
+
functionality: "file parts with provider references"
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
case "text": {
|
|
105
|
+
throw new UnsupportedFunctionalityError({
|
|
106
|
+
functionality: "text file parts"
|
|
107
|
+
});
|
|
113
108
|
}
|
|
114
|
-
|
|
109
|
+
case "url":
|
|
110
|
+
case "data": {
|
|
111
|
+
if (getTopLevelMediaType(part.mediaType) !== "image") {
|
|
112
|
+
throw new UnsupportedFunctionalityError({
|
|
113
|
+
functionality: "Non-image file content parts"
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
type: "image_url",
|
|
118
|
+
image_url: {
|
|
119
|
+
url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
115
124
|
}
|
|
116
125
|
}
|
|
117
126
|
})
|
|
@@ -168,7 +177,7 @@ function convertToGroqChatMessages(prompt) {
|
|
|
168
177
|
contentValue = output.value;
|
|
169
178
|
break;
|
|
170
179
|
case "execution-denied":
|
|
171
|
-
contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
|
|
180
|
+
contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
|
|
172
181
|
break;
|
|
173
182
|
case "content":
|
|
174
183
|
case "json":
|
|
@@ -206,30 +215,30 @@ function getResponseMetadata({
|
|
|
206
215
|
};
|
|
207
216
|
}
|
|
208
217
|
|
|
209
|
-
// src/groq-chat-options.ts
|
|
210
|
-
|
|
211
|
-
var
|
|
212
|
-
reasoningFormat:
|
|
218
|
+
// src/groq-chat-language-model-options.ts
|
|
219
|
+
import { z } from "zod/v4";
|
|
220
|
+
var groqLanguageModelChatOptions = z.object({
|
|
221
|
+
reasoningFormat: z.enum(["parsed", "raw", "hidden"]).optional(),
|
|
213
222
|
/**
|
|
214
223
|
* Specifies the reasoning effort level for model inference.
|
|
215
224
|
* @see https://console.groq.com/docs/reasoning#reasoning-effort
|
|
216
225
|
*/
|
|
217
|
-
reasoningEffort:
|
|
226
|
+
reasoningEffort: z.enum(["none", "default", "low", "medium", "high"]).optional(),
|
|
218
227
|
/**
|
|
219
228
|
* Whether to enable parallel function calling during tool use. Default to true.
|
|
220
229
|
*/
|
|
221
|
-
parallelToolCalls:
|
|
230
|
+
parallelToolCalls: z.boolean().optional(),
|
|
222
231
|
/**
|
|
223
232
|
* A unique identifier representing your end-user, which can help OpenAI to
|
|
224
233
|
* monitor and detect abuse. Learn more.
|
|
225
234
|
*/
|
|
226
|
-
user:
|
|
235
|
+
user: z.string().optional(),
|
|
227
236
|
/**
|
|
228
237
|
* Whether to use structured outputs.
|
|
229
238
|
*
|
|
230
239
|
* @default true
|
|
231
240
|
*/
|
|
232
|
-
structuredOutputs:
|
|
241
|
+
structuredOutputs: z.boolean().optional(),
|
|
233
242
|
/**
|
|
234
243
|
* Whether to use strict JSON schema validation.
|
|
235
244
|
* When true, the model uses constrained decoding to guarantee schema compliance.
|
|
@@ -237,34 +246,37 @@ var groqLanguageModelOptions = import_v4.z.object({
|
|
|
237
246
|
*
|
|
238
247
|
* @default true
|
|
239
248
|
*/
|
|
240
|
-
strictJsonSchema:
|
|
249
|
+
strictJsonSchema: z.boolean().optional(),
|
|
241
250
|
/**
|
|
242
251
|
* Service tier for the request.
|
|
243
252
|
* - 'on_demand': Default tier with consistent performance and fairness
|
|
253
|
+
* - 'performance': Prioritized tier for latency-sensitive workloads
|
|
244
254
|
* - 'flex': Higher throughput tier optimized for workloads that can handle occasional request failures
|
|
245
255
|
* - 'auto': Uses on_demand rate limits, then falls back to flex tier if exceeded
|
|
246
256
|
*
|
|
247
257
|
* @default 'on_demand'
|
|
248
258
|
*/
|
|
249
|
-
serviceTier:
|
|
259
|
+
serviceTier: z.enum(["on_demand", "performance", "flex", "auto"]).optional()
|
|
250
260
|
});
|
|
251
261
|
|
|
252
262
|
// src/groq-error.ts
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
var groqErrorDataSchema =
|
|
256
|
-
error:
|
|
257
|
-
message:
|
|
258
|
-
type:
|
|
263
|
+
import { z as z2 } from "zod/v4";
|
|
264
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
265
|
+
var groqErrorDataSchema = z2.object({
|
|
266
|
+
error: z2.object({
|
|
267
|
+
message: z2.string(),
|
|
268
|
+
type: z2.string()
|
|
259
269
|
})
|
|
260
270
|
});
|
|
261
|
-
var groqFailedResponseHandler =
|
|
271
|
+
var groqFailedResponseHandler = createJsonErrorResponseHandler({
|
|
262
272
|
errorSchema: groqErrorDataSchema,
|
|
263
273
|
errorToMessage: (data) => data.error.message
|
|
264
274
|
});
|
|
265
275
|
|
|
266
276
|
// src/groq-prepare-tools.ts
|
|
267
|
-
|
|
277
|
+
import {
|
|
278
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
279
|
+
} from "@ai-sdk/provider";
|
|
268
280
|
|
|
269
281
|
// src/groq-browser-search-models.ts
|
|
270
282
|
var BROWSER_SEARCH_SUPPORTED_MODELS = [
|
|
@@ -344,7 +356,7 @@ function prepareTools({
|
|
|
344
356
|
};
|
|
345
357
|
default: {
|
|
346
358
|
const _exhaustiveCheck = type;
|
|
347
|
-
throw new
|
|
359
|
+
throw new UnsupportedFunctionalityError2({
|
|
348
360
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
349
361
|
});
|
|
350
362
|
}
|
|
@@ -369,15 +381,24 @@ function mapGroqFinishReason(finishReason) {
|
|
|
369
381
|
}
|
|
370
382
|
|
|
371
383
|
// src/groq-chat-language-model.ts
|
|
372
|
-
var GroqChatLanguageModel = class {
|
|
384
|
+
var GroqChatLanguageModel = class _GroqChatLanguageModel {
|
|
373
385
|
constructor(modelId, config) {
|
|
374
|
-
this.specificationVersion = "
|
|
386
|
+
this.specificationVersion = "v4";
|
|
375
387
|
this.supportedUrls = {
|
|
376
388
|
"image/*": [/^https?:\/\/.*$/]
|
|
377
389
|
};
|
|
378
390
|
this.modelId = modelId;
|
|
379
391
|
this.config = config;
|
|
380
392
|
}
|
|
393
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
394
|
+
return serializeModelOptions({
|
|
395
|
+
modelId: model.modelId,
|
|
396
|
+
config: model.config
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
400
|
+
return new _GroqChatLanguageModel(options.modelId, options.config);
|
|
401
|
+
}
|
|
381
402
|
get provider() {
|
|
382
403
|
return this.config.provider;
|
|
383
404
|
}
|
|
@@ -392,17 +413,17 @@ var GroqChatLanguageModel = class {
|
|
|
392
413
|
stopSequences,
|
|
393
414
|
responseFormat,
|
|
394
415
|
seed,
|
|
395
|
-
|
|
416
|
+
reasoning,
|
|
396
417
|
tools,
|
|
397
418
|
toolChoice,
|
|
398
419
|
providerOptions
|
|
399
420
|
}) {
|
|
400
|
-
var _a, _b, _c;
|
|
421
|
+
var _a, _b, _c, _d;
|
|
401
422
|
const warnings = [];
|
|
402
|
-
const groqOptions = await
|
|
423
|
+
const groqOptions = await parseProviderOptions({
|
|
403
424
|
provider: "groq",
|
|
404
425
|
providerOptions,
|
|
405
|
-
schema:
|
|
426
|
+
schema: groqLanguageModelChatOptions
|
|
406
427
|
});
|
|
407
428
|
const structuredOutputs = (_a = groqOptions == null ? void 0 : groqOptions.structuredOutputs) != null ? _a : true;
|
|
408
429
|
const strictJsonSchema = (_b = groqOptions == null ? void 0 : groqOptions.strictJsonSchema) != null ? _b : true;
|
|
@@ -448,7 +469,17 @@ var GroqChatLanguageModel = class {
|
|
|
448
469
|
} : { type: "json_object" } : void 0,
|
|
449
470
|
// provider options:
|
|
450
471
|
reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
|
|
451
|
-
reasoning_effort: groqOptions == null ? void 0 : groqOptions.reasoningEffort
|
|
472
|
+
reasoning_effort: (_d = groqOptions == null ? void 0 : groqOptions.reasoningEffort) != null ? _d : isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
|
|
473
|
+
reasoning,
|
|
474
|
+
effortMap: {
|
|
475
|
+
minimal: "low",
|
|
476
|
+
low: "low",
|
|
477
|
+
medium: "medium",
|
|
478
|
+
high: "high",
|
|
479
|
+
xhigh: "high"
|
|
480
|
+
},
|
|
481
|
+
warnings
|
|
482
|
+
}) : void 0,
|
|
452
483
|
service_tier: groqOptions == null ? void 0 : groqOptions.serviceTier,
|
|
453
484
|
// messages:
|
|
454
485
|
messages: convertToGroqChatMessages(prompt),
|
|
@@ -460,25 +491,22 @@ var GroqChatLanguageModel = class {
|
|
|
460
491
|
};
|
|
461
492
|
}
|
|
462
493
|
async doGenerate(options) {
|
|
463
|
-
var _a, _b;
|
|
464
|
-
const { args, warnings } = await this.getArgs(
|
|
465
|
-
...options,
|
|
466
|
-
stream: false
|
|
467
|
-
});
|
|
494
|
+
var _a, _b, _c, _d;
|
|
495
|
+
const { args, warnings } = await this.getArgs(options);
|
|
468
496
|
const body = JSON.stringify(args);
|
|
469
497
|
const {
|
|
470
498
|
responseHeaders,
|
|
471
499
|
value: response,
|
|
472
500
|
rawValue: rawResponse
|
|
473
|
-
} = await
|
|
501
|
+
} = await postJsonToApi({
|
|
474
502
|
url: this.config.url({
|
|
475
503
|
path: "/chat/completions",
|
|
476
504
|
modelId: this.modelId
|
|
477
505
|
}),
|
|
478
|
-
headers: (
|
|
506
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
479
507
|
body: args,
|
|
480
508
|
failedResponseHandler: groqFailedResponseHandler,
|
|
481
|
-
successfulResponseHandler:
|
|
509
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
482
510
|
groqChatResponseSchema
|
|
483
511
|
),
|
|
484
512
|
abortSignal: options.abortSignal,
|
|
@@ -501,7 +529,7 @@ var GroqChatLanguageModel = class {
|
|
|
501
529
|
for (const toolCall of choice.message.tool_calls) {
|
|
502
530
|
content.push({
|
|
503
531
|
type: "tool-call",
|
|
504
|
-
toolCallId: (
|
|
532
|
+
toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
|
|
505
533
|
toolName: toolCall.function.name,
|
|
506
534
|
input: toolCall.function.arguments
|
|
507
535
|
});
|
|
@@ -511,7 +539,7 @@ var GroqChatLanguageModel = class {
|
|
|
511
539
|
content,
|
|
512
540
|
finishReason: {
|
|
513
541
|
unified: mapGroqFinishReason(choice.finish_reason),
|
|
514
|
-
raw: (
|
|
542
|
+
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
515
543
|
},
|
|
516
544
|
usage: convertGroqUsage(response.usage),
|
|
517
545
|
response: {
|
|
@@ -524,24 +552,22 @@ var GroqChatLanguageModel = class {
|
|
|
524
552
|
};
|
|
525
553
|
}
|
|
526
554
|
async doStream(options) {
|
|
527
|
-
|
|
528
|
-
const
|
|
529
|
-
const {
|
|
555
|
+
var _a, _b;
|
|
556
|
+
const { args, warnings } = await this.getArgs(options);
|
|
557
|
+
const body = { ...args, stream: true };
|
|
558
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
530
559
|
url: this.config.url({
|
|
531
560
|
path: "/chat/completions",
|
|
532
561
|
modelId: this.modelId
|
|
533
562
|
}),
|
|
534
|
-
headers: (
|
|
535
|
-
body
|
|
536
|
-
...args,
|
|
537
|
-
stream: true
|
|
538
|
-
},
|
|
563
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
564
|
+
body,
|
|
539
565
|
failedResponseHandler: groqFailedResponseHandler,
|
|
540
|
-
successfulResponseHandler:
|
|
566
|
+
successfulResponseHandler: createEventSourceResponseHandler(groqChatChunkSchema),
|
|
541
567
|
abortSignal: options.abortSignal,
|
|
542
568
|
fetch: this.config.fetch
|
|
543
569
|
});
|
|
544
|
-
|
|
570
|
+
let toolCallTracker;
|
|
545
571
|
let finishReason = {
|
|
546
572
|
unified: "other",
|
|
547
573
|
raw: void 0
|
|
@@ -555,10 +581,14 @@ var GroqChatLanguageModel = class {
|
|
|
555
581
|
stream: response.pipeThrough(
|
|
556
582
|
new TransformStream({
|
|
557
583
|
start(controller) {
|
|
584
|
+
toolCallTracker = new StreamingToolCallTracker(controller, {
|
|
585
|
+
generateId,
|
|
586
|
+
typeValidation: "required"
|
|
587
|
+
});
|
|
558
588
|
controller.enqueue({ type: "stream-start", warnings });
|
|
559
589
|
},
|
|
560
590
|
transform(chunk, controller) {
|
|
561
|
-
var
|
|
591
|
+
var _a2;
|
|
562
592
|
if (options.includeRawChunks) {
|
|
563
593
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
564
594
|
}
|
|
@@ -586,7 +616,7 @@ var GroqChatLanguageModel = class {
|
|
|
586
616
|
...getResponseMetadata(value)
|
|
587
617
|
});
|
|
588
618
|
}
|
|
589
|
-
if (((
|
|
619
|
+
if (((_a2 = value.x_groq) == null ? void 0 : _a2.usage) != null) {
|
|
590
620
|
usage = value.x_groq.usage;
|
|
591
621
|
}
|
|
592
622
|
const choice = value.choices[0];
|
|
@@ -641,90 +671,7 @@ var GroqChatLanguageModel = class {
|
|
|
641
671
|
isActiveReasoning = false;
|
|
642
672
|
}
|
|
643
673
|
for (const toolCallDelta of delta.tool_calls) {
|
|
644
|
-
|
|
645
|
-
if (toolCalls[index] == null) {
|
|
646
|
-
if (toolCallDelta.type !== "function") {
|
|
647
|
-
throw new import_provider3.InvalidResponseDataError({
|
|
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
|
-
}
|
|
674
|
+
toolCallTracker.processDelta(toolCallDelta);
|
|
728
675
|
}
|
|
729
676
|
}
|
|
730
677
|
},
|
|
@@ -735,6 +682,7 @@ var GroqChatLanguageModel = class {
|
|
|
735
682
|
if (isActiveText) {
|
|
736
683
|
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
737
684
|
}
|
|
685
|
+
toolCallTracker.flush();
|
|
738
686
|
controller.enqueue({
|
|
739
687
|
type: "finish",
|
|
740
688
|
finishReason,
|
|
@@ -744,83 +692,83 @@ var GroqChatLanguageModel = class {
|
|
|
744
692
|
}
|
|
745
693
|
})
|
|
746
694
|
),
|
|
747
|
-
request: { body },
|
|
695
|
+
request: { body: JSON.stringify(body) },
|
|
748
696
|
response: { headers: responseHeaders }
|
|
749
697
|
};
|
|
750
698
|
}
|
|
751
699
|
};
|
|
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:
|
|
700
|
+
var groqChatResponseSchema = z3.object({
|
|
701
|
+
id: z3.string().nullish(),
|
|
702
|
+
created: z3.number().nullish(),
|
|
703
|
+
model: z3.string().nullish(),
|
|
704
|
+
choices: z3.array(
|
|
705
|
+
z3.object({
|
|
706
|
+
message: z3.object({
|
|
707
|
+
content: z3.string().nullish(),
|
|
708
|
+
reasoning: z3.string().nullish(),
|
|
709
|
+
tool_calls: z3.array(
|
|
710
|
+
z3.object({
|
|
711
|
+
id: z3.string().nullish(),
|
|
712
|
+
type: z3.literal("function"),
|
|
713
|
+
function: z3.object({
|
|
714
|
+
name: z3.string(),
|
|
715
|
+
arguments: z3.string()
|
|
768
716
|
})
|
|
769
717
|
})
|
|
770
718
|
).nullish()
|
|
771
719
|
}),
|
|
772
|
-
index:
|
|
773
|
-
finish_reason:
|
|
720
|
+
index: z3.number(),
|
|
721
|
+
finish_reason: z3.string().nullish()
|
|
774
722
|
})
|
|
775
723
|
),
|
|
776
|
-
usage:
|
|
777
|
-
prompt_tokens:
|
|
778
|
-
completion_tokens:
|
|
779
|
-
total_tokens:
|
|
780
|
-
prompt_tokens_details:
|
|
781
|
-
cached_tokens:
|
|
724
|
+
usage: z3.object({
|
|
725
|
+
prompt_tokens: z3.number().nullish(),
|
|
726
|
+
completion_tokens: z3.number().nullish(),
|
|
727
|
+
total_tokens: z3.number().nullish(),
|
|
728
|
+
prompt_tokens_details: z3.object({
|
|
729
|
+
cached_tokens: z3.number().nullish()
|
|
782
730
|
}).nullish(),
|
|
783
|
-
completion_tokens_details:
|
|
784
|
-
reasoning_tokens:
|
|
731
|
+
completion_tokens_details: z3.object({
|
|
732
|
+
reasoning_tokens: z3.number().nullish()
|
|
785
733
|
}).nullish()
|
|
786
734
|
}).nullish()
|
|
787
735
|
});
|
|
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:
|
|
736
|
+
var groqChatChunkSchema = z3.union([
|
|
737
|
+
z3.object({
|
|
738
|
+
id: z3.string().nullish(),
|
|
739
|
+
created: z3.number().nullish(),
|
|
740
|
+
model: z3.string().nullish(),
|
|
741
|
+
choices: z3.array(
|
|
742
|
+
z3.object({
|
|
743
|
+
delta: z3.object({
|
|
744
|
+
content: z3.string().nullish(),
|
|
745
|
+
reasoning: z3.string().nullish(),
|
|
746
|
+
tool_calls: z3.array(
|
|
747
|
+
z3.object({
|
|
748
|
+
index: z3.number(),
|
|
749
|
+
id: z3.string().nullish(),
|
|
750
|
+
type: z3.literal("function").optional(),
|
|
751
|
+
function: z3.object({
|
|
752
|
+
name: z3.string().nullish(),
|
|
753
|
+
arguments: z3.string().nullish()
|
|
806
754
|
})
|
|
807
755
|
})
|
|
808
756
|
).nullish()
|
|
809
757
|
}).nullish(),
|
|
810
|
-
finish_reason:
|
|
811
|
-
index:
|
|
758
|
+
finish_reason: z3.string().nullable().optional(),
|
|
759
|
+
index: z3.number()
|
|
812
760
|
})
|
|
813
761
|
),
|
|
814
|
-
x_groq:
|
|
815
|
-
usage:
|
|
816
|
-
prompt_tokens:
|
|
817
|
-
completion_tokens:
|
|
818
|
-
total_tokens:
|
|
819
|
-
prompt_tokens_details:
|
|
820
|
-
cached_tokens:
|
|
762
|
+
x_groq: z3.object({
|
|
763
|
+
usage: z3.object({
|
|
764
|
+
prompt_tokens: z3.number().nullish(),
|
|
765
|
+
completion_tokens: z3.number().nullish(),
|
|
766
|
+
total_tokens: z3.number().nullish(),
|
|
767
|
+
prompt_tokens_details: z3.object({
|
|
768
|
+
cached_tokens: z3.number().nullish()
|
|
821
769
|
}).nullish(),
|
|
822
|
-
completion_tokens_details:
|
|
823
|
-
reasoning_tokens:
|
|
770
|
+
completion_tokens_details: z3.object({
|
|
771
|
+
reasoning_tokens: z3.number().nullish()
|
|
824
772
|
}).nullish()
|
|
825
773
|
}).nullish()
|
|
826
774
|
}).nullish()
|
|
@@ -829,34 +777,56 @@ var groqChatChunkSchema = import_v43.z.union([
|
|
|
829
777
|
]);
|
|
830
778
|
|
|
831
779
|
// src/groq-transcription-model.ts
|
|
832
|
-
|
|
833
|
-
|
|
780
|
+
import {
|
|
781
|
+
combineHeaders as combineHeaders2,
|
|
782
|
+
convertBase64ToUint8Array,
|
|
783
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
784
|
+
mediaTypeToExtension,
|
|
785
|
+
parseProviderOptions as parseProviderOptions2,
|
|
786
|
+
postFormDataToApi,
|
|
787
|
+
serializeModelOptions as serializeModelOptions2,
|
|
788
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
789
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
790
|
+
} from "@ai-sdk/provider-utils";
|
|
791
|
+
import { z as z5 } from "zod/v4";
|
|
834
792
|
|
|
835
|
-
// src/groq-transcription-options.ts
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
793
|
+
// src/groq-transcription-model-options.ts
|
|
794
|
+
import {
|
|
795
|
+
lazySchema,
|
|
796
|
+
zodSchema
|
|
797
|
+
} from "@ai-sdk/provider-utils";
|
|
798
|
+
import { z as z4 } from "zod/v4";
|
|
799
|
+
var groqTranscriptionModelOptions = lazySchema(
|
|
800
|
+
() => zodSchema(
|
|
801
|
+
z4.object({
|
|
802
|
+
language: z4.string().nullish(),
|
|
803
|
+
prompt: z4.string().nullish(),
|
|
804
|
+
responseFormat: z4.string().nullish(),
|
|
805
|
+
temperature: z4.number().min(0).max(1).nullish(),
|
|
806
|
+
timestampGranularities: z4.array(z4.string()).nullish()
|
|
846
807
|
})
|
|
847
808
|
)
|
|
848
809
|
);
|
|
849
810
|
|
|
850
811
|
// src/groq-transcription-model.ts
|
|
851
|
-
var GroqTranscriptionModel = class {
|
|
812
|
+
var GroqTranscriptionModel = class _GroqTranscriptionModel {
|
|
852
813
|
constructor(modelId, config) {
|
|
853
814
|
this.modelId = modelId;
|
|
854
815
|
this.config = config;
|
|
855
|
-
this.specificationVersion = "
|
|
816
|
+
this.specificationVersion = "v4";
|
|
856
817
|
}
|
|
857
818
|
get provider() {
|
|
858
819
|
return this.config.provider;
|
|
859
820
|
}
|
|
821
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
822
|
+
return serializeModelOptions2({
|
|
823
|
+
modelId: model.modelId,
|
|
824
|
+
config: model.config
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
828
|
+
return new _GroqTranscriptionModel(options.modelId, options.config);
|
|
829
|
+
}
|
|
860
830
|
async getArgs({
|
|
861
831
|
audio,
|
|
862
832
|
mediaType,
|
|
@@ -864,15 +834,15 @@ var GroqTranscriptionModel = class {
|
|
|
864
834
|
}) {
|
|
865
835
|
var _a, _b, _c, _d, _e;
|
|
866
836
|
const warnings = [];
|
|
867
|
-
const groqOptions = await (
|
|
837
|
+
const groqOptions = await parseProviderOptions2({
|
|
868
838
|
provider: "groq",
|
|
869
839
|
providerOptions,
|
|
870
840
|
schema: groqTranscriptionModelOptions
|
|
871
841
|
});
|
|
872
842
|
const formData = new FormData();
|
|
873
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([
|
|
843
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
874
844
|
formData.append("model", this.modelId);
|
|
875
|
-
const fileExtension =
|
|
845
|
+
const fileExtension = mediaTypeToExtension(mediaType);
|
|
876
846
|
formData.append(
|
|
877
847
|
"file",
|
|
878
848
|
new File([blob], "audio", { type: mediaType }),
|
|
@@ -905,22 +875,22 @@ var GroqTranscriptionModel = class {
|
|
|
905
875
|
};
|
|
906
876
|
}
|
|
907
877
|
async doGenerate(options) {
|
|
908
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
878
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
909
879
|
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
880
|
const { formData, warnings } = await this.getArgs(options);
|
|
911
881
|
const {
|
|
912
882
|
value: response,
|
|
913
883
|
responseHeaders,
|
|
914
884
|
rawValue: rawResponse
|
|
915
|
-
} = await
|
|
885
|
+
} = await postFormDataToApi({
|
|
916
886
|
url: this.config.url({
|
|
917
887
|
path: "/audio/transcriptions",
|
|
918
888
|
modelId: this.modelId
|
|
919
889
|
}),
|
|
920
|
-
headers: (
|
|
890
|
+
headers: combineHeaders2((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
|
|
921
891
|
formData,
|
|
922
892
|
failedResponseHandler: groqFailedResponseHandler,
|
|
923
|
-
successfulResponseHandler: (
|
|
893
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
924
894
|
groqTranscriptionResponseSchema
|
|
925
895
|
),
|
|
926
896
|
abortSignal: options.abortSignal,
|
|
@@ -928,13 +898,13 @@ var GroqTranscriptionModel = class {
|
|
|
928
898
|
});
|
|
929
899
|
return {
|
|
930
900
|
text: response.text,
|
|
931
|
-
segments: (
|
|
901
|
+
segments: (_g = (_f = response.segments) == null ? void 0 : _f.map((segment) => ({
|
|
932
902
|
text: segment.text,
|
|
933
903
|
startSecond: segment.start,
|
|
934
904
|
endSecond: segment.end
|
|
935
|
-
}))) != null ?
|
|
936
|
-
language: (
|
|
937
|
-
durationInSeconds: (
|
|
905
|
+
}))) != null ? _g : [],
|
|
906
|
+
language: (_h = response.language) != null ? _h : void 0,
|
|
907
|
+
durationInSeconds: (_i = response.duration) != null ? _i : void 0,
|
|
938
908
|
warnings,
|
|
939
909
|
response: {
|
|
940
910
|
timestamp: currentDate,
|
|
@@ -945,37 +915,42 @@ var GroqTranscriptionModel = class {
|
|
|
945
915
|
};
|
|
946
916
|
}
|
|
947
917
|
};
|
|
948
|
-
var groqTranscriptionResponseSchema =
|
|
949
|
-
text:
|
|
950
|
-
x_groq:
|
|
951
|
-
id:
|
|
918
|
+
var groqTranscriptionResponseSchema = z5.object({
|
|
919
|
+
text: z5.string(),
|
|
920
|
+
x_groq: z5.object({
|
|
921
|
+
id: z5.string()
|
|
952
922
|
}),
|
|
953
923
|
// 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:
|
|
924
|
+
task: z5.string().nullish(),
|
|
925
|
+
language: z5.string().nullish(),
|
|
926
|
+
duration: z5.number().nullish(),
|
|
927
|
+
segments: z5.array(
|
|
928
|
+
z5.object({
|
|
929
|
+
id: z5.number(),
|
|
930
|
+
seek: z5.number(),
|
|
931
|
+
start: z5.number(),
|
|
932
|
+
end: z5.number(),
|
|
933
|
+
text: z5.string(),
|
|
934
|
+
tokens: z5.array(z5.number()),
|
|
935
|
+
temperature: z5.number(),
|
|
936
|
+
avg_logprob: z5.number(),
|
|
937
|
+
compression_ratio: z5.number(),
|
|
938
|
+
no_speech_prob: z5.number()
|
|
969
939
|
})
|
|
970
940
|
).nullish()
|
|
971
941
|
});
|
|
972
942
|
|
|
973
943
|
// src/tool/browser-search.ts
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
944
|
+
import {
|
|
945
|
+
createProviderExecutedToolFactory,
|
|
946
|
+
lazySchema as lazySchema2,
|
|
947
|
+
zodSchema as zodSchema2
|
|
948
|
+
} from "@ai-sdk/provider-utils";
|
|
949
|
+
import { z as z6 } from "zod/v4";
|
|
950
|
+
var browserSearch = createProviderExecutedToolFactory({
|
|
977
951
|
id: "groq.browser_search",
|
|
978
|
-
inputSchema:
|
|
952
|
+
inputSchema: lazySchema2(() => zodSchema2(z6.object({}))),
|
|
953
|
+
outputSchema: lazySchema2(() => zodSchema2(z6.object({})))
|
|
979
954
|
});
|
|
980
955
|
|
|
981
956
|
// src/groq-tools.ts
|
|
@@ -984,15 +959,15 @@ var groqTools = {
|
|
|
984
959
|
};
|
|
985
960
|
|
|
986
961
|
// src/version.ts
|
|
987
|
-
var VERSION = true ? "4.0.0-beta.
|
|
962
|
+
var VERSION = true ? "4.0.0-beta.54" : "0.0.0-test";
|
|
988
963
|
|
|
989
964
|
// src/groq-provider.ts
|
|
990
965
|
function createGroq(options = {}) {
|
|
991
966
|
var _a;
|
|
992
|
-
const baseURL = (_a =
|
|
993
|
-
const getHeaders = () =>
|
|
967
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
|
|
968
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
994
969
|
{
|
|
995
|
-
Authorization: `Bearer ${
|
|
970
|
+
Authorization: `Bearer ${loadApiKey({
|
|
996
971
|
apiKey: options.apiKey,
|
|
997
972
|
environmentVariableName: "GROQ_API_KEY",
|
|
998
973
|
description: "Groq"
|
|
@@ -1026,15 +1001,15 @@ function createGroq(options = {}) {
|
|
|
1026
1001
|
const provider = function(modelId) {
|
|
1027
1002
|
return createLanguageModel(modelId);
|
|
1028
1003
|
};
|
|
1029
|
-
provider.specificationVersion = "
|
|
1004
|
+
provider.specificationVersion = "v4";
|
|
1030
1005
|
provider.languageModel = createLanguageModel;
|
|
1031
1006
|
provider.chat = createChatModel;
|
|
1032
1007
|
provider.embeddingModel = (modelId) => {
|
|
1033
|
-
throw new
|
|
1008
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
1034
1009
|
};
|
|
1035
1010
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
1036
1011
|
provider.imageModel = (modelId) => {
|
|
1037
|
-
throw new
|
|
1012
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1038
1013
|
};
|
|
1039
1014
|
provider.transcription = createTranscriptionModel;
|
|
1040
1015
|
provider.transcriptionModel = createTranscriptionModel;
|
|
@@ -1042,11 +1017,10 @@ function createGroq(options = {}) {
|
|
|
1042
1017
|
return provider;
|
|
1043
1018
|
}
|
|
1044
1019
|
var groq = createGroq();
|
|
1045
|
-
|
|
1046
|
-
0 && (module.exports = {
|
|
1020
|
+
export {
|
|
1047
1021
|
VERSION,
|
|
1048
1022
|
browserSearch,
|
|
1049
1023
|
createGroq,
|
|
1050
1024
|
groq
|
|
1051
|
-
}
|
|
1025
|
+
};
|
|
1052
1026
|
//# sourceMappingURL=index.js.map
|