@ai-sdk/fireworks 0.0.0-764dcadb-20250115082903 → 0.0.0-98261322-20260122142521
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 +1611 -10
- package/README.md +3 -3
- package/dist/index.d.mts +48 -24
- package/dist/index.d.ts +48 -24
- package/dist/index.js +95 -89
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -96
- package/dist/index.mjs.map +1 -1
- package/docs/26-fireworks.mdx +289 -0
- package/package.json +23 -14
- package/src/fireworks-chat-options.ts +20 -0
- package/src/fireworks-completion-options.ts +5 -0
- package/src/fireworks-embedding-options.ts +12 -0
- package/src/fireworks-image-model.test.ts +629 -0
- package/src/fireworks-image-model.ts +196 -0
- package/src/fireworks-image-options.ts +12 -0
- package/src/fireworks-provider.test.ts +198 -0
- package/src/fireworks-provider.ts +172 -0
- package/src/index.ts +13 -0
- package/src/version.ts +6 -0
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { createTestServer } from '@ai-sdk/test-server/with-vitest';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { FireworksImageModel } from './fireworks-image-model';
|
|
5
|
+
|
|
6
|
+
const prompt = 'A cute baby sea otter';
|
|
7
|
+
|
|
8
|
+
function createBasicModel({
|
|
9
|
+
headers,
|
|
10
|
+
fetch,
|
|
11
|
+
currentDate,
|
|
12
|
+
}: {
|
|
13
|
+
headers?: () => Record<string, string>;
|
|
14
|
+
fetch?: FetchFunction;
|
|
15
|
+
currentDate?: () => Date;
|
|
16
|
+
} = {}) {
|
|
17
|
+
return new FireworksImageModel('accounts/fireworks/models/flux-1-dev-fp8', {
|
|
18
|
+
provider: 'fireworks',
|
|
19
|
+
baseURL: 'https://api.example.com',
|
|
20
|
+
headers: headers ?? (() => ({ 'api-key': 'test-key' })),
|
|
21
|
+
fetch,
|
|
22
|
+
_internal: {
|
|
23
|
+
currentDate,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function createSizeModel() {
|
|
29
|
+
return new FireworksImageModel(
|
|
30
|
+
'accounts/fireworks/models/playground-v2-5-1024px-aesthetic',
|
|
31
|
+
{
|
|
32
|
+
provider: 'fireworks',
|
|
33
|
+
baseURL: 'https://api.size-example.com',
|
|
34
|
+
headers: () => ({ 'api-key': 'test-key' }),
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('FireworksImageModel', () => {
|
|
40
|
+
const server = createTestServer({
|
|
41
|
+
'https://api.example.com/*': {
|
|
42
|
+
response: {
|
|
43
|
+
type: 'binary',
|
|
44
|
+
body: Buffer.from('test-binary-content'),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
'https://api.size-example.com/*': {
|
|
48
|
+
response: {
|
|
49
|
+
type: 'binary',
|
|
50
|
+
body: Buffer.from('test-binary-content'),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('doGenerate', () => {
|
|
56
|
+
it('should pass the correct parameters including aspect ratio and seed', async () => {
|
|
57
|
+
const model = createBasicModel();
|
|
58
|
+
|
|
59
|
+
await model.doGenerate({
|
|
60
|
+
prompt,
|
|
61
|
+
files: undefined,
|
|
62
|
+
mask: undefined,
|
|
63
|
+
n: 1,
|
|
64
|
+
size: undefined,
|
|
65
|
+
aspectRatio: '16:9',
|
|
66
|
+
seed: 42,
|
|
67
|
+
providerOptions: { fireworks: { additional_param: 'value' } },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(await server.calls[0].requestBodyJson).toStrictEqual({
|
|
71
|
+
prompt,
|
|
72
|
+
aspect_ratio: '16:9',
|
|
73
|
+
seed: 42,
|
|
74
|
+
samples: 1,
|
|
75
|
+
additional_param: 'value',
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should call the correct url', async () => {
|
|
80
|
+
const model = createBasicModel();
|
|
81
|
+
|
|
82
|
+
await model.doGenerate({
|
|
83
|
+
prompt,
|
|
84
|
+
files: undefined,
|
|
85
|
+
mask: undefined,
|
|
86
|
+
n: 1,
|
|
87
|
+
size: undefined,
|
|
88
|
+
aspectRatio: '16:9',
|
|
89
|
+
seed: 42,
|
|
90
|
+
providerOptions: { fireworks: { additional_param: 'value' } },
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
expect(server.calls[0].requestMethod).toStrictEqual('POST');
|
|
94
|
+
expect(server.calls[0].requestUrl).toStrictEqual(
|
|
95
|
+
'https://api.example.com/workflows/accounts/fireworks/models/flux-1-dev-fp8/text_to_image',
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should pass headers', async () => {
|
|
100
|
+
const modelWithHeaders = createBasicModel({
|
|
101
|
+
headers: () => ({
|
|
102
|
+
'Custom-Provider-Header': 'provider-header-value',
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await modelWithHeaders.doGenerate({
|
|
107
|
+
prompt,
|
|
108
|
+
files: undefined,
|
|
109
|
+
mask: undefined,
|
|
110
|
+
n: 1,
|
|
111
|
+
size: undefined,
|
|
112
|
+
aspectRatio: undefined,
|
|
113
|
+
seed: undefined,
|
|
114
|
+
providerOptions: {},
|
|
115
|
+
headers: {
|
|
116
|
+
'Custom-Request-Header': 'request-header-value',
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(server.calls[0].requestHeaders).toStrictEqual({
|
|
121
|
+
'content-type': 'application/json',
|
|
122
|
+
'custom-provider-header': 'provider-header-value',
|
|
123
|
+
'custom-request-header': 'request-header-value',
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should handle empty response body', async () => {
|
|
128
|
+
server.urls['https://api.example.com/*'].response = {
|
|
129
|
+
type: 'empty',
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const model = createBasicModel();
|
|
133
|
+
await expect(
|
|
134
|
+
model.doGenerate({
|
|
135
|
+
prompt,
|
|
136
|
+
files: undefined,
|
|
137
|
+
mask: undefined,
|
|
138
|
+
n: 1,
|
|
139
|
+
size: undefined,
|
|
140
|
+
aspectRatio: undefined,
|
|
141
|
+
seed: undefined,
|
|
142
|
+
providerOptions: {},
|
|
143
|
+
}),
|
|
144
|
+
).rejects.toMatchObject({
|
|
145
|
+
message: 'Response body is empty',
|
|
146
|
+
statusCode: 200,
|
|
147
|
+
url: 'https://api.example.com/workflows/accounts/fireworks/models/flux-1-dev-fp8/text_to_image',
|
|
148
|
+
requestBodyValues: {
|
|
149
|
+
prompt: 'A cute baby sea otter',
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should handle API errors', async () => {
|
|
155
|
+
server.urls['https://api.example.com/*'].response = {
|
|
156
|
+
type: 'error',
|
|
157
|
+
status: 400,
|
|
158
|
+
body: 'Bad Request',
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const model = createBasicModel();
|
|
162
|
+
await expect(
|
|
163
|
+
model.doGenerate({
|
|
164
|
+
prompt,
|
|
165
|
+
files: undefined,
|
|
166
|
+
mask: undefined,
|
|
167
|
+
n: 1,
|
|
168
|
+
size: undefined,
|
|
169
|
+
aspectRatio: undefined,
|
|
170
|
+
seed: undefined,
|
|
171
|
+
providerOptions: {},
|
|
172
|
+
}),
|
|
173
|
+
).rejects.toMatchObject({
|
|
174
|
+
message: 'Bad Request',
|
|
175
|
+
statusCode: 400,
|
|
176
|
+
url: 'https://api.example.com/workflows/accounts/fireworks/models/flux-1-dev-fp8/text_to_image',
|
|
177
|
+
requestBodyValues: {
|
|
178
|
+
prompt: 'A cute baby sea otter',
|
|
179
|
+
},
|
|
180
|
+
responseBody: 'Bad Request',
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('should handle size parameter for supported models', async () => {
|
|
185
|
+
const sizeModel = createSizeModel();
|
|
186
|
+
|
|
187
|
+
await sizeModel.doGenerate({
|
|
188
|
+
prompt,
|
|
189
|
+
files: undefined,
|
|
190
|
+
mask: undefined,
|
|
191
|
+
n: 1,
|
|
192
|
+
size: '1024x768',
|
|
193
|
+
aspectRatio: undefined,
|
|
194
|
+
seed: 42,
|
|
195
|
+
providerOptions: {},
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
expect(await server.calls[0].requestBodyJson).toStrictEqual({
|
|
199
|
+
prompt,
|
|
200
|
+
width: '1024',
|
|
201
|
+
height: '768',
|
|
202
|
+
seed: 42,
|
|
203
|
+
samples: 1,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe('warnings', () => {
|
|
208
|
+
it('should return size warning on workflow model', async () => {
|
|
209
|
+
const model = createBasicModel();
|
|
210
|
+
|
|
211
|
+
const result1 = await model.doGenerate({
|
|
212
|
+
prompt,
|
|
213
|
+
files: undefined,
|
|
214
|
+
mask: undefined,
|
|
215
|
+
n: 1,
|
|
216
|
+
size: '1024x1024',
|
|
217
|
+
aspectRatio: '1:1',
|
|
218
|
+
seed: 123,
|
|
219
|
+
providerOptions: {},
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
expect(result1.warnings).toMatchInlineSnapshot(`
|
|
223
|
+
[
|
|
224
|
+
{
|
|
225
|
+
"details": "This model does not support the \`size\` option. Use \`aspectRatio\` instead.",
|
|
226
|
+
"feature": "size",
|
|
227
|
+
"type": "unsupported",
|
|
228
|
+
},
|
|
229
|
+
]
|
|
230
|
+
`);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('should return aspectRatio warning on size-supporting model', async () => {
|
|
234
|
+
const sizeModel = createSizeModel();
|
|
235
|
+
|
|
236
|
+
const result2 = await sizeModel.doGenerate({
|
|
237
|
+
prompt,
|
|
238
|
+
files: undefined,
|
|
239
|
+
mask: undefined,
|
|
240
|
+
n: 1,
|
|
241
|
+
size: '1024x1024',
|
|
242
|
+
aspectRatio: '1:1',
|
|
243
|
+
seed: 123,
|
|
244
|
+
providerOptions: {},
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(result2.warnings).toMatchInlineSnapshot(`
|
|
248
|
+
[
|
|
249
|
+
{
|
|
250
|
+
"details": "This model does not support the \`aspectRatio\` option.",
|
|
251
|
+
"feature": "aspectRatio",
|
|
252
|
+
"type": "unsupported",
|
|
253
|
+
},
|
|
254
|
+
]
|
|
255
|
+
`);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should respect the abort signal', async () => {
|
|
260
|
+
const model = createBasicModel();
|
|
261
|
+
const controller = new AbortController();
|
|
262
|
+
|
|
263
|
+
const generatePromise = model.doGenerate({
|
|
264
|
+
prompt,
|
|
265
|
+
files: undefined,
|
|
266
|
+
mask: undefined,
|
|
267
|
+
n: 1,
|
|
268
|
+
size: undefined,
|
|
269
|
+
aspectRatio: undefined,
|
|
270
|
+
seed: undefined,
|
|
271
|
+
providerOptions: {},
|
|
272
|
+
abortSignal: controller.signal,
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
controller.abort();
|
|
276
|
+
|
|
277
|
+
await expect(generatePromise).rejects.toThrow(
|
|
278
|
+
'This operation was aborted',
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('should use custom fetch function when provided', async () => {
|
|
283
|
+
const mockFetch = vi.fn().mockResolvedValue(
|
|
284
|
+
new Response(Buffer.from('mock-image-data'), {
|
|
285
|
+
status: 200,
|
|
286
|
+
}),
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
const model = createBasicModel({
|
|
290
|
+
fetch: mockFetch,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
await model.doGenerate({
|
|
294
|
+
prompt,
|
|
295
|
+
files: undefined,
|
|
296
|
+
mask: undefined,
|
|
297
|
+
n: 1,
|
|
298
|
+
size: undefined,
|
|
299
|
+
aspectRatio: undefined,
|
|
300
|
+
seed: undefined,
|
|
301
|
+
providerOptions: {},
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
expect(mockFetch).toHaveBeenCalled();
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('should pass samples parameter to API', async () => {
|
|
308
|
+
const model = createBasicModel();
|
|
309
|
+
|
|
310
|
+
await model.doGenerate({
|
|
311
|
+
prompt,
|
|
312
|
+
files: undefined,
|
|
313
|
+
mask: undefined,
|
|
314
|
+
n: 42,
|
|
315
|
+
size: undefined,
|
|
316
|
+
aspectRatio: undefined,
|
|
317
|
+
seed: undefined,
|
|
318
|
+
providerOptions: {},
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
expect(await server.calls[0].requestBodyJson).toHaveProperty(
|
|
322
|
+
'samples',
|
|
323
|
+
42,
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
describe('response metadata', () => {
|
|
328
|
+
it('should include timestamp, headers and modelId in response', async () => {
|
|
329
|
+
const testDate = new Date('2024-01-01T00:00:00Z');
|
|
330
|
+
const model = createBasicModel({
|
|
331
|
+
currentDate: () => testDate,
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const result = await model.doGenerate({
|
|
335
|
+
prompt,
|
|
336
|
+
files: undefined,
|
|
337
|
+
mask: undefined,
|
|
338
|
+
n: 1,
|
|
339
|
+
size: undefined,
|
|
340
|
+
aspectRatio: undefined,
|
|
341
|
+
seed: undefined,
|
|
342
|
+
providerOptions: {},
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
expect(result.response).toStrictEqual({
|
|
346
|
+
timestamp: testDate,
|
|
347
|
+
modelId: 'accounts/fireworks/models/flux-1-dev-fp8',
|
|
348
|
+
headers: expect.any(Object),
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it('should include response headers from API call', async () => {
|
|
353
|
+
server.urls['https://api.example.com/*'].response = {
|
|
354
|
+
type: 'binary',
|
|
355
|
+
body: Buffer.from('test-binary-content'),
|
|
356
|
+
headers: {
|
|
357
|
+
'x-request-id': 'test-request-id',
|
|
358
|
+
'content-type': 'image/png',
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const model = createBasicModel();
|
|
363
|
+
const result = await model.doGenerate({
|
|
364
|
+
prompt,
|
|
365
|
+
files: undefined,
|
|
366
|
+
mask: undefined,
|
|
367
|
+
n: 1,
|
|
368
|
+
size: undefined,
|
|
369
|
+
aspectRatio: undefined,
|
|
370
|
+
seed: undefined,
|
|
371
|
+
providerOptions: {},
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
expect(result.response.headers).toStrictEqual({
|
|
375
|
+
'content-length': '19',
|
|
376
|
+
'x-request-id': 'test-request-id',
|
|
377
|
+
'content-type': 'image/png',
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
describe('constructor', () => {
|
|
384
|
+
it('should expose correct provider and model information', () => {
|
|
385
|
+
const model = createBasicModel();
|
|
386
|
+
|
|
387
|
+
expect(model.provider).toBe('fireworks');
|
|
388
|
+
expect(model.modelId).toBe('accounts/fireworks/models/flux-1-dev-fp8');
|
|
389
|
+
expect(model.specificationVersion).toBe('v3');
|
|
390
|
+
expect(model.maxImagesPerCall).toBe(1);
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
describe('Image Editing', () => {
|
|
395
|
+
const editServer = createTestServer({
|
|
396
|
+
'https://api.edit.example.com/*': {
|
|
397
|
+
response: {
|
|
398
|
+
type: 'binary',
|
|
399
|
+
body: Buffer.from('edited-image-data'),
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
function createKontextModel() {
|
|
405
|
+
return new FireworksImageModel(
|
|
406
|
+
'accounts/fireworks/models/flux-kontext-pro',
|
|
407
|
+
{
|
|
408
|
+
provider: 'fireworks',
|
|
409
|
+
baseURL: 'https://api.edit.example.com',
|
|
410
|
+
headers: () => ({ 'api-key': 'test-key' }),
|
|
411
|
+
},
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
it('should send edit request with files as data URI', async () => {
|
|
416
|
+
const imageData = new Uint8Array([137, 80, 78, 71]); // PNG magic bytes
|
|
417
|
+
|
|
418
|
+
await createKontextModel().doGenerate({
|
|
419
|
+
prompt: 'Turn the cat into a dog',
|
|
420
|
+
files: [
|
|
421
|
+
{
|
|
422
|
+
type: 'file',
|
|
423
|
+
data: imageData,
|
|
424
|
+
mediaType: 'image/png',
|
|
425
|
+
},
|
|
426
|
+
],
|
|
427
|
+
mask: undefined,
|
|
428
|
+
n: 1,
|
|
429
|
+
size: undefined,
|
|
430
|
+
aspectRatio: undefined,
|
|
431
|
+
seed: undefined,
|
|
432
|
+
providerOptions: {},
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
const requestBody = await editServer.calls[0].requestBodyJson;
|
|
436
|
+
expect(requestBody).toMatchInlineSnapshot(`
|
|
437
|
+
{
|
|
438
|
+
"input_image": "data:image/png;base64,iVBORw==",
|
|
439
|
+
"prompt": "Turn the cat into a dog",
|
|
440
|
+
"samples": 1,
|
|
441
|
+
}
|
|
442
|
+
`);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it('should use correct URL for Kontext model (no text_to_image suffix)', async () => {
|
|
446
|
+
const imageData = new Uint8Array([137, 80, 78, 71]);
|
|
447
|
+
|
|
448
|
+
await createKontextModel().doGenerate({
|
|
449
|
+
prompt: 'Edit this image',
|
|
450
|
+
files: [
|
|
451
|
+
{
|
|
452
|
+
type: 'file',
|
|
453
|
+
data: imageData,
|
|
454
|
+
mediaType: 'image/png',
|
|
455
|
+
},
|
|
456
|
+
],
|
|
457
|
+
mask: undefined,
|
|
458
|
+
n: 1,
|
|
459
|
+
size: undefined,
|
|
460
|
+
aspectRatio: undefined,
|
|
461
|
+
seed: undefined,
|
|
462
|
+
providerOptions: {},
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
expect(editServer.calls[0].requestUrl).toBe(
|
|
466
|
+
'https://api.edit.example.com/workflows/accounts/fireworks/models/flux-kontext-pro',
|
|
467
|
+
);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it('should send edit request with URL-based file', async () => {
|
|
471
|
+
await createKontextModel().doGenerate({
|
|
472
|
+
prompt: 'Edit this image',
|
|
473
|
+
files: [
|
|
474
|
+
{
|
|
475
|
+
type: 'url',
|
|
476
|
+
url: 'https://example.com/input.png',
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
mask: undefined,
|
|
480
|
+
n: 1,
|
|
481
|
+
size: undefined,
|
|
482
|
+
aspectRatio: undefined,
|
|
483
|
+
seed: undefined,
|
|
484
|
+
providerOptions: {},
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
const requestBody = await editServer.calls[0].requestBodyJson;
|
|
488
|
+
expect(requestBody).toMatchInlineSnapshot(`
|
|
489
|
+
{
|
|
490
|
+
"input_image": "https://example.com/input.png",
|
|
491
|
+
"prompt": "Edit this image",
|
|
492
|
+
"samples": 1,
|
|
493
|
+
}
|
|
494
|
+
`);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it('should send edit request with base64 string data', async () => {
|
|
498
|
+
await createKontextModel().doGenerate({
|
|
499
|
+
prompt: 'Edit this image',
|
|
500
|
+
files: [
|
|
501
|
+
{
|
|
502
|
+
type: 'file',
|
|
503
|
+
data: 'iVBORw0KGgoAAAANSUhEUgAAAAE=',
|
|
504
|
+
mediaType: 'image/png',
|
|
505
|
+
},
|
|
506
|
+
],
|
|
507
|
+
mask: undefined,
|
|
508
|
+
n: 1,
|
|
509
|
+
size: undefined,
|
|
510
|
+
aspectRatio: undefined,
|
|
511
|
+
seed: undefined,
|
|
512
|
+
providerOptions: {},
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
const requestBody = await editServer.calls[0].requestBodyJson;
|
|
516
|
+
expect(requestBody).toMatchInlineSnapshot(`
|
|
517
|
+
{
|
|
518
|
+
"input_image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAE=",
|
|
519
|
+
"prompt": "Edit this image",
|
|
520
|
+
"samples": 1,
|
|
521
|
+
}
|
|
522
|
+
`);
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it('should warn when multiple files are provided', async () => {
|
|
526
|
+
const imageData = new Uint8Array([137, 80, 78, 71]);
|
|
527
|
+
|
|
528
|
+
const result = await createKontextModel().doGenerate({
|
|
529
|
+
prompt: 'Edit images',
|
|
530
|
+
files: [
|
|
531
|
+
{
|
|
532
|
+
type: 'file',
|
|
533
|
+
data: imageData,
|
|
534
|
+
mediaType: 'image/png',
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
type: 'file',
|
|
538
|
+
data: imageData,
|
|
539
|
+
mediaType: 'image/png',
|
|
540
|
+
},
|
|
541
|
+
],
|
|
542
|
+
mask: undefined,
|
|
543
|
+
n: 1,
|
|
544
|
+
size: undefined,
|
|
545
|
+
aspectRatio: undefined,
|
|
546
|
+
seed: undefined,
|
|
547
|
+
providerOptions: {},
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
expect(result.warnings).toContainEqual({
|
|
551
|
+
type: 'other',
|
|
552
|
+
message:
|
|
553
|
+
'Fireworks only supports a single input image. Additional images are ignored.',
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('should warn when mask is provided', async () => {
|
|
558
|
+
const imageData = new Uint8Array([137, 80, 78, 71]);
|
|
559
|
+
const maskData = new Uint8Array([255, 255, 255, 0]);
|
|
560
|
+
|
|
561
|
+
const result = await createKontextModel().doGenerate({
|
|
562
|
+
prompt: 'Edit with mask',
|
|
563
|
+
files: [
|
|
564
|
+
{
|
|
565
|
+
type: 'file',
|
|
566
|
+
data: imageData,
|
|
567
|
+
mediaType: 'image/png',
|
|
568
|
+
},
|
|
569
|
+
],
|
|
570
|
+
mask: {
|
|
571
|
+
type: 'file',
|
|
572
|
+
data: maskData,
|
|
573
|
+
mediaType: 'image/png',
|
|
574
|
+
},
|
|
575
|
+
n: 1,
|
|
576
|
+
size: undefined,
|
|
577
|
+
aspectRatio: undefined,
|
|
578
|
+
seed: undefined,
|
|
579
|
+
providerOptions: {},
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
expect(result.warnings).toContainEqual({
|
|
583
|
+
type: 'unsupported',
|
|
584
|
+
feature: 'mask',
|
|
585
|
+
details:
|
|
586
|
+
'Fireworks Kontext models do not support explicit masks. Use the prompt to describe the areas to edit.',
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it('should pass provider options with edit request', async () => {
|
|
591
|
+
const imageData = new Uint8Array([137, 80, 78, 71]);
|
|
592
|
+
|
|
593
|
+
await createKontextModel().doGenerate({
|
|
594
|
+
prompt: 'Edit with options',
|
|
595
|
+
files: [
|
|
596
|
+
{
|
|
597
|
+
type: 'file',
|
|
598
|
+
data: imageData,
|
|
599
|
+
mediaType: 'image/png',
|
|
600
|
+
},
|
|
601
|
+
],
|
|
602
|
+
mask: undefined,
|
|
603
|
+
n: 1,
|
|
604
|
+
size: undefined,
|
|
605
|
+
aspectRatio: '16:9',
|
|
606
|
+
seed: 42,
|
|
607
|
+
providerOptions: {
|
|
608
|
+
fireworks: {
|
|
609
|
+
output_format: 'jpeg',
|
|
610
|
+
safety_tolerance: 2,
|
|
611
|
+
},
|
|
612
|
+
},
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
const requestBody = await editServer.calls[0].requestBodyJson;
|
|
616
|
+
expect(requestBody).toMatchInlineSnapshot(`
|
|
617
|
+
{
|
|
618
|
+
"aspect_ratio": "16:9",
|
|
619
|
+
"input_image": "data:image/png;base64,iVBORw==",
|
|
620
|
+
"output_format": "jpeg",
|
|
621
|
+
"prompt": "Edit with options",
|
|
622
|
+
"safety_tolerance": 2,
|
|
623
|
+
"samples": 1,
|
|
624
|
+
"seed": 42,
|
|
625
|
+
}
|
|
626
|
+
`);
|
|
627
|
+
});
|
|
628
|
+
});
|
|
629
|
+
});
|