Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Generations preview: say what the route runs — its endpoint, the final prompt and the LoRAs it loads

Claude12d6e9dbff17
diff --git a/src/lib/catalog/plan.ts b/src/lib/catalog/plan.ts
index f35e0ad7..fcb6f34c 100644
--- a/src/lib/catalog/plan.ts
+++ b/src/lib/catalog/plan.ts
@@ -459,6 +459,23 @@ export function pricingAt(p: Pricing, now = Date.now()): Pricing {
*/
const CLIP_LENGTH_OPS = new Set<Operation>(["upscale-video", "interpolate", "sdr-to-hdr", "export-video"]);
+/**
+ * Which of a plan's LoRAs a route really applies, and why the others are left out: ComfyUI loads every file
+ * (injectLoras); fal switches to the model's LoRA endpoint for LoRAs with a URL; other routes take none.
+ * The preview reports it, so a caller (the evaluation harness) records the recipe that ran, not the one it asked for.
+ */
+export function routeLoras(route: Pick<ModelRoute, "provider" | "loraEndpoint">, loras: LoraRef[]): { applied: LoraRef[]; dropped: { file: string; reason: string }[] } {
+ if (route.provider === "comfyui") return { applied: loras, dropped: [] };
+ const applied: LoraRef[] = [];
+ const dropped: { file: string; reason: string }[] = [];
+ for (const l of loras) {
+ if (route.provider !== "fal" || !route.loraEndpoint) dropped.push({ file: l.file, reason: "this route takes no LoRAs" });
+ else if (!l.url) dropped.push({ file: l.file, reason: "no URL to send to the LoRA endpoint" });
+ else applied.push(l);
+ }
+ return { applied, dropped };
+}
+
/** Rough USD estimate for a plan (BYO-key cloud runs). Open-source runs are free. */
export function estimateCost(model: ModelDef, params: GenParams, jobs = 1, op?: Operation): number | null {
if (model.engine === "open" || !model.pricing) return model.engine === "open" ? 0 : null;
diff --git a/src/server/generations.ts b/src/server/generations.ts
index 3bfdbeda..7a06edcf 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -10,7 +10,7 @@ import { cueText, type Cue } from "@/lib/cues";
import { HELPER_FEATURES, HELPER_SUFFIX, isReviewStatus, type AssetUse, type ReviewFilter } from "@/lib/library";
import { upscaleTier } from "@/lib/av/upscale";
import { chainedWaitMessage, keyframeChain } from "@/lib/catalog/keyframes";
-import { estimateCost, inferOperation, planGeneration, routesFor } from "@/lib/catalog/plan";
+import { estimateCost, inferOperation, planGeneration, routeLoras, routesFor } from "@/lib/catalog/plan";
import { keepMatte } from "@/lib/catalog/payload";
import {
LAST_FRAME_CHAIN,
@@ -436,8 +436,21 @@ function prepare(original: GenerationRequest) {
/** What a request would run as — model, operation, job count and cost — without starting it. */
export function previewGeneration(req: GenerationRequest) {
- const { plan, demo, providerId, cost } = prepare(req);
- return { model: plan.model, op: plan.op, jobs: plan.jobs, outputs: plan.jobs * plan.perJobOutputs, demo, providerId, costUsd: cost === null ? null : cost * plan.jobs };
+ const { plan, route, demo, providerId, cost } = prepare(req);
+ const loras = routeLoras(route, plan.loras);
+ return {
+ model: plan.model,
+ op: plan.op,
+ jobs: plan.jobs,
+ outputs: plan.jobs * plan.perJobOutputs,
+ demo,
+ providerId,
+ costUsd: cost === null ? null : cost * plan.jobs,
+ // What the route runs (the evaluation harness records it): the provider endpoint, the final prompt and the LoRAs it loads.
+ route: { provider: route.provider, endpoint: loras.applied.length && route.provider === "fal" && route.loraEndpoint ? route.loraEndpoint : route.endpoint },
+ prompt: plan.prompt,
+ loras,
+ };
}
/** Preview a step that will wait for `deps` earlier steps: validated with placeholders in its chain slots, as createGenerations does. */
diff --git a/tests/eval-api.test.ts b/tests/eval-api.test.ts
index d8bcd558..53a92250 100644
--- a/tests/eval-api.test.ts
+++ b/tests/eval-api.test.ts
@@ -3,9 +3,9 @@ import os from "node:os";
import path from "node:path";
import { afterAll, describe, expect, it, vi } from "vitest";
import { getModel, getPreset } from "@/lib/catalog";
-import { planGeneration } from "@/lib/catalog/plan";
+import { planGeneration, routeLoras } from "@/lib/catalog/plan";
-/** The REST seam the evaluation harness (scripts/eval) needs: a recipe's LoRAs on POST /api/generations. */
+/** The REST seams the evaluation harness (scripts/eval) needs: a recipe's LoRAs on POST /api/generations, and a preview that says which ones run. */
vi.mock("next/server", async (importOriginal) => ({ ...(await importOriginal<typeof import("next/server")>()), connection: async () => {} }));
@@ -76,3 +76,32 @@ describe("planGeneration with request LoRAs", () => {
expect(none.prompt).toBe(full.prompt);
});
});
+
+describe("the preview says what the route runs", () => {
+ const hf = { file: "AWPortrait-Z.safetensors", url: "https://huggingface.co/Shakker-Labs/AWPortrait-Z/resolve/main/AWPortrait-Z.safetensors", strength: 0.6 };
+ const local = { file: "civitai-2463391-hardflash.safetensors", strength: 0.7, trigger: "hardflashy" };
+
+ it("routeLoras: ComfyUI loads every file, fal's LoRA endpoint the ones with a URL, other routes none", () => {
+ expect(routeLoras({ provider: "comfyui" }, [hf, local])).toEqual({ applied: [hf, local], dropped: [] });
+ expect(routeLoras({ provider: "fal", loraEndpoint: "fal-ai/z-image/turbo/lora" }, [hf, local])).toEqual({
+ applied: [hf],
+ dropped: [{ file: local.file, reason: "no URL to send to the LoRA endpoint" }],
+ });
+ expect(routeLoras({ provider: "fal" }, [hf]).dropped).toEqual([{ file: hf.file, reason: "this route takes no LoRAs" }]);
+ expect(routeLoras({ provider: "replicate", loraEndpoint: "x" }, [hf]).applied).toEqual([]);
+ });
+
+ it("returns the endpoint, the final prompt and the LoRAs on the open engine (demo mode, no ComfyUI here)", async () => {
+ const r = await post({ ...soul, loras: [hf, local] });
+ expect(r.status).toBe(200);
+ expect(r.body).toMatchObject({ demo: true, route: { provider: "comfyui", endpoint: "z-image-turbo-t2i" }, loras: { applied: [hf, local], dropped: [] } });
+ expect(r.body.prompt).toContain("a portrait in soft daylight");
+ });
+
+ it("on the cloud: the LoRA endpoint when a LoRA has a URL, and what was left out", async () => {
+ const r = await post({ ...soul, modelId: "z-image-turbo-cloud", loras: [hf, local] });
+ expect(r.body).toMatchObject({ route: { provider: "fal", endpoint: "fal-ai/z-image/turbo/lora" }, loras: { applied: [hf], dropped: [{ file: local.file }] } });
+ const none = await post({ ...soul, modelId: "z-image-turbo-cloud" });
+ expect(none.body.route).toMatchObject({ endpoint: expect.not.stringMatching(/lora/) });
+ });
+});