15 Commits

Author SHA1 Message Date
github-actions[bot] e063911178 format: auto-format code [skip ci] 2026-05-17 16:40:09 +00:00
github-actions[bot] 592b6858eb style: auto-fix ruff warnings [skip ci] 2026-05-17 16:39:54 +00:00
aladac 6935491081 feat(generate): validate model availability against live ComfyUI before queueing
Catches mismatches between local intent and what's actually loaded on the
ComfyUI host. Replaces ComfyUI's generic 400 'prompt_outputs_failed_validation'
with a clear "model X not available on host — did you mean Y?" suggestion.

Why: when a user types `tsr generate -m getphatFLUXReality_v5Hardcore` but
only v11Softcore is installed, they got a 30-line raw API error buried in
node validation output. Now they get one red line plus three fuzzy-matched
candidates from the actual loader bucket.

Implementation:
- Extends get_loaded_models() in comfyui.py to include the diffusion_models
  bucket (UNETLoader -> unet_name). Previously only checkpoints, loras, vae,
  clip, controlnet, upscale_models were exposed.
- New _validate_model_available() helper in cli.py runs after family
  detection, before prompt enhancement. Maps family -> loader bucket:
  flux_unet / flux2_klein -> diffusion_models/, else checkpoints/. Uses
  difflib.get_close_matches for the "did you mean" hint.
- Validates LoRA presence too when -l is passed.
- Special hint: if the requested file IS in checkpoints/ but the family
  requires diffusion_models/, suggests the symlink command the user needs
  to run on the host. Common case for newly-uploaded UNet-only checkpoints.
- Network failures are non-fatal — falls through to let ComfyUI surface
  the error itself rather than blocking on a stale endpoint.
- Skipped in --json mode (machine callers) and --remote dispatches (the
  server validates remotely).

8 new tests covering: unknown model in checkpoints bucket, unknown in
diffusion_models, flux2_klein routing, happy path, missing LoRA, network
failure, symlink hint, and a source-level check that the
diffusion_models bucket is wired into get_loaded_models.

259 -> 267 tests.
2026-05-17 18:37:13 +02:00
aladac b7263d1229 feat(workflow): support Flux.2 Klein 9B checkpoints (CLIPLoader type=flux2)
Adds a `flux2_klein` model family for Black Forest Labs' Flux.2 Klein 9B
release. Different architecture from Flux.1 D — required a separate
workflow rather than extending flux_unet.

Architecture differences from Flux.1 D:
- Single Qwen3-8B text encoder via CLIPLoader(type=flux2), producing
  12288-dim conditioning (3 stacked hidden layers). NOT DualCLIPLoader.
- EmptyFlux2LatentImage instead of EmptySD3LatentImage (different
  latent shape).
- Custom-sampling pipeline: Flux2Scheduler -> SIGMAS, fed into
  SamplerCustomAdvanced together with BasicGuider + RandomNoise +
  KSamplerSelect. No standalone KSampler node, so the caller's
  scheduler argument is ignored.
