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
Runs: a text helper that declines leaves the prompt as typed
Adarsh531c75cc4ab7
diff --git a/src/server/english-prompt.ts b/src/server/english-prompt.tsindex bbe2eb54..e58cb61b 100644--- a/src/server/english-prompt.ts+++ b/src/server/english-prompt.ts@@ -40,6 +40,9 @@ Remove the hat and the glasses.Mach den Himmel klar, ohne Wolken, und ändere das Auto nichtMake the sky clear and cloudless, and keep the car the same.`;+/** How a model's refusal starts ("I'm sorry, but…", "I can't help with that", "As an AI…"). */+const REFUSAL = /^(i'?m sorry|i am sorry|sorry|i apologi[sz]e|i (can ?not|can't|cannot|won't|will not|am unable|'m unable|am not able)|unfortunately|as an ai)\b/i;+/** The helper's answer as a prompt: trimmed, a wrapper of quotes or a "Prompt:" label taken off; null when it isn't one. */export function cleanEnglish(answer: string | null | undefined, original: string): string | null {if (!answer) return null;@@ -47,6 +50,8 @@ export function cleanEnglish(answer: string | null | undefined, original: strings = s.replace(/^(english( prompt)?|prompt|translation)\s*:\s*/i, "").trim();if (/^(["“'])[\s\S]*(["”'])$/.test(s) && !/^["“']/.test(original.trim())) s = s.slice(1, -1).trim();if (!s) return null;+ // A model that declines answers with a refusal, never a prompt: the run keeps the words as typed.+ if (REFUSAL.test(s) && !REFUSAL.test(original.trim())) return null;// A prompt, not a chat: far longer than the words given means the model said more than the prompt.if (s.length > original.length * 3 + 200) return null;return s;diff --git a/tests/prompt-language.test.ts b/tests/prompt-language.test.tsindex 22dc7c31..c65aafa6 100644--- a/tests/prompt-language.test.ts+++ b/tests/prompt-language.test.ts@@ -97,6 +97,14 @@ describe("cleanEnglish", () => {expect(cleanEnglish('"Hola" written in neon', '"Hola" escrito en neón')).toBe('"Hola" written in neon');});+ it("gives nothing for a refusal, so the run keeps the words as typed", () => {+ for (const r of ["I'm sorry, but I can't help with that.", "I cannot translate this content.", "I can't assist with that request.", "Sorry, I am unable to do that.", "As an AI, I won't write that."]) expect(cleanEnglish(r, "x")).toBeNull();+ // An answer that only starts like one goes as typed too (the words were the person's anyway)...+ expect(cleanEnglish("Unfortunately rainy street, a man under an umbrella", "x")).toBeNull();+ // ...unless the person's own words start that way.+ expect(cleanEnglish("Sorry sign in neon over a bar", "Sorry sign in neon")).toBe("Sorry sign in neon over a bar");+ });+it("gives nothing for an empty answer", () => {expect(cleanEnglish(" ", "x")).toBeNull();expect(cleanEnglish(null, "x")).toBeNull();