@ai-sdk/groq 3.0.14 → 3.0.16
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 +16 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +8 -4
- package/src/convert-groq-usage.test.ts +0 -237
- package/src/convert-to-groq-chat-messages.test.ts +0 -205
- package/src/groq-chat-language-model.test.ts +0 -2028
- package/src/groq-chat-options.test.ts +0 -110
- package/src/groq-prepare-tools.test.ts +0 -272
- package/src/groq-transcription-model.test.ts +0 -185
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ai-sdk/groq
|
|
2
2
|
|
|
3
|
+
## 3.0.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [462ad00]
|
|
8
|
+
- @ai-sdk/provider-utils@4.0.10
|
|
9
|
+
|
|
10
|
+
## 3.0.15
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 4de5a1d: chore: excluded tests from src folder in npm package
|
|
15
|
+
- Updated dependencies [4de5a1d]
|
|
16
|
+
- @ai-sdk/provider@3.0.5
|
|
17
|
+
- @ai-sdk/provider-utils@4.0.9
|
|
18
|
+
|
|
3
19
|
## 3.0.14
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/groq",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.16",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
"dist/**/*",
|
|
11
11
|
"docs/**/*",
|
|
12
12
|
"src",
|
|
13
|
+
"!src/**/*.test.ts",
|
|
14
|
+
"!src/**/*.test-d.ts",
|
|
15
|
+
"!src/**/__snapshots__",
|
|
16
|
+
"!src/**/__fixtures__",
|
|
13
17
|
"CHANGELOG.md",
|
|
14
18
|
"README.md"
|
|
15
19
|
],
|
|
@@ -25,15 +29,15 @@
|
|
|
25
29
|
}
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
28
|
-
"@ai-sdk/provider": "3.0.
|
|
29
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
32
|
+
"@ai-sdk/provider": "3.0.5",
|
|
33
|
+
"@ai-sdk/provider-utils": "4.0.10"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
36
|
"@types/node": "20.17.24",
|
|
33
37
|
"tsup": "^8",
|
|
34
38
|
"typescript": "5.8.3",
|
|
35
39
|
"zod": "3.25.76",
|
|
36
|
-
"@ai-sdk/test-server": "1.0.
|
|
40
|
+
"@ai-sdk/test-server": "1.0.3",
|
|
37
41
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
38
42
|
},
|
|
39
43
|
"peerDependencies": {
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { convertGroqUsage } from './convert-groq-usage';
|
|
3
|
-
|
|
4
|
-
describe('convertGroqUsage', () => {
|
|
5
|
-
it('should return undefined values when usage is null', () => {
|
|
6
|
-
const result = convertGroqUsage(null);
|
|
7
|
-
|
|
8
|
-
expect(result).toStrictEqual({
|
|
9
|
-
inputTokens: {
|
|
10
|
-
total: undefined,
|
|
11
|
-
noCache: undefined,
|
|
12
|
-
cacheRead: undefined,
|
|
13
|
-
cacheWrite: undefined,
|
|
14
|
-
},
|
|
15
|
-
outputTokens: {
|
|
16
|
-
total: undefined,
|
|
17
|
-
text: undefined,
|
|
18
|
-
reasoning: undefined,
|
|
19
|
-
},
|
|
20
|
-
raw: undefined,
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should return undefined values when usage is undefined', () => {
|
|
25
|
-
const result = convertGroqUsage(undefined);
|
|
26
|
-
|
|
27
|
-
expect(result).toStrictEqual({
|
|
28
|
-
inputTokens: {
|
|
29
|
-
total: undefined,
|
|
30
|
-
noCache: undefined,
|
|
31
|
-
cacheRead: undefined,
|
|
32
|
-
cacheWrite: undefined,
|
|
33
|
-
},
|
|
34
|
-
outputTokens: {
|
|
35
|
-
total: undefined,
|
|
36
|
-
text: undefined,
|
|
37
|
-
reasoning: undefined,
|
|
38
|
-
},
|
|
39
|
-
raw: undefined,
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should convert basic usage without token details', () => {
|
|
44
|
-
const result = convertGroqUsage({
|
|
45
|
-
prompt_tokens: 20,
|
|
46
|
-
completion_tokens: 10,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
expect(result).toStrictEqual({
|
|
50
|
-
inputTokens: {
|
|
51
|
-
total: 20,
|
|
52
|
-
noCache: 20,
|
|
53
|
-
cacheRead: undefined,
|
|
54
|
-
cacheWrite: undefined,
|
|
55
|
-
},
|
|
56
|
-
outputTokens: {
|
|
57
|
-
total: 10,
|
|
58
|
-
text: 10,
|
|
59
|
-
reasoning: undefined,
|
|
60
|
-
},
|
|
61
|
-
raw: {
|
|
62
|
-
prompt_tokens: 20,
|
|
63
|
-
completion_tokens: 10,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should extract reasoning tokens from completion_tokens_details', () => {
|
|
69
|
-
const result = convertGroqUsage({
|
|
70
|
-
prompt_tokens: 79,
|
|
71
|
-
completion_tokens: 40,
|
|
72
|
-
completion_tokens_details: {
|
|
73
|
-
reasoning_tokens: 21,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
expect(result).toStrictEqual({
|
|
78
|
-
inputTokens: {
|
|
79
|
-
total: 79,
|
|
80
|
-
noCache: 79,
|
|
81
|
-
cacheRead: undefined,
|
|
82
|
-
cacheWrite: undefined,
|
|
83
|
-
},
|
|
84
|
-
outputTokens: {
|
|
85
|
-
total: 40,
|
|
86
|
-
text: 19, // 40 - 21 = 19
|
|
87
|
-
reasoning: 21,
|
|
88
|
-
},
|
|
89
|
-
raw: {
|
|
90
|
-
prompt_tokens: 79,
|
|
91
|
-
completion_tokens: 40,
|
|
92
|
-
completion_tokens_details: {
|
|
93
|
-
reasoning_tokens: 21,
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should handle null reasoning_tokens in completion_tokens_details', () => {
|
|
100
|
-
const result = convertGroqUsage({
|
|
101
|
-
prompt_tokens: 20,
|
|
102
|
-
completion_tokens: 10,
|
|
103
|
-
completion_tokens_details: {
|
|
104
|
-
reasoning_tokens: null,
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
expect(result).toStrictEqual({
|
|
109
|
-
inputTokens: {
|
|
110
|
-
total: 20,
|
|
111
|
-
noCache: 20,
|
|
112
|
-
cacheRead: undefined,
|
|
113
|
-
cacheWrite: undefined,
|
|
114
|
-
},
|
|
115
|
-
outputTokens: {
|
|
116
|
-
total: 10,
|
|
117
|
-
text: 10,
|
|
118
|
-
reasoning: undefined,
|
|
119
|
-
},
|
|
120
|
-
raw: {
|
|
121
|
-
prompt_tokens: 20,
|
|
122
|
-
completion_tokens: 10,
|
|
123
|
-
completion_tokens_details: {
|
|
124
|
-
reasoning_tokens: null,
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should handle null completion_tokens_details', () => {
|
|
131
|
-
const result = convertGroqUsage({
|
|
132
|
-
prompt_tokens: 20,
|
|
133
|
-
completion_tokens: 10,
|
|
134
|
-
completion_tokens_details: null,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
expect(result).toStrictEqual({
|
|
138
|
-
inputTokens: {
|
|
139
|
-
total: 20,
|
|
140
|
-
noCache: 20,
|
|
141
|
-
cacheRead: undefined,
|
|
142
|
-
cacheWrite: undefined,
|
|
143
|
-
},
|
|
144
|
-
outputTokens: {
|
|
145
|
-
total: 10,
|
|
146
|
-
text: 10,
|
|
147
|
-
reasoning: undefined,
|
|
148
|
-
},
|
|
149
|
-
raw: {
|
|
150
|
-
prompt_tokens: 20,
|
|
151
|
-
completion_tokens: 10,
|
|
152
|
-
completion_tokens_details: null,
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should handle zero reasoning tokens', () => {
|
|
158
|
-
const result = convertGroqUsage({
|
|
159
|
-
prompt_tokens: 20,
|
|
160
|
-
completion_tokens: 10,
|
|
161
|
-
completion_tokens_details: {
|
|
162
|
-
reasoning_tokens: 0,
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
expect(result).toStrictEqual({
|
|
167
|
-
inputTokens: {
|
|
168
|
-
total: 20,
|
|
169
|
-
noCache: 20,
|
|
170
|
-
cacheRead: undefined,
|
|
171
|
-
cacheWrite: undefined,
|
|
172
|
-
},
|
|
173
|
-
outputTokens: {
|
|
174
|
-
total: 10,
|
|
175
|
-
text: 10,
|
|
176
|
-
reasoning: 0,
|
|
177
|
-
},
|
|
178
|
-
raw: {
|
|
179
|
-
prompt_tokens: 20,
|
|
180
|
-
completion_tokens: 10,
|
|
181
|
-
completion_tokens_details: {
|
|
182
|
-
reasoning_tokens: 0,
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('should handle all tokens being reasoning tokens', () => {
|
|
189
|
-
const result = convertGroqUsage({
|
|
190
|
-
prompt_tokens: 20,
|
|
191
|
-
completion_tokens: 50,
|
|
192
|
-
completion_tokens_details: {
|
|
193
|
-
reasoning_tokens: 50,
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
expect(result).toStrictEqual({
|
|
198
|
-
inputTokens: {
|
|
199
|
-
total: 20,
|
|
200
|
-
noCache: 20,
|
|
201
|
-
cacheRead: undefined,
|
|
202
|
-
cacheWrite: undefined,
|
|
203
|
-
},
|
|
204
|
-
outputTokens: {
|
|
205
|
-
total: 50,
|
|
206
|
-
text: 0, // 50 - 50 = 0
|
|
207
|
-
reasoning: 50,
|
|
208
|
-
},
|
|
209
|
-
raw: {
|
|
210
|
-
prompt_tokens: 20,
|
|
211
|
-
completion_tokens: 50,
|
|
212
|
-
completion_tokens_details: {
|
|
213
|
-
reasoning_tokens: 50,
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('should handle missing prompt_tokens and completion_tokens', () => {
|
|
220
|
-
const result = convertGroqUsage({});
|
|
221
|
-
|
|
222
|
-
expect(result).toStrictEqual({
|
|
223
|
-
inputTokens: {
|
|
224
|
-
total: 0,
|
|
225
|
-
noCache: 0,
|
|
226
|
-
cacheRead: undefined,
|
|
227
|
-
cacheWrite: undefined,
|
|
228
|
-
},
|
|
229
|
-
outputTokens: {
|
|
230
|
-
total: 0,
|
|
231
|
-
text: 0,
|
|
232
|
-
reasoning: undefined,
|
|
233
|
-
},
|
|
234
|
-
raw: {},
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
});
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { convertToGroqChatMessages } from './convert-to-groq-chat-messages';
|
|
2
|
-
import { describe, it, expect } from 'vitest';
|
|
3
|
-
|
|
4
|
-
describe('user messages', () => {
|
|
5
|
-
it('should convert messages with image parts', async () => {
|
|
6
|
-
const result = convertToGroqChatMessages([
|
|
7
|
-
{
|
|
8
|
-
role: 'user',
|
|
9
|
-
content: [
|
|
10
|
-
{ type: 'text', text: 'Hello' },
|
|
11
|
-
{
|
|
12
|
-
type: 'file',
|
|
13
|
-
data: 'AAECAw==',
|
|
14
|
-
mediaType: 'image/png',
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
},
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
expect(result).toMatchInlineSnapshot(`
|
|
21
|
-
[
|
|
22
|
-
{
|
|
23
|
-
"content": [
|
|
24
|
-
{
|
|
25
|
-
"text": "Hello",
|
|
26
|
-
"type": "text",
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"image_url": {
|
|
30
|
-
"url": "data:image/png;base64,AAECAw==",
|
|
31
|
-
},
|
|
32
|
-
"type": "image_url",
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
"role": "user",
|
|
36
|
-
},
|
|
37
|
-
]
|
|
38
|
-
`);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should convert messages with image parts from Uint8Array', async () => {
|
|
42
|
-
const result = convertToGroqChatMessages([
|
|
43
|
-
{
|
|
44
|
-
role: 'user',
|
|
45
|
-
content: [
|
|
46
|
-
{ type: 'text', text: 'Hi' },
|
|
47
|
-
{
|
|
48
|
-
type: 'file',
|
|
49
|
-
data: new Uint8Array([0, 1, 2, 3]),
|
|
50
|
-
mediaType: 'image/png',
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
expect(result).toMatchInlineSnapshot(`
|
|
57
|
-
[
|
|
58
|
-
{
|
|
59
|
-
"content": [
|
|
60
|
-
{
|
|
61
|
-
"text": "Hi",
|
|
62
|
-
"type": "text",
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
"image_url": {
|
|
66
|
-
"url": "data:image/png;base64,AAECAw==",
|
|
67
|
-
},
|
|
68
|
-
"type": "image_url",
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
"role": "user",
|
|
72
|
-
},
|
|
73
|
-
]
|
|
74
|
-
`);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should convert messages with only a text part to a string content', async () => {
|
|
78
|
-
const result = convertToGroqChatMessages([
|
|
79
|
-
{
|
|
80
|
-
role: 'user',
|
|
81
|
-
content: [{ type: 'text', text: 'Hello' }],
|
|
82
|
-
},
|
|
83
|
-
]);
|
|
84
|
-
|
|
85
|
-
expect(result).toMatchInlineSnapshot(`
|
|
86
|
-
[
|
|
87
|
-
{
|
|
88
|
-
"content": "Hello",
|
|
89
|
-
"role": "user",
|
|
90
|
-
},
|
|
91
|
-
]
|
|
92
|
-
`);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('tool calls', () => {
|
|
97
|
-
it('should stringify arguments to tool calls', () => {
|
|
98
|
-
const result = convertToGroqChatMessages([
|
|
99
|
-
{
|
|
100
|
-
role: 'assistant',
|
|
101
|
-
content: [
|
|
102
|
-
{
|
|
103
|
-
type: 'tool-call',
|
|
104
|
-
input: { foo: 'bar123' },
|
|
105
|
-
toolCallId: 'quux',
|
|
106
|
-
toolName: 'thwomp',
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
role: 'tool',
|
|
112
|
-
content: [
|
|
113
|
-
{
|
|
114
|
-
type: 'tool-result',
|
|
115
|
-
toolCallId: 'quux',
|
|
116
|
-
toolName: 'thwomp',
|
|
117
|
-
output: { type: 'json', value: { oof: '321rab' } },
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
},
|
|
121
|
-
]);
|
|
122
|
-
|
|
123
|
-
expect(result).toMatchInlineSnapshot(`
|
|
124
|
-
[
|
|
125
|
-
{
|
|
126
|
-
"content": "",
|
|
127
|
-
"role": "assistant",
|
|
128
|
-
"tool_calls": [
|
|
129
|
-
{
|
|
130
|
-
"function": {
|
|
131
|
-
"arguments": "{"foo":"bar123"}",
|
|
132
|
-
"name": "thwomp",
|
|
133
|
-
},
|
|
134
|
-
"id": "quux",
|
|
135
|
-
"type": "function",
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
"content": "{"oof":"321rab"}",
|
|
141
|
-
"role": "tool",
|
|
142
|
-
"tool_call_id": "quux",
|
|
143
|
-
},
|
|
144
|
-
]
|
|
145
|
-
`);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should send reasoning if present', () => {
|
|
149
|
-
const result = convertToGroqChatMessages([
|
|
150
|
-
{
|
|
151
|
-
role: 'assistant',
|
|
152
|
-
content: [
|
|
153
|
-
{
|
|
154
|
-
type: 'reasoning',
|
|
155
|
-
text: 'I think the tool will return the correct value.',
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
type: 'tool-call',
|
|
159
|
-
input: { foo: 'bar123' },
|
|
160
|
-
toolCallId: 'quux',
|
|
161
|
-
toolName: 'thwomp',
|
|
162
|
-
},
|
|
163
|
-
],
|
|
164
|
-
},
|
|
165
|
-
]);
|
|
166
|
-
|
|
167
|
-
expect(result).toMatchInlineSnapshot(`
|
|
168
|
-
[
|
|
169
|
-
{
|
|
170
|
-
"content": "",
|
|
171
|
-
"reasoning": "I think the tool will return the correct value.",
|
|
172
|
-
"role": "assistant",
|
|
173
|
-
"tool_calls": [
|
|
174
|
-
{
|
|
175
|
-
"function": {
|
|
176
|
-
"arguments": "{"foo":"bar123"}",
|
|
177
|
-
"name": "thwomp",
|
|
178
|
-
},
|
|
179
|
-
"id": "quux",
|
|
180
|
-
"type": "function",
|
|
181
|
-
},
|
|
182
|
-
],
|
|
183
|
-
},
|
|
184
|
-
]
|
|
185
|
-
`);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('should not include reasoning field when no reasoning content is present', () => {
|
|
189
|
-
const result = convertToGroqChatMessages([
|
|
190
|
-
{
|
|
191
|
-
role: 'assistant',
|
|
192
|
-
content: [{ type: 'text', text: 'Hello, how can I help you?' }],
|
|
193
|
-
},
|
|
194
|
-
]);
|
|
195
|
-
|
|
196
|
-
expect(result).toMatchInlineSnapshot(`
|
|
197
|
-
[
|
|
198
|
-
{
|
|
199
|
-
"content": "Hello, how can I help you?",
|
|
200
|
-
"role": "assistant",
|
|
201
|
-
},
|
|
202
|
-
]
|
|
203
|
-
`);
|
|
204
|
-
});
|
|
205
|
-
});
|