Skip to content

Commit 85c37b8

Browse files
committed
limit max seed value to max
1 parent 23b219e commit 85c37b8

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

MyApp.ServiceInterface/AppExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,17 @@ public static AgentInfo ToAgentInfo(this ComfyAgent from)
350350
}
351351
return to;
352352
}
353+
354+
public static long GetMaxSeedValue(this WorkflowInfo info)
355+
{
356+
return info.Inputs?.Where(x => x.Name is "seed" or "noise_seed")
357+
.Select(x => (long)(x.Max ?? long.MaxValue))
358+
.DefaultIfEmpty(long.MaxValue)
359+
.Min() ?? long.MaxValue;
360+
}
361+
362+
public static long GetNextSeedValue(this WorkflowInfo info)
363+
{
364+
return Random.Shared.NextInt64(0, GetMaxSeedValue(info));
365+
}
353366
}

MyApp.ServiceInterface/ComfyServices.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,17 @@ public async Task<object> Post(RequeueGeneration request)
399399
// If we're retrying an existing generation we need to regenerate the seeds
400400
if (gen.Args?.Count > 0 && (gen.Args.ContainsKey("seed") || gen.Args.ContainsKey("noise_seed")))
401401
{
402+
var workflowVersion = GetWorkflowVersion(Db, gen.WorkflowId, gen.VersionId);
403+
402404
if (gen.Args.TryGetValue("seed", out var seed))
403405
{
404-
gen.Args["seed"] = Random.Shared.NextInt64(0, long.MaxValue);
406+
gen.Args["seed"] = workflowVersion.Info.GetNextSeedValue();
405407
}
406408
if (gen.Args.TryGetValue("noise_seed", out var noiseSeed))
407409
{
408-
gen.Args["noise_seed"] = Random.Shared.NextInt64(0, long.MaxValue);
410+
gen.Args["noise_seed"] = workflowVersion.Info.GetNextSeedValue();
409411
}
410412

411-
var workflowVersion = GetWorkflowVersion(Db, gen.WorkflowId, gen.VersionId);
412413
var (apiPrompt, newWorkflow, _) = await comfyConverter.CreateApiPromptAsync(workflowVersion, gen.Args, agent:null, gen.Id);
413414

414415
gen.Workflow = newWorkflow;

0 commit comments

Comments
 (0)