@@ -30,17 +30,29 @@ curl --request POST \
3030With the Workers AI binding, you can use it as such:
3131
3232``` javascript
33+
3334const 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+
3848const 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
4557The parameters you can send to the model are detailed here:
4658
@@ -89,6 +101,7 @@ curl --request POST \
89101Through Workers AI Binding:
90102
91103``` javascript
104+
92105// helper function to convert ReadableStream to Blob
93106async 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");
112125form .append (' input_image_0' , image_blob0)
113126form .append (' input_image_1' , image_blob1)
114127form .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
116138const resp = await env .AI .run (" @cf/black-forest-labs/flux-2-dev" , {
117139 multipart: {
0 commit comments