Skip to content

Commit cd0e7d3

Browse files
committed
patch for code
1 parent ff4adfb commit cd0e7d3

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/content/changelog/workers-ai/2025-11-25-flux-2-dev-workers-ai.mdx

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,29 @@ curl --request POST \
3030
With the Workers AI binding, you can use it as such:
3131

3232
```javascript
33+
3334
const form = new FormData();
34-
form.append('prompt', 'a sunset at the alps')
35-
form.append('width', 512)
36-
form.append('height', 512)
37-
35+
form.append('prompt', 'a sunset with a dog');
36+
form.append('width', '1024');
37+
form.append('height', '1024');
38+
39+
//this dummy request is temporary hack
40+
//we're pushing a change to address this soon
41+
const formRequest = new Request('http://dummy', {
42+
method: 'POST',
43+
body: form
44+
});
45+
const formStream = formRequest.body;
46+
const formContentType = formRequest.headers.get('content-type') || 'multipart/form-data';
47+
3848
const resp = await env.AI.run("@cf/black-forest-labs/flux-2-dev", {
39-
multipart: {
40-
body: form,
41-
contentType: "multipart/form-data"
42-
}
43-
})
49+
multipart: {
50+
body: formStream,
51+
contentType: formContentType
52+
}
53+
});
54+
55+
```
4456

4557
The parameters you can send to the model are detailed here:
4658

@@ -89,6 +101,7 @@ curl --request POST \
89101
Through Workers AI Binding:
90102

91103
```javascript
104+
92105
//helper function to convert ReadableStream to Blob
93106
async function streamToBlob(stream: ReadableStream, contentType: string): Promise<Blob> {
94107
const reader = stream.getReader();
@@ -112,6 +125,15 @@ const image_blob1 = await streamToBlob(image1.body, "image/png");
112125
form.append('input_image_0', image_blob0)
113126
form.append('input_image_1', image_blob1)
114127
form.append('prompt', 'take the subject of image 1and style it like image 0')
128+
129+
//this dummy request is temporary hack
130+
//we're pushing a change to address this soon
131+
const formRequest = new Request('http://dummy', {
132+
method: 'POST',
133+
body: form
134+
});
135+
const formStream = formRequest.body;
136+
const formContentType = formRequest.headers.get('content-type') || 'multipart/form-data';
115137

116138
const resp = await env.AI.run("@cf/black-forest-labs/flux-2-dev", {
117139
multipart: {

0 commit comments

Comments
 (0)