@ai-sdk/groq 4.0.0-beta.21 → 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 +20 -0
- package/dist/index.js +183 -191
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/groq-chat-language-model.ts +6 -15
- package/dist/index.d.mts +0 -113
- package/dist/index.mjs +0 -1068
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
DELETED
|
@@ -1,1068 +0,0 @@
|
|
|
1
|
-
// src/groq-provider.ts
|
|
2
|
-
import {
|
|
3
|
-
NoSuchModelError
|
|
4
|
-
} from "@ai-sdk/provider";
|
|
5
|
-
import {
|
|
6
|
-
loadApiKey,
|
|
7
|
-
withoutTrailingSlash,
|
|
8
|
-
withUserAgentSuffix
|
|
9
|
-
} from "@ai-sdk/provider-utils";
|
|
10
|
-
|
|
11
|
-
// src/groq-chat-language-model.ts
|
|
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";
|
|
27
|
-
|
|
28
|
-
// src/convert-groq-usage.ts
|
|
29
|
-
function convertGroqUsage(usage) {
|
|
30
|
-
var _a, _b, _c, _d;
|
|
31
|
-
if (usage == null) {
|
|
32
|
-
return {
|
|
33
|
-
inputTokens: {
|
|
34
|
-
total: void 0,
|
|
35
|
-
noCache: void 0,
|
|
36
|
-
cacheRead: void 0,
|
|
37
|
-
cacheWrite: void 0
|
|
38
|
-
},
|
|
39
|
-
outputTokens: {
|
|
40
|
-
total: void 0,
|
|
41
|
-
text: void 0,
|
|
42
|
-
reasoning: void 0
|
|
43
|
-
},
|
|
44
|
-
raw: void 0
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
|
|
48
|
-
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
49
|
-
const reasoningTokens = (_d = (_c = usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : void 0;
|
|
50
|
-
const textTokens = reasoningTokens != null ? completionTokens - reasoningTokens : completionTokens;
|
|
51
|
-
return {
|
|
52
|
-
inputTokens: {
|
|
53
|
-
total: promptTokens,
|
|
54
|
-
noCache: promptTokens,
|
|
55
|
-
cacheRead: void 0,
|
|
56
|
-
cacheWrite: void 0
|
|
57
|
-
},
|
|
58
|
-
outputTokens: {
|
|
59
|
-
total: completionTokens,
|
|
60
|
-
text: textTokens,
|
|
61
|
-
reasoning: reasoningTokens
|
|
62
|
-
},
|
|
63
|
-
raw: usage
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/convert-to-groq-chat-messages.ts
|
|
68
|
-
import {
|
|
69
|
-
UnsupportedFunctionalityError
|
|
70
|
-
} from "@ai-sdk/provider";
|
|
71
|
-
import { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
|
|
72
|
-
function convertToGroqChatMessages(prompt) {
|
|
73
|
-
var _a;
|
|
74
|
-
const messages = [];
|
|
75
|
-
for (const { role, content } of prompt) {
|
|
76
|
-
switch (role) {
|
|
77
|
-
case "system": {
|
|
78
|
-
messages.push({ role: "system", content });
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
case "user": {
|
|
82
|
-
if (content.length === 1 && content[0].type === "text") {
|
|
83
|
-
messages.push({ role: "user", content: content[0].text });
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
messages.push({
|
|
87
|
-
role: "user",
|
|
88
|
-
content: content.map((part) => {
|
|
89
|
-
switch (part.type) {
|
|
90
|
-
case "text": {
|
|
91
|
-
return { type: "text", text: part.text };
|
|
92
|
-
}
|
|
93
|
-
case "file": {
|
|
94
|
-
if (isProviderReference(part.data)) {
|
|
95
|
-
throw new UnsupportedFunctionalityError({
|
|
96
|
-
functionality: "file parts with provider references"
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
if (!part.mediaType.startsWith("image/")) {
|
|
100
|
-
throw new UnsupportedFunctionalityError({
|
|
101
|
-
functionality: "Non-image file content parts"
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
105
|
-
return {
|
|
106
|
-
type: "image_url",
|
|
107
|
-
image_url: {
|
|
108
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
});
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
case "assistant": {
|
|
118
|
-
let text = "";
|
|
119
|
-
let reasoning = "";
|
|
120
|
-
const toolCalls = [];
|
|
121
|
-
for (const part of content) {
|
|
122
|
-
switch (part.type) {
|
|
123
|
-
// groq supports reasoning for tool-calls in multi-turn conversations
|
|
124
|
-
// https://github.com/vercel/ai/issues/7860
|
|
125
|
-
case "reasoning": {
|
|
126
|
-
reasoning += part.text;
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
case "text": {
|
|
130
|
-
text += part.text;
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
case "tool-call": {
|
|
134
|
-
toolCalls.push({
|
|
135
|
-
id: part.toolCallId,
|
|
136
|
-
type: "function",
|
|
137
|
-
function: {
|
|
138
|
-
name: part.toolName,
|
|
139
|
-
arguments: JSON.stringify(part.input)
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
messages.push({
|
|
147
|
-
role: "assistant",
|
|
148
|
-
content: text,
|
|
149
|
-
...reasoning.length > 0 ? { reasoning } : null,
|
|
150
|
-
...toolCalls.length > 0 ? { tool_calls: toolCalls } : null
|
|
151
|
-
});
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
case "tool": {
|
|
155
|
-
for (const toolResponse of content) {
|
|
156
|
-
if (toolResponse.type === "tool-approval-response") {
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
const output = toolResponse.output;
|
|
160
|
-
let contentValue;
|
|
161
|
-
switch (output.type) {
|
|
162
|
-
case "text":
|
|
163
|
-
case "error-text":
|
|
164
|
-
contentValue = output.value;
|
|
165
|
-
break;
|
|
166
|
-
case "execution-denied":
|
|
167
|
-
contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
|
|
168
|
-
break;
|
|
169
|
-
case "content":
|
|
170
|
-
case "json":
|
|
171
|
-
case "error-json":
|
|
172
|
-
contentValue = JSON.stringify(output.value);
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
messages.push({
|
|
176
|
-
role: "tool",
|
|
177
|
-
tool_call_id: toolResponse.toolCallId,
|
|
178
|
-
content: contentValue
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
default: {
|
|
184
|
-
const _exhaustiveCheck = role;
|
|
185
|
-
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return messages;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// src/get-response-metadata.ts
|
|
193
|
-
function getResponseMetadata({
|
|
194
|
-
id,
|
|
195
|
-
model,
|
|
196
|
-
created
|
|
197
|
-
}) {
|
|
198
|
-
return {
|
|
199
|
-
id: id != null ? id : void 0,
|
|
200
|
-
modelId: model != null ? model : void 0,
|
|
201
|
-
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// src/groq-chat-options.ts
|
|
206
|
-
import { z } from "zod/v4";
|
|
207
|
-
var groqLanguageModelOptions = z.object({
|
|
208
|
-
reasoningFormat: z.enum(["parsed", "raw", "hidden"]).optional(),
|
|
209
|
-
/**
|
|
210
|
-
* Specifies the reasoning effort level for model inference.
|
|
211
|
-
* @see https://console.groq.com/docs/reasoning#reasoning-effort
|
|
212
|
-
*/
|
|
213
|
-
reasoningEffort: z.enum(["none", "default", "low", "medium", "high"]).optional(),
|
|
214
|
-
/**
|
|
215
|
-
* Whether to enable parallel function calling during tool use. Default to true.
|
|
216
|
-
*/
|
|
217
|
-
parallelToolCalls: z.boolean().optional(),
|
|
218
|
-
/**
|
|
219
|
-
* A unique identifier representing your end-user, which can help OpenAI to
|
|
220
|
-
* monitor and detect abuse. Learn more.
|
|
221
|
-
*/
|
|
222
|
-
user: z.string().optional(),
|
|
223
|
-
/**
|
|
224
|
-
* Whether to use structured outputs.
|
|
225
|
-
*
|
|
226
|
-
* @default true
|
|
227
|
-
*/
|
|
228
|
-
structuredOutputs: z.boolean().optional(),
|
|
229
|
-
/**
|
|
230
|
-
* Whether to use strict JSON schema validation.
|
|
231
|
-
* When true, the model uses constrained decoding to guarantee schema compliance.
|
|
232
|
-
* Only used when structured outputs are enabled and a schema is provided.
|
|
233
|
-
*
|
|
234
|
-
* @default true
|
|
235
|
-
*/
|
|
236
|
-
strictJsonSchema: z.boolean().optional(),
|
|
237
|
-
/**
|
|
238
|
-
* Service tier for the request.
|
|
239
|
-
* - 'on_demand': Default tier with consistent performance and fairness
|
|
240
|
-
* - 'performance': Prioritized tier for latency-sensitive workloads
|
|
241
|
-
* - 'flex': Higher throughput tier optimized for workloads that can handle occasional request failures
|
|
242
|
-
* - 'auto': Uses on_demand rate limits, then falls back to flex tier if exceeded
|
|
243
|
-
*
|
|
244
|
-
* @default 'on_demand'
|
|
245
|
-
*/
|
|
246
|
-
serviceTier: z.enum(["on_demand", "performance", "flex", "auto"]).optional()
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
// src/groq-error.ts
|
|
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()
|
|
256
|
-
})
|
|
257
|
-
});
|
|
258
|
-
var groqFailedResponseHandler = createJsonErrorResponseHandler({
|
|
259
|
-
errorSchema: groqErrorDataSchema,
|
|
260
|
-
errorToMessage: (data) => data.error.message
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
// src/groq-prepare-tools.ts
|
|
264
|
-
import {
|
|
265
|
-
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
266
|
-
} from "@ai-sdk/provider";
|
|
267
|
-
|
|
268
|
-
// src/groq-browser-search-models.ts
|
|
269
|
-
var BROWSER_SEARCH_SUPPORTED_MODELS = [
|
|
270
|
-
"openai/gpt-oss-20b",
|
|
271
|
-
"openai/gpt-oss-120b"
|
|
272
|
-
];
|
|
273
|
-
function isBrowserSearchSupportedModel(modelId) {
|
|
274
|
-
return BROWSER_SEARCH_SUPPORTED_MODELS.includes(modelId);
|
|
275
|
-
}
|
|
276
|
-
function getSupportedModelsString() {
|
|
277
|
-
return BROWSER_SEARCH_SUPPORTED_MODELS.join(", ");
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// src/groq-prepare-tools.ts
|
|
281
|
-
function prepareTools({
|
|
282
|
-
tools,
|
|
283
|
-
toolChoice,
|
|
284
|
-
modelId
|
|
285
|
-
}) {
|
|
286
|
-
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
287
|
-
const toolWarnings = [];
|
|
288
|
-
if (tools == null) {
|
|
289
|
-
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
290
|
-
}
|
|
291
|
-
const groqTools2 = [];
|
|
292
|
-
for (const tool of tools) {
|
|
293
|
-
if (tool.type === "provider") {
|
|
294
|
-
if (tool.id === "groq.browser_search") {
|
|
295
|
-
if (!isBrowserSearchSupportedModel(modelId)) {
|
|
296
|
-
toolWarnings.push({
|
|
297
|
-
type: "unsupported",
|
|
298
|
-
feature: `provider-defined tool ${tool.id}`,
|
|
299
|
-
details: `Browser search is only supported on the following models: ${getSupportedModelsString()}. Current model: ${modelId}`
|
|
300
|
-
});
|
|
301
|
-
} else {
|
|
302
|
-
groqTools2.push({
|
|
303
|
-
type: "browser_search"
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
} else {
|
|
307
|
-
toolWarnings.push({
|
|
308
|
-
type: "unsupported",
|
|
309
|
-
feature: `provider-defined tool ${tool.id}`
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
} else {
|
|
313
|
-
groqTools2.push({
|
|
314
|
-
type: "function",
|
|
315
|
-
function: {
|
|
316
|
-
name: tool.name,
|
|
317
|
-
description: tool.description,
|
|
318
|
-
parameters: tool.inputSchema,
|
|
319
|
-
...tool.strict != null ? { strict: tool.strict } : {}
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
if (toolChoice == null) {
|
|
325
|
-
return { tools: groqTools2, toolChoice: void 0, toolWarnings };
|
|
326
|
-
}
|
|
327
|
-
const type = toolChoice.type;
|
|
328
|
-
switch (type) {
|
|
329
|
-
case "auto":
|
|
330
|
-
case "none":
|
|
331
|
-
case "required":
|
|
332
|
-
return { tools: groqTools2, toolChoice: type, toolWarnings };
|
|
333
|
-
case "tool":
|
|
334
|
-
return {
|
|
335
|
-
tools: groqTools2,
|
|
336
|
-
toolChoice: {
|
|
337
|
-
type: "function",
|
|
338
|
-
function: {
|
|
339
|
-
name: toolChoice.toolName
|
|
340
|
-
}
|
|
341
|
-
},
|
|
342
|
-
toolWarnings
|
|
343
|
-
};
|
|
344
|
-
default: {
|
|
345
|
-
const _exhaustiveCheck = type;
|
|
346
|
-
throw new UnsupportedFunctionalityError2({
|
|
347
|
-
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// src/map-groq-finish-reason.ts
|
|
354
|
-
function mapGroqFinishReason(finishReason) {
|
|
355
|
-
switch (finishReason) {
|
|
356
|
-
case "stop":
|
|
357
|
-
return "stop";
|
|
358
|
-
case "length":
|
|
359
|
-
return "length";
|
|
360
|
-
case "content_filter":
|
|
361
|
-
return "content-filter";
|
|
362
|
-
case "function_call":
|
|
363
|
-
case "tool_calls":
|
|
364
|
-
return "tool-calls";
|
|
365
|
-
default:
|
|
366
|
-
return "other";
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// src/groq-chat-language-model.ts
|
|
371
|
-
var GroqChatLanguageModel = class {
|
|
372
|
-
constructor(modelId, config) {
|
|
373
|
-
this.specificationVersion = "v4";
|
|
374
|
-
this.supportedUrls = {
|
|
375
|
-
"image/*": [/^https?:\/\/.*$/]
|
|
376
|
-
};
|
|
377
|
-
this.modelId = modelId;
|
|
378
|
-
this.config = config;
|
|
379
|
-
}
|
|
380
|
-
get provider() {
|
|
381
|
-
return this.config.provider;
|
|
382
|
-
}
|
|
383
|
-
async getArgs({
|
|
384
|
-
prompt,
|
|
385
|
-
maxOutputTokens,
|
|
386
|
-
temperature,
|
|
387
|
-
topP,
|
|
388
|
-
topK,
|
|
389
|
-
frequencyPenalty,
|
|
390
|
-
presencePenalty,
|
|
391
|
-
stopSequences,
|
|
392
|
-
responseFormat,
|
|
393
|
-
seed,
|
|
394
|
-
reasoning,
|
|
395
|
-
stream,
|
|
396
|
-
tools,
|
|
397
|
-
toolChoice,
|
|
398
|
-
providerOptions
|
|
399
|
-
}) {
|
|
400
|
-
var _a, _b, _c, _d;
|
|
401
|
-
const warnings = [];
|
|
402
|
-
const groqOptions = await parseProviderOptions({
|
|
403
|
-
provider: "groq",
|
|
404
|
-
providerOptions,
|
|
405
|
-
schema: groqLanguageModelOptions
|
|
406
|
-
});
|
|
407
|
-
const structuredOutputs = (_a = groqOptions == null ? void 0 : groqOptions.structuredOutputs) != null ? _a : true;
|
|
408
|
-
const strictJsonSchema = (_b = groqOptions == null ? void 0 : groqOptions.strictJsonSchema) != null ? _b : true;
|
|
409
|
-
if (topK != null) {
|
|
410
|
-
warnings.push({ type: "unsupported", feature: "topK" });
|
|
411
|
-
}
|
|
412
|
-
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !structuredOutputs) {
|
|
413
|
-
warnings.push({
|
|
414
|
-
type: "unsupported",
|
|
415
|
-
feature: "responseFormat",
|
|
416
|
-
details: "JSON response format schema is only supported with structuredOutputs"
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
const {
|
|
420
|
-
tools: groqTools2,
|
|
421
|
-
toolChoice: groqToolChoice,
|
|
422
|
-
toolWarnings
|
|
423
|
-
} = prepareTools({ tools, toolChoice, modelId: this.modelId });
|
|
424
|
-
return {
|
|
425
|
-
args: {
|
|
426
|
-
// model id:
|
|
427
|
-
model: this.modelId,
|
|
428
|
-
// model specific settings:
|
|
429
|
-
user: groqOptions == null ? void 0 : groqOptions.user,
|
|
430
|
-
parallel_tool_calls: groqOptions == null ? void 0 : groqOptions.parallelToolCalls,
|
|
431
|
-
// standardized settings:
|
|
432
|
-
max_tokens: maxOutputTokens,
|
|
433
|
-
temperature,
|
|
434
|
-
top_p: topP,
|
|
435
|
-
frequency_penalty: frequencyPenalty,
|
|
436
|
-
presence_penalty: presencePenalty,
|
|
437
|
-
stop: stopSequences,
|
|
438
|
-
seed,
|
|
439
|
-
// response format:
|
|
440
|
-
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && responseFormat.schema != null ? {
|
|
441
|
-
type: "json_schema",
|
|
442
|
-
json_schema: {
|
|
443
|
-
schema: responseFormat.schema,
|
|
444
|
-
strict: strictJsonSchema,
|
|
445
|
-
name: (_c = responseFormat.name) != null ? _c : "response",
|
|
446
|
-
description: responseFormat.description
|
|
447
|
-
}
|
|
448
|
-
} : { type: "json_object" } : void 0,
|
|
449
|
-
// provider options:
|
|
450
|
-
reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
|
|
451
|
-
reasoning_effort: (_d = groqOptions == null ? void 0 : groqOptions.reasoningEffort) != null ? _d : isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
|
|
452
|
-
reasoning,
|
|
453
|
-
effortMap: {
|
|
454
|
-
minimal: "low",
|
|
455
|
-
low: "low",
|
|
456
|
-
medium: "medium",
|
|
457
|
-
high: "high",
|
|
458
|
-
xhigh: "high"
|
|
459
|
-
},
|
|
460
|
-
warnings
|
|
461
|
-
}) : void 0,
|
|
462
|
-
service_tier: groqOptions == null ? void 0 : groqOptions.serviceTier,
|
|
463
|
-
// messages:
|
|
464
|
-
messages: convertToGroqChatMessages(prompt),
|
|
465
|
-
// tools:
|
|
466
|
-
tools: groqTools2,
|
|
467
|
-
tool_choice: groqToolChoice
|
|
468
|
-
},
|
|
469
|
-
warnings: [...warnings, ...toolWarnings]
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
async doGenerate(options) {
|
|
473
|
-
var _a, _b;
|
|
474
|
-
const { args, warnings } = await this.getArgs({
|
|
475
|
-
...options,
|
|
476
|
-
stream: false
|
|
477
|
-
});
|
|
478
|
-
const body = JSON.stringify(args);
|
|
479
|
-
const {
|
|
480
|
-
responseHeaders,
|
|
481
|
-
value: response,
|
|
482
|
-
rawValue: rawResponse
|
|
483
|
-
} = await postJsonToApi({
|
|
484
|
-
url: this.config.url({
|
|
485
|
-
path: "/chat/completions",
|
|
486
|
-
modelId: this.modelId
|
|
487
|
-
}),
|
|
488
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
489
|
-
body: args,
|
|
490
|
-
failedResponseHandler: groqFailedResponseHandler,
|
|
491
|
-
successfulResponseHandler: createJsonResponseHandler(
|
|
492
|
-
groqChatResponseSchema
|
|
493
|
-
),
|
|
494
|
-
abortSignal: options.abortSignal,
|
|
495
|
-
fetch: this.config.fetch
|
|
496
|
-
});
|
|
497
|
-
const choice = response.choices[0];
|
|
498
|
-
const content = [];
|
|
499
|
-
const text = choice.message.content;
|
|
500
|
-
if (text != null && text.length > 0) {
|
|
501
|
-
content.push({ type: "text", text });
|
|
502
|
-
}
|
|
503
|
-
const reasoning = choice.message.reasoning;
|
|
504
|
-
if (reasoning != null && reasoning.length > 0) {
|
|
505
|
-
content.push({
|
|
506
|
-
type: "reasoning",
|
|
507
|
-
text: reasoning
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
if (choice.message.tool_calls != null) {
|
|
511
|
-
for (const toolCall of choice.message.tool_calls) {
|
|
512
|
-
content.push({
|
|
513
|
-
type: "tool-call",
|
|
514
|
-
toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
|
|
515
|
-
toolName: toolCall.function.name,
|
|
516
|
-
input: toolCall.function.arguments
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
return {
|
|
521
|
-
content,
|
|
522
|
-
finishReason: {
|
|
523
|
-
unified: mapGroqFinishReason(choice.finish_reason),
|
|
524
|
-
raw: (_b = choice.finish_reason) != null ? _b : void 0
|
|
525
|
-
},
|
|
526
|
-
usage: convertGroqUsage(response.usage),
|
|
527
|
-
response: {
|
|
528
|
-
...getResponseMetadata(response),
|
|
529
|
-
headers: responseHeaders,
|
|
530
|
-
body: rawResponse
|
|
531
|
-
},
|
|
532
|
-
warnings,
|
|
533
|
-
request: { body }
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
async doStream(options) {
|
|
537
|
-
const { args, warnings } = await this.getArgs({ ...options, stream: true });
|
|
538
|
-
const body = JSON.stringify({ ...args, stream: true });
|
|
539
|
-
const { responseHeaders, value: response } = await postJsonToApi({
|
|
540
|
-
url: this.config.url({
|
|
541
|
-
path: "/chat/completions",
|
|
542
|
-
modelId: this.modelId
|
|
543
|
-
}),
|
|
544
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
545
|
-
body: {
|
|
546
|
-
...args,
|
|
547
|
-
stream: true
|
|
548
|
-
},
|
|
549
|
-
failedResponseHandler: groqFailedResponseHandler,
|
|
550
|
-
successfulResponseHandler: createEventSourceResponseHandler(groqChatChunkSchema),
|
|
551
|
-
abortSignal: options.abortSignal,
|
|
552
|
-
fetch: this.config.fetch
|
|
553
|
-
});
|
|
554
|
-
const toolCalls = [];
|
|
555
|
-
let finishReason = {
|
|
556
|
-
unified: "other",
|
|
557
|
-
raw: void 0
|
|
558
|
-
};
|
|
559
|
-
let usage = void 0;
|
|
560
|
-
let isFirstChunk = true;
|
|
561
|
-
let isActiveText = false;
|
|
562
|
-
let isActiveReasoning = false;
|
|
563
|
-
let providerMetadata;
|
|
564
|
-
return {
|
|
565
|
-
stream: response.pipeThrough(
|
|
566
|
-
new TransformStream({
|
|
567
|
-
start(controller) {
|
|
568
|
-
controller.enqueue({ type: "stream-start", warnings });
|
|
569
|
-
},
|
|
570
|
-
transform(chunk, controller) {
|
|
571
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
572
|
-
if (options.includeRawChunks) {
|
|
573
|
-
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
574
|
-
}
|
|
575
|
-
if (!chunk.success) {
|
|
576
|
-
finishReason = {
|
|
577
|
-
unified: "error",
|
|
578
|
-
raw: void 0
|
|
579
|
-
};
|
|
580
|
-
controller.enqueue({ type: "error", error: chunk.error });
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
const value = chunk.value;
|
|
584
|
-
if ("error" in value) {
|
|
585
|
-
finishReason = {
|
|
586
|
-
unified: "error",
|
|
587
|
-
raw: void 0
|
|
588
|
-
};
|
|
589
|
-
controller.enqueue({ type: "error", error: value.error });
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
if (isFirstChunk) {
|
|
593
|
-
isFirstChunk = false;
|
|
594
|
-
controller.enqueue({
|
|
595
|
-
type: "response-metadata",
|
|
596
|
-
...getResponseMetadata(value)
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
if (((_a = value.x_groq) == null ? void 0 : _a.usage) != null) {
|
|
600
|
-
usage = value.x_groq.usage;
|
|
601
|
-
}
|
|
602
|
-
const choice = value.choices[0];
|
|
603
|
-
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
604
|
-
finishReason = {
|
|
605
|
-
unified: mapGroqFinishReason(choice.finish_reason),
|
|
606
|
-
raw: choice.finish_reason
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
const delta = choice.delta;
|
|
613
|
-
if (delta.reasoning != null && delta.reasoning.length > 0) {
|
|
614
|
-
if (!isActiveReasoning) {
|
|
615
|
-
controller.enqueue({
|
|
616
|
-
type: "reasoning-start",
|
|
617
|
-
id: "reasoning-0"
|
|
618
|
-
});
|
|
619
|
-
isActiveReasoning = true;
|
|
620
|
-
}
|
|
621
|
-
controller.enqueue({
|
|
622
|
-
type: "reasoning-delta",
|
|
623
|
-
id: "reasoning-0",
|
|
624
|
-
delta: delta.reasoning
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
if (delta.content != null && delta.content.length > 0) {
|
|
628
|
-
if (isActiveReasoning) {
|
|
629
|
-
controller.enqueue({
|
|
630
|
-
type: "reasoning-end",
|
|
631
|
-
id: "reasoning-0"
|
|
632
|
-
});
|
|
633
|
-
isActiveReasoning = false;
|
|
634
|
-
}
|
|
635
|
-
if (!isActiveText) {
|
|
636
|
-
controller.enqueue({ type: "text-start", id: "txt-0" });
|
|
637
|
-
isActiveText = true;
|
|
638
|
-
}
|
|
639
|
-
controller.enqueue({
|
|
640
|
-
type: "text-delta",
|
|
641
|
-
id: "txt-0",
|
|
642
|
-
delta: delta.content
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
if (delta.tool_calls != null) {
|
|
646
|
-
if (isActiveReasoning) {
|
|
647
|
-
controller.enqueue({
|
|
648
|
-
type: "reasoning-end",
|
|
649
|
-
id: "reasoning-0"
|
|
650
|
-
});
|
|
651
|
-
isActiveReasoning = false;
|
|
652
|
-
}
|
|
653
|
-
for (const toolCallDelta of delta.tool_calls) {
|
|
654
|
-
const index = toolCallDelta.index;
|
|
655
|
-
if (toolCalls[index] == null) {
|
|
656
|
-
if (toolCallDelta.type !== "function") {
|
|
657
|
-
throw new InvalidResponseDataError({
|
|
658
|
-
data: toolCallDelta,
|
|
659
|
-
message: `Expected 'function' type.`
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
if (toolCallDelta.id == null) {
|
|
663
|
-
throw new InvalidResponseDataError({
|
|
664
|
-
data: toolCallDelta,
|
|
665
|
-
message: `Expected 'id' to be a string.`
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
|
|
669
|
-
throw new InvalidResponseDataError({
|
|
670
|
-
data: toolCallDelta,
|
|
671
|
-
message: `Expected 'function.name' to be a string.`
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
controller.enqueue({
|
|
675
|
-
type: "tool-input-start",
|
|
676
|
-
id: toolCallDelta.id,
|
|
677
|
-
toolName: toolCallDelta.function.name
|
|
678
|
-
});
|
|
679
|
-
toolCalls[index] = {
|
|
680
|
-
id: toolCallDelta.id,
|
|
681
|
-
type: "function",
|
|
682
|
-
function: {
|
|
683
|
-
name: toolCallDelta.function.name,
|
|
684
|
-
arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
|
|
685
|
-
},
|
|
686
|
-
hasFinished: false
|
|
687
|
-
};
|
|
688
|
-
const toolCall2 = toolCalls[index];
|
|
689
|
-
if (((_d = toolCall2.function) == null ? void 0 : _d.name) != null && ((_e = toolCall2.function) == null ? void 0 : _e.arguments) != null) {
|
|
690
|
-
if (toolCall2.function.arguments.length > 0) {
|
|
691
|
-
controller.enqueue({
|
|
692
|
-
type: "tool-input-delta",
|
|
693
|
-
id: toolCall2.id,
|
|
694
|
-
delta: toolCall2.function.arguments
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
|
-
if (isParsableJson(toolCall2.function.arguments)) {
|
|
698
|
-
controller.enqueue({
|
|
699
|
-
type: "tool-input-end",
|
|
700
|
-
id: toolCall2.id
|
|
701
|
-
});
|
|
702
|
-
controller.enqueue({
|
|
703
|
-
type: "tool-call",
|
|
704
|
-
toolCallId: (_f = toolCall2.id) != null ? _f : generateId(),
|
|
705
|
-
toolName: toolCall2.function.name,
|
|
706
|
-
input: toolCall2.function.arguments
|
|
707
|
-
});
|
|
708
|
-
toolCall2.hasFinished = true;
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
continue;
|
|
712
|
-
}
|
|
713
|
-
const toolCall = toolCalls[index];
|
|
714
|
-
if (toolCall.hasFinished) {
|
|
715
|
-
continue;
|
|
716
|
-
}
|
|
717
|
-
if (((_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null) {
|
|
718
|
-
toolCall.function.arguments += (_i = (_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null ? _i : "";
|
|
719
|
-
}
|
|
720
|
-
controller.enqueue({
|
|
721
|
-
type: "tool-input-delta",
|
|
722
|
-
id: toolCall.id,
|
|
723
|
-
delta: (_j = toolCallDelta.function.arguments) != null ? _j : ""
|
|
724
|
-
});
|
|
725
|
-
if (((_k = toolCall.function) == null ? void 0 : _k.name) != null && ((_l = toolCall.function) == null ? void 0 : _l.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
726
|
-
controller.enqueue({
|
|
727
|
-
type: "tool-input-end",
|
|
728
|
-
id: toolCall.id
|
|
729
|
-
});
|
|
730
|
-
controller.enqueue({
|
|
731
|
-
type: "tool-call",
|
|
732
|
-
toolCallId: (_m = toolCall.id) != null ? _m : generateId(),
|
|
733
|
-
toolName: toolCall.function.name,
|
|
734
|
-
input: toolCall.function.arguments
|
|
735
|
-
});
|
|
736
|
-
toolCall.hasFinished = true;
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
},
|
|
741
|
-
flush(controller) {
|
|
742
|
-
if (isActiveReasoning) {
|
|
743
|
-
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
|
744
|
-
}
|
|
745
|
-
if (isActiveText) {
|
|
746
|
-
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
747
|
-
}
|
|
748
|
-
controller.enqueue({
|
|
749
|
-
type: "finish",
|
|
750
|
-
finishReason,
|
|
751
|
-
usage: convertGroqUsage(usage),
|
|
752
|
-
...providerMetadata != null ? { providerMetadata } : {}
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
})
|
|
756
|
-
),
|
|
757
|
-
request: { body },
|
|
758
|
-
response: { headers: responseHeaders }
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
};
|
|
762
|
-
var groqChatResponseSchema = z3.object({
|
|
763
|
-
id: z3.string().nullish(),
|
|
764
|
-
created: z3.number().nullish(),
|
|
765
|
-
model: z3.string().nullish(),
|
|
766
|
-
choices: z3.array(
|
|
767
|
-
z3.object({
|
|
768
|
-
message: z3.object({
|
|
769
|
-
content: z3.string().nullish(),
|
|
770
|
-
reasoning: z3.string().nullish(),
|
|
771
|
-
tool_calls: z3.array(
|
|
772
|
-
z3.object({
|
|
773
|
-
id: z3.string().nullish(),
|
|
774
|
-
type: z3.literal("function"),
|
|
775
|
-
function: z3.object({
|
|
776
|
-
name: z3.string(),
|
|
777
|
-
arguments: z3.string()
|
|
778
|
-
})
|
|
779
|
-
})
|
|
780
|
-
).nullish()
|
|
781
|
-
}),
|
|
782
|
-
index: z3.number(),
|
|
783
|
-
finish_reason: z3.string().nullish()
|
|
784
|
-
})
|
|
785
|
-
),
|
|
786
|
-
usage: z3.object({
|
|
787
|
-
prompt_tokens: z3.number().nullish(),
|
|
788
|
-
completion_tokens: z3.number().nullish(),
|
|
789
|
-
total_tokens: z3.number().nullish(),
|
|
790
|
-
prompt_tokens_details: z3.object({
|
|
791
|
-
cached_tokens: z3.number().nullish()
|
|
792
|
-
}).nullish(),
|
|
793
|
-
completion_tokens_details: z3.object({
|
|
794
|
-
reasoning_tokens: z3.number().nullish()
|
|
795
|
-
}).nullish()
|
|
796
|
-
}).nullish()
|
|
797
|
-
});
|
|
798
|
-
var groqChatChunkSchema = z3.union([
|
|
799
|
-
z3.object({
|
|
800
|
-
id: z3.string().nullish(),
|
|
801
|
-
created: z3.number().nullish(),
|
|
802
|
-
model: z3.string().nullish(),
|
|
803
|
-
choices: z3.array(
|
|
804
|
-
z3.object({
|
|
805
|
-
delta: z3.object({
|
|
806
|
-
content: z3.string().nullish(),
|
|
807
|
-
reasoning: z3.string().nullish(),
|
|
808
|
-
tool_calls: z3.array(
|
|
809
|
-
z3.object({
|
|
810
|
-
index: z3.number(),
|
|
811
|
-
id: z3.string().nullish(),
|
|
812
|
-
type: z3.literal("function").optional(),
|
|
813
|
-
function: z3.object({
|
|
814
|
-
name: z3.string().nullish(),
|
|
815
|
-
arguments: z3.string().nullish()
|
|
816
|
-
})
|
|
817
|
-
})
|
|
818
|
-
).nullish()
|
|
819
|
-
}).nullish(),
|
|
820
|
-
finish_reason: z3.string().nullable().optional(),
|
|
821
|
-
index: z3.number()
|
|
822
|
-
})
|
|
823
|
-
),
|
|
824
|
-
x_groq: z3.object({
|
|
825
|
-
usage: z3.object({
|
|
826
|
-
prompt_tokens: z3.number().nullish(),
|
|
827
|
-
completion_tokens: z3.number().nullish(),
|
|
828
|
-
total_tokens: z3.number().nullish(),
|
|
829
|
-
prompt_tokens_details: z3.object({
|
|
830
|
-
cached_tokens: z3.number().nullish()
|
|
831
|
-
}).nullish(),
|
|
832
|
-
completion_tokens_details: z3.object({
|
|
833
|
-
reasoning_tokens: z3.number().nullish()
|
|
834
|
-
}).nullish()
|
|
835
|
-
}).nullish()
|
|
836
|
-
}).nullish()
|
|
837
|
-
}),
|
|
838
|
-
groqErrorDataSchema
|
|
839
|
-
]);
|
|
840
|
-
|
|
841
|
-
// src/groq-transcription-model.ts
|
|
842
|
-
import {
|
|
843
|
-
combineHeaders as combineHeaders2,
|
|
844
|
-
convertBase64ToUint8Array,
|
|
845
|
-
createJsonResponseHandler as createJsonResponseHandler2,
|
|
846
|
-
mediaTypeToExtension,
|
|
847
|
-
parseProviderOptions as parseProviderOptions2,
|
|
848
|
-
postFormDataToApi
|
|
849
|
-
} from "@ai-sdk/provider-utils";
|
|
850
|
-
import { z as z5 } from "zod/v4";
|
|
851
|
-
|
|
852
|
-
// src/groq-transcription-options.ts
|
|
853
|
-
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
854
|
-
import { z as z4 } from "zod/v4";
|
|
855
|
-
var groqTranscriptionModelOptions = lazySchema(
|
|
856
|
-
() => zodSchema(
|
|
857
|
-
z4.object({
|
|
858
|
-
language: z4.string().nullish(),
|
|
859
|
-
prompt: z4.string().nullish(),
|
|
860
|
-
responseFormat: z4.string().nullish(),
|
|
861
|
-
temperature: z4.number().min(0).max(1).nullish(),
|
|
862
|
-
timestampGranularities: z4.array(z4.string()).nullish()
|
|
863
|
-
})
|
|
864
|
-
)
|
|
865
|
-
);
|
|
866
|
-
|
|
867
|
-
// src/groq-transcription-model.ts
|
|
868
|
-
var GroqTranscriptionModel = class {
|
|
869
|
-
constructor(modelId, config) {
|
|
870
|
-
this.modelId = modelId;
|
|
871
|
-
this.config = config;
|
|
872
|
-
this.specificationVersion = "v4";
|
|
873
|
-
}
|
|
874
|
-
get provider() {
|
|
875
|
-
return this.config.provider;
|
|
876
|
-
}
|
|
877
|
-
async getArgs({
|
|
878
|
-
audio,
|
|
879
|
-
mediaType,
|
|
880
|
-
providerOptions
|
|
881
|
-
}) {
|
|
882
|
-
var _a, _b, _c, _d, _e;
|
|
883
|
-
const warnings = [];
|
|
884
|
-
const groqOptions = await parseProviderOptions2({
|
|
885
|
-
provider: "groq",
|
|
886
|
-
providerOptions,
|
|
887
|
-
schema: groqTranscriptionModelOptions
|
|
888
|
-
});
|
|
889
|
-
const formData = new FormData();
|
|
890
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
891
|
-
formData.append("model", this.modelId);
|
|
892
|
-
const fileExtension = mediaTypeToExtension(mediaType);
|
|
893
|
-
formData.append(
|
|
894
|
-
"file",
|
|
895
|
-
new File([blob], "audio", { type: mediaType }),
|
|
896
|
-
`audio.${fileExtension}`
|
|
897
|
-
);
|
|
898
|
-
if (groqOptions) {
|
|
899
|
-
const transcriptionModelOptions = {
|
|
900
|
-
language: (_a = groqOptions.language) != null ? _a : void 0,
|
|
901
|
-
prompt: (_b = groqOptions.prompt) != null ? _b : void 0,
|
|
902
|
-
response_format: (_c = groqOptions.responseFormat) != null ? _c : void 0,
|
|
903
|
-
temperature: (_d = groqOptions.temperature) != null ? _d : void 0,
|
|
904
|
-
timestamp_granularities: (_e = groqOptions.timestampGranularities) != null ? _e : void 0
|
|
905
|
-
};
|
|
906
|
-
for (const key in transcriptionModelOptions) {
|
|
907
|
-
const value = transcriptionModelOptions[key];
|
|
908
|
-
if (value !== void 0) {
|
|
909
|
-
if (Array.isArray(value)) {
|
|
910
|
-
for (const item of value) {
|
|
911
|
-
formData.append(`${key}[]`, String(item));
|
|
912
|
-
}
|
|
913
|
-
} else {
|
|
914
|
-
formData.append(key, String(value));
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
return {
|
|
920
|
-
formData,
|
|
921
|
-
warnings
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
async doGenerate(options) {
|
|
925
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
926
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
927
|
-
const { formData, warnings } = await this.getArgs(options);
|
|
928
|
-
const {
|
|
929
|
-
value: response,
|
|
930
|
-
responseHeaders,
|
|
931
|
-
rawValue: rawResponse
|
|
932
|
-
} = await postFormDataToApi({
|
|
933
|
-
url: this.config.url({
|
|
934
|
-
path: "/audio/transcriptions",
|
|
935
|
-
modelId: this.modelId
|
|
936
|
-
}),
|
|
937
|
-
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
938
|
-
formData,
|
|
939
|
-
failedResponseHandler: groqFailedResponseHandler,
|
|
940
|
-
successfulResponseHandler: createJsonResponseHandler2(
|
|
941
|
-
groqTranscriptionResponseSchema
|
|
942
|
-
),
|
|
943
|
-
abortSignal: options.abortSignal,
|
|
944
|
-
fetch: this.config.fetch
|
|
945
|
-
});
|
|
946
|
-
return {
|
|
947
|
-
text: response.text,
|
|
948
|
-
segments: (_e = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
|
|
949
|
-
text: segment.text,
|
|
950
|
-
startSecond: segment.start,
|
|
951
|
-
endSecond: segment.end
|
|
952
|
-
}))) != null ? _e : [],
|
|
953
|
-
language: (_f = response.language) != null ? _f : void 0,
|
|
954
|
-
durationInSeconds: (_g = response.duration) != null ? _g : void 0,
|
|
955
|
-
warnings,
|
|
956
|
-
response: {
|
|
957
|
-
timestamp: currentDate,
|
|
958
|
-
modelId: this.modelId,
|
|
959
|
-
headers: responseHeaders,
|
|
960
|
-
body: rawResponse
|
|
961
|
-
}
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
};
|
|
965
|
-
var groqTranscriptionResponseSchema = z5.object({
|
|
966
|
-
text: z5.string(),
|
|
967
|
-
x_groq: z5.object({
|
|
968
|
-
id: z5.string()
|
|
969
|
-
}),
|
|
970
|
-
// additional properties are returned when `response_format: 'verbose_json'` is
|
|
971
|
-
task: z5.string().nullish(),
|
|
972
|
-
language: z5.string().nullish(),
|
|
973
|
-
duration: z5.number().nullish(),
|
|
974
|
-
segments: z5.array(
|
|
975
|
-
z5.object({
|
|
976
|
-
id: z5.number(),
|
|
977
|
-
seek: z5.number(),
|
|
978
|
-
start: z5.number(),
|
|
979
|
-
end: z5.number(),
|
|
980
|
-
text: z5.string(),
|
|
981
|
-
tokens: z5.array(z5.number()),
|
|
982
|
-
temperature: z5.number(),
|
|
983
|
-
avg_logprob: z5.number(),
|
|
984
|
-
compression_ratio: z5.number(),
|
|
985
|
-
no_speech_prob: z5.number()
|
|
986
|
-
})
|
|
987
|
-
).nullish()
|
|
988
|
-
});
|
|
989
|
-
|
|
990
|
-
// src/tool/browser-search.ts
|
|
991
|
-
import { createProviderToolFactory } from "@ai-sdk/provider-utils";
|
|
992
|
-
import { z as z6 } from "zod/v4";
|
|
993
|
-
var browserSearch = createProviderToolFactory({
|
|
994
|
-
id: "groq.browser_search",
|
|
995
|
-
inputSchema: z6.object({})
|
|
996
|
-
});
|
|
997
|
-
|
|
998
|
-
// src/groq-tools.ts
|
|
999
|
-
var groqTools = {
|
|
1000
|
-
browserSearch
|
|
1001
|
-
};
|
|
1002
|
-
|
|
1003
|
-
// src/version.ts
|
|
1004
|
-
var VERSION = true ? "4.0.0-beta.21" : "0.0.0-test";
|
|
1005
|
-
|
|
1006
|
-
// src/groq-provider.ts
|
|
1007
|
-
function createGroq(options = {}) {
|
|
1008
|
-
var _a;
|
|
1009
|
-
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
|
|
1010
|
-
const getHeaders = () => withUserAgentSuffix(
|
|
1011
|
-
{
|
|
1012
|
-
Authorization: `Bearer ${loadApiKey({
|
|
1013
|
-
apiKey: options.apiKey,
|
|
1014
|
-
environmentVariableName: "GROQ_API_KEY",
|
|
1015
|
-
description: "Groq"
|
|
1016
|
-
})}`,
|
|
1017
|
-
...options.headers
|
|
1018
|
-
},
|
|
1019
|
-
`ai-sdk/groq/${VERSION}`
|
|
1020
|
-
);
|
|
1021
|
-
const createChatModel = (modelId) => new GroqChatLanguageModel(modelId, {
|
|
1022
|
-
provider: "groq.chat",
|
|
1023
|
-
url: ({ path }) => `${baseURL}${path}`,
|
|
1024
|
-
headers: getHeaders,
|
|
1025
|
-
fetch: options.fetch
|
|
1026
|
-
});
|
|
1027
|
-
const createLanguageModel = (modelId) => {
|
|
1028
|
-
if (new.target) {
|
|
1029
|
-
throw new Error(
|
|
1030
|
-
"The Groq model function cannot be called with the new keyword."
|
|
1031
|
-
);
|
|
1032
|
-
}
|
|
1033
|
-
return createChatModel(modelId);
|
|
1034
|
-
};
|
|
1035
|
-
const createTranscriptionModel = (modelId) => {
|
|
1036
|
-
return new GroqTranscriptionModel(modelId, {
|
|
1037
|
-
provider: "groq.transcription",
|
|
1038
|
-
url: ({ path }) => `${baseURL}${path}`,
|
|
1039
|
-
headers: getHeaders,
|
|
1040
|
-
fetch: options.fetch
|
|
1041
|
-
});
|
|
1042
|
-
};
|
|
1043
|
-
const provider = function(modelId) {
|
|
1044
|
-
return createLanguageModel(modelId);
|
|
1045
|
-
};
|
|
1046
|
-
provider.specificationVersion = "v4";
|
|
1047
|
-
provider.languageModel = createLanguageModel;
|
|
1048
|
-
provider.chat = createChatModel;
|
|
1049
|
-
provider.embeddingModel = (modelId) => {
|
|
1050
|
-
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
1051
|
-
};
|
|
1052
|
-
provider.textEmbeddingModel = provider.embeddingModel;
|
|
1053
|
-
provider.imageModel = (modelId) => {
|
|
1054
|
-
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1055
|
-
};
|
|
1056
|
-
provider.transcription = createTranscriptionModel;
|
|
1057
|
-
provider.transcriptionModel = createTranscriptionModel;
|
|
1058
|
-
provider.tools = groqTools;
|
|
1059
|
-
return provider;
|
|
1060
|
-
}
|
|
1061
|
-
var groq = createGroq();
|
|
1062
|
-
export {
|
|
1063
|
-
VERSION,
|
|
1064
|
-
browserSearch,
|
|
1065
|
-
createGroq,
|
|
1066
|
-
groq
|
|
1067
|
-
};
|
|
1068
|
-
//# sourceMappingURL=index.mjs.map
|