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.

Originals O13: Evolution says its limits in words on every route, and the page says when a direction is cut

Claude5791614f1fdf
diff --git a/src/components/evolution/evolution-tool.tsx b/src/components/evolution/evolution-tool.tsx
index ffb1881d..931c62aa 100644
--- a/src/components/evolution/evolution-tool.tsx
+++ b/src/components/evolution/evolution-tool.tsx
@@ -17,7 +17,7 @@ import { Feed } from "@/components/studio/feed";
import { fileToList, MediaSlot, type SlotValue } from "@/components/studio/media-slot";
import { VideoTrimmer, type TrimRange, type VideoTrimmerHandle } from "@/components/studio/video-trimmer";
import { useEngine, useGenerations } from "@/lib/api";
-import { EVOLUTION, EVOLUTION_DEFAULT_RESOLUTION, EVOLUTION_RESOLUTIONS, INTENSITIES, type Intensity } from "@/lib/catalog/evolution";
+import { DIRECTION_CUT_NOTE, directionPrompt, EVOLUTION, EVOLUTION_DEFAULT_RESOLUTION, EVOLUTION_RESOLUTIONS, INTENSITIES, type Intensity } from "@/lib/catalog/evolution";
import { chainState } from "@/lib/catalog/shorts";
import { downloadHref, downloadName } from "@/lib/library";
import { cn } from "@/lib/utils";
@@ -88,6 +88,9 @@ export function EvolutionTool({ tabs }: { tabs?: React.ReactNode }) {
: null;
const estimate = useEvolutionEstimate(body);
const est = estimate.data && !estimate.isError ? estimate.data : undefined;
+ // The words stay out of the estimate's key, so a direction too long for the models is said here as you type.
+ const cut = useMemo(() => directionPrompt(direction).cut, [direction]);
+ const notes = est ? [...est.notes.filter((n) => n !== DIRECTION_CUT_NOTE), ...(cut ? [DIRECTION_CUT_NOTE] : [])] : [];
const blocker = !clip
? "Add a clip"
@@ -291,9 +294,9 @@ export function EvolutionTool({ tabs }: { tabs?: React.ReactNode }) {
{actions.run.isPending ? <Loader2 className="size-4 animate-spin" /> : <Wand2 className="size-4" />} Evolve
</Button>
</div>
- {est && est.notes.length > 0 && !blocker && (
+ {est && notes.length > 0 && !blocker && (
<ul className="space-y-1 text-[12px] leading-snug text-muted-foreground">
- {est.notes.map((n) => (
+ {notes.map((n) => (
<li key={n} className="flex gap-1.5">
<Sparkles className="mt-0.5 size-3 shrink-0 text-brand-text" />
<span>{n}.</span>
diff --git a/src/lib/catalog/evolution.ts b/src/lib/catalog/evolution.ts
index baeaa51c..6662c930 100644
--- a/src/lib/catalog/evolution.ts
+++ b/src/lib/catalog/evolution.ts
@@ -119,6 +119,9 @@ export function evolutionProblem(o: { engine: Engine; source: Pick<EvolutionSour
const tidy = (s: string) => s.replace(/\s+/g, " ").trim();
+/** Said when a direction is longer than the models take (the estimate's note; the page says it as you type). */
+export const DIRECTION_CUT_NOTE = `Only the first ${EVOLUTION.promptChars.toLocaleString("en")} characters of the direction reach the model, up to the last full sentence`;
+
/** The prompt the models get: the direction, cut after a sentence once it passes EVOLUTION.promptChars. */
export function directionPrompt(direction: string): { text: string; cut: boolean } {
const t = tidy(direction);
diff --git a/src/server/evolution.ts b/src/server/evolution.ts
index 26646753..238ad98a 100644
--- a/src/server/evolution.ts
+++ b/src/server/evolution.ts
@@ -2,6 +2,7 @@ import "server-only";
import { z } from "zod";
import { getModel } from "@/lib/catalog";
import {
+ DIRECTION_CUT_NOTE,
DIRECTION_SYSTEM,
directionRequest,
EVOLUTION,
@@ -40,16 +41,20 @@ export { ShortsError as EvolutionError };
const fileUrl = z.string().startsWith("/api/files/").max(500);
const seconds = z.number().finite().min(0).max(3600);
const intensity = z.enum(["low", "medium", "high"]);
+// Hard caps on what a body may carry, well past the limits: a run over the limits is refused by evolutionProblem in
+// words ("Use up to 40 references"), which a schema failure can't say.
+const DIRECTION_CAP = EVOLUTION.maxDirectionChars * 10;
+const REFERENCES_CAP = EVOLUTION.maxReferences * 10;
/** The body of /api/evolution (and /estimate). */
export const EvolutionBodySchema = z.object({
engine: z.enum(["cloud", "open"]),
intensity: intensity.default("medium"),
/** The creative direction; empty: written before the run (LLM or offline writer). */
- direction: z.string().max(EVOLUTION.maxDirectionChars).optional(),
+ direction: z.string().max(DIRECTION_CAP).optional(),
/** Your few words for the writer, when the direction is left to it. */
idea: z.string().max(2000).optional(),
- references: z.array(fileUrl).max(EVOLUTION.maxReferences).default([]),
+ references: z.array(fileUrl).max(REFERENCES_CAP).default([]),
source: z.object({
url: fileUrl,
name: z.string().max(200).optional(),
@@ -70,7 +75,7 @@ export type EvolutionBody = z.input<typeof EvolutionBodySchema>;
/** The estimate is asked for before the upload finishes: any URL stands in, references may still be uploading. */
export const EvolutionEstimateSchema = EvolutionBodySchema.extend({
source: EvolutionBodySchema.shape.source.extend({ url: z.string().max(500).default("/api/files/placeholder.mp4") }),
- references: z.array(z.string().max(500)).max(EVOLUTION.maxReferences).default([]),
+ references: z.array(z.string().max(500)).max(REFERENCES_CAP).default([]),
});
/** The body of /api/evolution/direction: what the writer works from. */
@@ -78,7 +83,7 @@ export const DirectionSchema = z.object({
engine: z.enum(["cloud", "open"]),
intensity: intensity.default("medium"),
idea: z.string().max(2000).optional(),
- references: z.array(fileUrl).max(EVOLUTION.maxReferences).default([]),
+ references: z.array(fileUrl).max(REFERENCES_CAP).default([]),
/** A frame of the clip the browser grabbed (a JPEG or PNG data URL, at most about 1.5 MB). */
frame: z
.string()
@@ -130,6 +135,7 @@ async function referenceImages(urls: string[], max: number) {
*/
export async function writeDirection(body: z.infer<typeof DirectionSchema>): Promise<DirectionAnswer> {
mustMatchMode(body.engine);
+ if (body.references.length > EVOLUTION.maxReferences) throw new ShortsError(`Use up to ${EVOLUTION.maxReferences} references`, 422);
const offline = (why: string): DirectionAnswer => ({ direction: offlineDirection({ intensity: body.intensity as Intensity, idea: body.idea, references: body.references.length }), by: "offline", why });
if (getSetting("demoMode") === "on") return offline("demo mode");
const textModel = getModel(body.engine === "open" ? "oss-text-llm" : "text-llm");
@@ -240,7 +246,7 @@ export function estimateEvolution(body: z.infer<typeof EvolutionEstimateSchema>)
// The price doesn't depend on the words: a stand-in direction when none is written yet.
const { input, notes } = planInput(body, {}, body.direction?.trim() || "the same scene", false);
const plan = planEvolution(input);
- if (plan.cut) notes.push(`Only the first ${EVOLUTION.promptChars.toLocaleString("en")} characters of the direction reach the model`);
+ if (plan.cut) notes.push(DIRECTION_CUT_NOTE);
return {
...price(plan.steps),
modelName: getModel(EVOLUTION.model)?.name ?? "Fuobe Evolution",
diff --git a/tests/evolution-api.test.ts b/tests/evolution-api.test.ts
index bb39b89b..1ba116d3 100644
--- a/tests/evolution-api.test.ts
+++ b/tests/evolution-api.test.ts
@@ -84,12 +84,33 @@ describe("Evolution: estimates", () => {
expect(await say(body({ range: { start: 0, end: 3 } }))).toBe("Select at least 4 seconds");
expect(await say(body({ engine: "open", resolution: "1080p" }))).toMatch(/isn't offered on your GPU/);
expect(await say({ engine: "cloud" })).toBe("Add a clip and pick how much should change");
+ // Past the limits, the limit is said (not the schema's generic refusal), on every route.
+ expect(await say(body({ direction: "x".repeat(10_001) }))).toBe("Keep the direction under 10,000 characters");
+ expect(await say(body({ references: Array(41).fill(ref) }))).toBe("Use up to 40 references");
+ const create = await createRoute.POST(json(body({ references: Array(41).fill(ref) })));
+ expect([create.status, (await create.json()).error]).toEqual([422, "Use up to 40 references"]);
+ const long = await createRoute.POST(json(body({ direction: "A night market. ".repeat(700) })));
+ expect([long.status, (await long.json()).error]).toEqual([422, "Keep the direction under 10,000 characters"]);
+ const write = await directionRoute.POST(json({ engine: "cloud", references: Array(41).fill(ref) }));
+ expect([write.status, (await write.json()).error]).toEqual([422, "Use up to 40 references"]);
changeAccess([{ kind: "model", id: "fuobe-evolution", on: false }]);
expect(await say(body())).toBe("Fuobe Evolution is switched off in the cloud in Settings → Models & licences");
changeAccess([{ kind: "reset" }]);
});
});
+describe("Evolution: a direction longer than the models take", () => {
+ it("the estimate says only its first sentences reach the model, and the page says the same words", async () => {
+ const { DIRECTION_CUT_NOTE, directionPrompt } = await import("@/lib/catalog/evolution");
+ const direction = "A night market in the rain. ".repeat(80);
+ expect(directionPrompt(direction).cut).toBe(true);
+ const est = await (await estimateRoute.POST(json(body({ direction })))).json();
+ expect(est.notes).toContain(DIRECTION_CUT_NOTE);
+ const short = await (await estimateRoute.POST(json(body({ direction: "A night market in the rain." })))).json();
+ expect(short.notes).not.toContain(DIRECTION_CUT_NOTE);
+ });
+});
+
describe("Evolution: the direction", () => {
it("no LLM running: Fuobe's offline writer, from the intensity, your words and the references", async () => {
const res = await directionRoute.POST(json({ engine: "cloud", intensity: "high", idea: "a western at high noon", references: [ref, ref] }));