Skip to content

Commit 7dd8c33

Browse files
committed
Workers AI - Added seed parameter to Flux-1-Schnell model and examples
1 parent f202f1f commit 7dd8c33

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/components/models/code/Flux-1-Schnell.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default {
2020
async fetch(request, env): Promise<Response> {
2121
const response = await env.AI.run('@cf/black-forest-labs/flux-1-schnell', {
2222
prompt: 'a cyberpunk lizard',
23+
seed: Math.floor(Math.random() * 10)
2324
});
2425
// response.image is base64 encoded which can be used directly as an <img src=""> data URI
2526
const dataURI = \`data:image/jpeg;charset=utf-8;base64,\${response.image}\`;
@@ -38,6 +39,7 @@ export default {
3839
async fetch(request, env): Promise<Response> {
3940
const response = await env.AI.run('@cf/black-forest-labs/flux-1-schnell', {
4041
prompt: 'a cyberpunk lizard',
42+
seed: Math.floor(Math.random() * 10)
4143
});
4244
// Convert from base64 string
4345
const binaryString = atob(response.image);
@@ -56,7 +58,7 @@ const curl = `
5658
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/${name} \\
5759
-X POST \\
5860
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \\
59-
-d '{ "prompt": "cyberpunk cat" }'
61+
-d '{ "prompt": "cyberpunk cat", "seed": "Put a different number on each call" }'
6062
`;
6163
---
6264

src/content/workers-ai-models/flux-1-schnell.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
"default": 4,
4343
"maximum": 8,
4444
"description": "The number of diffusion steps; higher values can improve quality but take longer."
45+
},
46+
"seed": {
47+
"type": "integer",
48+
"default": 1,
49+
"maximum": 8,
50+
"description": "A positive integer that controls randomness. Using the same seed value will produce identical images, while different seeds create variations."
4551
}
4652
},
4753
"required": [

0 commit comments

Comments
 (0)