Add SwarmUI settings management and portrait generation enhancements

- Introduced new API endpoints for managing SwarmUI settings, including fetching and saving presets and age rules.
- Updated the portrait generation logic to utilize the new settings structure, allowing for dynamic preset selection based on age.
- Enhanced UI components to support SwarmUI settings, including localization for new strings and improved styling for settings sections.
- Added tests to verify the functionality of new settings endpoints and portrait generation behavior.

This commit lays the groundwork for more flexible and user-friendly portrait generation options.
This commit is contained in:
Leonid Pershin
2026-08-20 06:06:45 +03:00
parent e0b7122f3b
commit 5a400be792
32 changed files with 2178 additions and 184 deletions
@@ -22,15 +22,10 @@ public class SwarmUiClientTests
Options.Create(new SwarmUiOptions { BaseUrl = "http://swarm.test", TimeoutSeconds = 30 }),
NullLogger<SwarmUiClient>.Instance);
var settings = new SwarmUiSettings
{
Model = "model.safetensors",
Steps = 8,
CfgScale = 1,
Avatar = new SwarmUiSettings.SwarmUiPreset { Width = 512, Height = 512 },
};
var preset = SwarmUiPresetDefinition.CreateDefault();
var profile = preset.ToProfile(PortraitKind.Avatar);
var bytes = await client.GenerateAsync("a student", "bad", settings, PortraitKind.Avatar, CancellationToken.None);
var bytes = await client.GenerateAsync("a student", "bad", profile, CancellationToken.None);
Assert.Equal([0x89, 0x50, 0x4E, 0x47], bytes.Take(4));
Assert.Contains("/API/GetNewSession", handler.Requests[0]);
@@ -85,18 +80,15 @@ public class SwarmUiClientTests
Options.Create(new SwarmUiOptions { BaseUrl = "http://swarm.test", TimeoutSeconds = 30 }),
NullLogger<SwarmUiClient>.Instance);
var settings = new SwarmUiSettings
{
Model = "model.safetensors",
Steps = 4,
CfgScale = 2,
ClipSkip = 2,
Sampler = "dpmpp_sde",
Scheduler = "karras",
Avatar = new SwarmUiSettings.SwarmUiPreset { Width = 512, Height = 512 },
};
var preset = SwarmUiPresetDefinition.CreateDefault();
preset.Steps = 4;
preset.CfgScale = 2;
preset.ClipSkip = 2;
preset.Sampler = "dpmpp_sde";
preset.Scheduler = "karras";
var profile = preset.ToProfile(PortraitKind.Avatar);
await client.GenerateAsync("a student", "bad", settings, PortraitKind.Avatar, CancellationToken.None);
await client.GenerateAsync("a student", "bad", profile, CancellationToken.None);
using var document = JsonDocument.Parse(handler.GenerateBody!);
Assert.Equal(-2, document.RootElement.GetProperty("clipstopatlayer").GetInt32());