|
7 | 7 | Fal, |
8 | 8 | Google, |
9 | 9 | OpenAI, |
| 10 | + OpenAICompatible, |
10 | 11 | Replicate, |
11 | 12 | Stability, |
12 | 13 | VercelAIGateway, |
@@ -169,6 +170,39 @@ describe("Image", () => { |
169 | 170 | }), |
170 | 171 | ) |
171 | 172 |
|
| 173 | + it.effect("requests inline bytes by default where hosts would return URLs", () => |
| 174 | + Effect.gen(function* () { |
| 175 | + const bodies: Array<unknown> = [] |
| 176 | + const compatible = OpenAICompatible.configure({ apiKey: "test", baseURL: "https://compatible.test/v1" }) |
| 177 | + const xai = XAI.configure({ apiKey: "test", baseURL: "https://api.xai.test/v1" }) |
| 178 | + const generate = (model: Parameters<typeof Image.generate>[0]["model"], providerOptions?: Record<string, unknown>) => |
| 179 | + Image.generate({ model, prompt: "A lighthouse", providerOptions }).pipe( |
| 180 | + Effect.provide( |
| 181 | + layer((input) => { |
| 182 | + bodies.push(JSON.parse(input.text)) |
| 183 | + return Effect.succeed(json(input, { data: [{ b64_json: "AQID" }] })) |
| 184 | + }), |
| 185 | + ), |
| 186 | + ) |
| 187 | + |
| 188 | + yield* generate(compatible.image("flux-schnell")) |
| 189 | + yield* generate(compatible.image("flux-schnell"), { response_format: "url" }) |
| 190 | + yield* generate(compatible.image("openai/gpt-image-2")) |
| 191 | + yield* generate(compatible.image("image-alias"), { response_format: null }) |
| 192 | + yield* generate(xai.image("grok-imagine-image")) |
| 193 | + yield* generate(xai.image("grok-imagine-image"), { responseFormat: "url" }) |
| 194 | + |
| 195 | + expect(bodies).toEqual([ |
| 196 | + { model: "flux-schnell", prompt: "A lighthouse", response_format: "b64_json" }, |
| 197 | + { model: "flux-schnell", prompt: "A lighthouse", response_format: "url" }, |
| 198 | + { model: "openai/gpt-image-2", prompt: "A lighthouse" }, |
| 199 | + { model: "image-alias", prompt: "A lighthouse" }, |
| 200 | + { model: "grok-imagine-image", prompt: "A lighthouse", response_format: "b64_json" }, |
| 201 | + { model: "grok-imagine-image", prompt: "A lighthouse", response_format: "url" }, |
| 202 | + ]) |
| 203 | + }), |
| 204 | + ) |
| 205 | + |
172 | 206 | describe("OpenAI-style url results", () => { |
173 | 207 | const generate = (data: unknown) => |
174 | 208 | Image.generate({ |
@@ -457,6 +491,7 @@ describe("Image", () => { |
457 | 491 | { url: "https://example.test/source.jpg", type: "image_url" }, |
458 | 492 | { file_id: "file_123" }, |
459 | 493 | ], |
| 494 | + response_format: "b64_json", |
460 | 495 | }) |
461 | 496 | return Effect.succeed( |
462 | 497 | input.respond(JSON.stringify({ data: [{ b64_json: "AQID", mime_type: "image/png" }] }), { |
@@ -484,6 +519,7 @@ describe("Image", () => { |
484 | 519 | model: "future-model", |
485 | 520 | prompt: "Edit this image", |
486 | 521 | image: { file_id: "file_123" }, |
| 522 | + response_format: "b64_json", |
487 | 523 | }) |
488 | 524 | return Effect.succeed( |
489 | 525 | input.respond(JSON.stringify({ data: [{ b64_json: "AQID", mime_type: "image/png" }] }), { |
@@ -945,12 +981,21 @@ describe("Image", () => { |
945 | 981 | images: images.slice(0, 1), |
946 | 982 | aspect: "16:9", |
947 | 983 | }) |
948 | | - yield* Image.start({ model: fal.image("fal-ai/flux-pro/kontext/max/multi"), prompt: "A lighthouse", images }) |
| 984 | + yield* Image.start({ |
| 985 | + model: fal.image("fal-ai/flux-pro/kontext/max/multi"), |
| 986 | + prompt: "A lighthouse", |
| 987 | + images, |
| 988 | + providerOptions: { sync_mode: false }, |
| 989 | + }) |
949 | 990 |
|
950 | 991 | expect(rejected.reason).toMatchObject({ _tag: "UnsupportedOperation", operation: "media.resolution" }) |
951 | 992 | expect(bodies).toEqual([ |
952 | | - { prompt: "A lighthouse", aspect_ratio: "16:9", image_url: "https://example.test/a.png" }, |
953 | | - { prompt: "A lighthouse", image_urls: ["https://example.test/a.png", "https://example.test/b.png"] }, |
| 993 | + { prompt: "A lighthouse", aspect_ratio: "16:9", image_url: "https://example.test/a.png", sync_mode: true }, |
| 994 | + { |
| 995 | + prompt: "A lighthouse", |
| 996 | + image_urls: ["https://example.test/a.png", "https://example.test/b.png"], |
| 997 | + sync_mode: false, |
| 998 | + }, |
954 | 999 | ]) |
955 | 1000 | }).pipe( |
956 | 1001 | Effect.provide( |
|
0 commit comments