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.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Generations API: take a recipe's LoRAs (for the evaluation harness); a LoRA at strength 0 is left out
Claudeedaa5c7c7c13
diff --git a/src/app/api/generations/route.ts b/src/app/api/generations/route.tsindex d78e48fa..5ad9e4c2 100644--- a/src/app/api/generations/route.ts+++ b/src/app/api/generations/route.ts@@ -83,6 +83,25 @@ const RequestSchema = z.object({presetOptions: z.record(z.string(), z.string()).optional(),presetStrength: z.number().min(0).max(1).optional(),mix: z.object({ presetId: z.string().max(120), strength: z.number().min(0).max(1) }).optional(),+ // A recipe's LoRAs (the evaluation harness, scripts/eval): added after the preset's own. On ComfyUI `file` must+ // already be in models/loras (ComfyUI checks the name against its list); a cloud LoRA endpoint takes `url`.+ loras: z+ .array(+ z.object({+ file: z+ .string()+ .min(1)+ .max(200)+ .regex(/^[\w ()+,.@-]+(\/[\w ()+,.@-]+)*$/, "a file name in ComfyUI's models/loras")+ .refine((f) => !f.split("/").includes(".."), "a file name in ComfyUI's models/loras"),+ url: z.string().max(2000).regex(/^https:\/\//, "an https:// link").optional(),+ strength: z.number().min(-4).max(4).optional(),+ trigger: z.string().max(200).optional(),+ target: z.enum(["high", "low", "both"]).optional(),+ }),+ )+ .max(8)+ .optional(),// Image studio: the Color signature / Moodboard picks (its sentences join the prompt on the server).signature: SignatureSchema,// What a tool calls its result (Trim · 0:01.0–0:02.5, Captions · Karaoke), shown instead of the prompt.diff --git a/src/lib/catalog/plan.ts b/src/lib/catalog/plan.tsindex 46f2b694..f35e0ad7 100644--- a/src/lib/catalog/plan.ts+++ b/src/lib/catalog/plan.ts@@ -197,6 +197,8 @@ export function planGeneration(}if (req.loras?.length) loras = [...loras, ...req.loras];+ // A LoRA at strength 0 changes nothing: leave it out, so preset strength 0 is the preset's prompt alone (and its file isn't needed).+ loras = loras.filter((l) => (l.strength ?? 1) !== 0);// Multi-shot: the clip is as long as its shots, and models without per-shot prompts get them written out.const shots = params.shots?.filter((s) => s.prompt.trim());diff --git a/src/lib/catalog/types.ts b/src/lib/catalog/types.tsindex a4ca85b1..56c422fa 100644--- a/src/lib/catalog/types.ts+++ b/src/lib/catalog/types.ts@@ -690,7 +690,7 @@ export interface GenerationRequest {presetStrength?: number;/** Higgsfield's Mix: a second motion or effect on top of the first, with its own strength. */mix?: { presetId: string; strength: number };- /** Server-side only: LoRAs added by @element mentions (trained identities). */+ /** LoRAs added by @element mentions (trained identities, server-side), or a recipe's LoRAs sent by the evaluation harness. */loras?: LoraRef[];/** Chained jobs: where the previous job's image goes among `inputs.images` (one dependency). */chainFrom?: "first" | "last";diff --git a/tests/eval-api.test.ts b/tests/eval-api.test.tsnew file mode 100644index 00000000..d8bcd558--- /dev/null+++ b/tests/eval-api.test.ts@@ -0,0 +1,78 @@+import fs from "node:fs";+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";++/** The REST seam the evaluation harness (scripts/eval) needs: a recipe's LoRAs on POST /api/generations. */++vi.mock("next/server", async (importOriginal) => ({ ...(await importOriginal<typeof import("next/server")>()), connection: async () => {} }));++const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-eval-api-"));+process.env.FUOBE_DATA_DIR = dir;+process.env.COMFYUI_URL = "http://127.0.0.1:9";+process.env.OLLAMA_URL = "http://127.0.0.1:9";+const { POST } = await import("@/app/api/generations/route");+afterAll(() => fs.rmSync(dir, { recursive: true, force: true }));++const post = async (body: unknown, preview = true) => {+ const res = await POST(new Request(`http://localhost/api/generations${preview ? "?preview=1" : ""}`, { method: "POST", body: JSON.stringify(body) }));+ return { status: res.status, body: (await res.json()) as Record<string, unknown> & { error?: string; items?: { request: { loras?: unknown[] } }[] } };+};++const soul = { feature: "eval", modelId: "oss-z-image-turbo", prompt: "a portrait in soft daylight", params: { seed: 1001 } };++describe("POST /api/generations with a recipe's LoRAs", () => {+ it("takes LoRAs by ComfyUI file name with an optional https URL, strength, trigger and Wan expert", async () => {+ const loras = [+ { file: "AWPortrait-Z.safetensors", url: "https://huggingface.co/Shakker-Labs/AWPortrait-Z/resolve/main/AWPortrait-Z.safetensors", strength: 0.6 },+ { file: "civitai-2463391-hardflash.safetensors", strength: 0.7, trigger: "hardflashy" },+ { file: "wan/camera-overhead-high.safetensors", strength: 1, target: "high" },+ ];+ expect((await post({ ...soul, loras })).status).toBe(200);+ const made = await post({ ...soul, loras }, false);+ expect(made.status).toBe(201);+ // The stored request keeps them, so Reuse and the harness's records show the recipe that ran.+ expect(made.body.items?.[0].request.loras).toEqual(loras);+ });++ it("refuses names that leave models/loras, links that aren't https and strengths out of range", async () => {+ for (const bad of [+ { file: "../../etc/passwd" },+ { file: "loras/../../x.safetensors" },+ { file: "/abs.safetensors" },+ { file: "ok.safetensors", url: "http://insecure.example/x.safetensors" },+ { file: "ok.safetensors", url: "file:///etc/passwd" },+ { file: "ok.safetensors", strength: 9 },+ { file: "ok.safetensors", target: "middle" },+ ]) {+ const r = await post({ ...soul, loras: [bad] });+ expect(r.status, JSON.stringify(bad)).toBe(400);+ expect(r.body.error).toMatch(/^loras\./);+ }+ expect((await post({ ...soul, loras: Array.from({ length: 9 }, (_, i) => ({ file: `l${i}.safetensors` })) })).status).toBe(400);+ });+});++describe("planGeneration with request LoRAs", () => {+ it("adds them after the preset's own and drops any at strength 0", () => {+ const plan = planGeneration(+ { ...soul, loras: [{ file: "a.safetensors", strength: 0.5 }, { file: "off.safetensors", strength: 0 }] },+ getModel,+ getPreset,+ );+ expect(plan.loras.map((l) => l.file)).toEqual(["a.safetensors"]);+ });++ it("preset strength 0 is the motion's prompt without its LoRAs (the harness's prompt-only baseline)", () => {+ const motion = getPreset("motion-dolly-in");+ expect(motion?.open?.loras?.length, "a motion with an open LoRA").toBeGreaterThan(0);+ const req = { feature: "eval", presetId: motion!.id, modelId: motion!.open!.modelId, prompt: "a cyclist on a coastal road", inputs: { images: ["start.png"] } };+ const full = planGeneration(req, getModel, getPreset);+ const none = planGeneration({ ...req, presetStrength: 0 }, getModel, getPreset);+ expect(full.loras.length).toBeGreaterThan(0);+ expect(none.loras).toEqual([]);+ expect(none.prompt).toBe(full.prompt);+ });+});