- Dedicated VAE: flux2-vae.safetensors (not Flux.1's ae.safetensors).

Detection:
- New FLUX2_KLEIN_PATTERNS constant lists known Klein filenames
  ("lust_", "moodydesire"). _is_flux2_klein() checks base_model field
  first ("flux.2 klein" / "flux2 klein") then filename pattern.
- detect_model_family() runs the Klein check BEFORE flux_unet, so
  Klein checkpoints that also match UNet-only patterns (lust_v10,
  moodyDesireMix) correctly route to flux2_klein.

Affected checkpoints reclassified from flux_unet -> flux2_klein:
- lust_v10.safetensors (Flux.2 Klein 9B-base per CivitAI DB)
- moodyDesireMix_v20PRO.safetensors (Flux.2 Klein 9B)

Still flux_unet (genuinely Flux.1 D UNet-only):
- cyberrealisticFlux_v25, fcFluxPonyPerfectBase,
  getphatFLUXReality_v11Softcore.

Required ComfyUI host setup (one-time):
- /home/madcat/comfyui/models/text_encoders/qwen_3_8b_fp8mixed.safetensors
  (8.1 GB, from Comfy-Org/vae-text-encorder-for-flux-klein-9b on HF)
- /home/madcat/comfyui/models/vae/flux2-vae.safetensors (321 MB)

Verified end-to-end on madcat: lust_v10 generated successfully through
the new flux2_klein workflow (~85s per image at 1024x1024, 20 steps).

7 new tests; 253 -> 259 total. Existing flux_unet tests retargeted to
genuine Flux.1 D checkpoints (getphat, fcFluxPony, cyberrealisticFlux).
2026-05-17 18:22:23 +02:00
aladac 3e04929515 feat(workflow): support UNet-only Flux.1 D checkpoints via DualCLIPLoader
Adds a `flux_unet` model family for Flux.1 D checkpoints that ship only the
UNet weights (no baked-in CLIP/T5/VAE) and require external encoder loading.

Affected checkpoints: lust_v10, cyberrealisticFlux_v25,
getphatFLUXReality_v11Softcore, moodyDesireMix_v20PRO,
fcFluxPonyPerfectBase. These live in `models/diffusion_models/` (or
`models/unet/`) on the ComfyUI host and are loaded via UNETLoader instead
of CheckpointLoaderSimple.

Detection:
- New `FLUX_UNET_ONLY_PATTERNS` constant in config.py lists known
  UNet-only filename substrings.
- `detect_model_family()` returns `flux_unet` when any pattern matches,
  taking precedence over base_model field (same architecture-override
  pattern used for FluxPony hybrids).

Workflow:
- New flux_unet workflow in comfyui.py uses UNETLoader + DualCLIPLoader
  (clip_l.safetensors + t5xxl_fp16.safetensors, type=flux) + VAELoader
  (ae.safetensors) wired into the same Flux KSampler graph as the
  monolithic flux family.
- Family defaults inherit from flux (sampler/scheduler/steps/cfg) with
  external_clip flag set.

Smoke-tested end-to-end on madcat with getphatFLUXReality_v11Softcore
producing valid output. Flux.2 Klein checkpoints (lust_v10,
moodyDesireMix) still fail because they require a different text encoder
(qwen_3_8b) — see follow-up commit.

13 new tests; 240 -> 253 total.
2026-05-17 18:15:33 +02:00
aladac 338a7fe267 fix(generate): dispatch hybrid Flux models to Flux workflow
Models like gonzalomoXLFluxPony are architecturally Flux but CivitAI
tags them as 'Pony', causing the SDXL workflow to be sent to ComfyUI
which fails validation. The filename now overrides base_model when it
contains 'flux'.

Also adds:
- Full Flux Dev/Schnell workflow template (ModelSamplingFlux,
  FluxGuidance, ConditioningZeroOut, EmptySD3LatentImage); KSampler
  cfg locked to 1.0, caller cfg routed to FluxGuidance
- --family/-F flag to manually override family detection
- queue_prompt now surfaces ComfyUI node_errors from 400 responses
- Tests for Flux workflow builder (8 cases) and updated family defaults
2026-05-17 15:50:25 +02:00
aladac 7162db1ab9 dynamic checkpoint presets with orientation, correct VAEs, and auto-resolved sampler/scheduler/cfg/steps 2026-04-20 22:08:01 +02:00
aladac 2a704aa677 Add model family-specific sampler, scheduler, and VAE defaults
- Add sampler/scheduler/steps/vae to MODEL_FAMILY_DEFAULTS for all families
- Add zimage family detection for ZImageTurbo models
- Flux and zimage families use ae.safetensors VAE
- SD 1.5 families use checkpoint built-in VAE
- SDXL families use sdxl_vae.safetensors
- API auto-applies family defaults when request uses default values

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-20 09:22:41 +01:00
aladac 372133edcc Update 2026-03-20 09:07 2026-03-20 09:07:19 +01:00
Adam Ladachowski 574cdb6abd Add configurable model paths
- Add [paths] section to config.toml for custom model directories
- Add get_model_paths() function that merges config with defaults
- Update get_default_output_path() to check config first
- Add --set-path option to tsr config command
- Update download_routes.py to use centralized path function
- Add tests for path configuration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 13:40:45 +01:00
Adam Ladachowski e4fc392a90 Expand server test coverage from 66% to 73%
Add comprehensive tests for:
- Download routes helper functions (_format_size, _get_output_dir, _resolve_version_id)
- Background download task execution (success, failure, exception handling)
- Progress callback with different sizes (bytes, KB, MB, GB)
- Auto-linking downloaded files to CivitAI
- Database file lookup and linking with CivitAI matches
- CivitAI cache failure handling
- Gallery edge cases and metadata operations
- Server initialization and OpenAPI schema

Server module coverage now:
- auth.py: 100%
- civitai_routes.py: 98%
- db_routes.py: 97%
- download_routes.py: 98%
- gallery_routes.py: 98%
- gallery.py: 95%

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-15 19:11:25 +01:00
Adam Ladachowski 9f8d8d6fcd Add comprehensive tests, coverage 21% → 74% 2026-02-03 23:10:30 +01:00
Adam Ladachowski 5588370a43 [Update] [2026-02-03 22:57:52] 10 files 2026-02-03 22:57:52 +01:00
Adam Ladachowski 2b62987a0c 💬 Commit message: Update 2026-02-03 20:55:19, 5 files 2026-02-03 20:55:19 +01:00
Adam Ladachowski da5bdc5a06 💬 Commit message: Update 2026-02-03 20:53:31, 12 files 2026-02-03 20:53:31 +01:00