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.

Chat: the free model calls make when asked, and asks for a jingle or a poster are read directly

Adarsh2e172bd1e72b
diff --git a/src/lib/chat/make-intent.ts b/src/lib/chat/make-intent.ts
index 5cc9dc91..acfdff3e 100644
--- a/src/lib/chat/make-intent.ts
+++ b/src/lib/chat/make-intent.ts
@@ -19,9 +19,18 @@ const START = new RegExp(`^${POLITE}${MAKE_VERBS}\\b`, "i");
/** Words that make it a conversation about making, not a request to make ("how do I make a reel?"). */
const TALK = /^(?:how|what|why|when|where|which|who|should|is|are|do|does|can i|could i|tips|ideas?|explain|tell me|write|draft|brainstorm|suggest|help me (?:think|plan|write|decide))\b/i;
+/**
+ * Hindi and Hinglish asks ("ek photo banao", "गाना बनाओ") are left to the model's make tool, which writes what to make as
+ * a rich description; read here, the words would go to the picture model as they are.
+ */
+
+/** "Can I get a jingle for…", "I need a poster for…": asking for a thing that can be made. */
+const ASK_FOR = /^(?:(?:hey|hi|ok|okay|so|please)[,!.]?\s+)*(?:(?:can|could|may) (?:i|we) (?:get|have)|i (?:need|want|would like|'d like)|we need)\s+(?:a|an|some|one|two|three|four|five|\d+|my|our)\b/;
+
export function wantsToMake(text: string, hasPicture = false): boolean {
const t = text.trim().toLowerCase().replace(/\s+/g, " ");
if (!t) return false;
+ if (ASK_FOR.test(t) && MADE.test(t) && !/\b(ideas?|tips|advice|help|feedback|suggestions?|names?|captions?|lyrics|scripts?)\b/.test(t)) return true;
if (TALK.test(t) && !/^(?:can|could|would|will) you (?:please )?(?:make|create|generate|render|draw|design|animate)\b/.test(t)) return false;
const stripped = t.replace(new RegExp(`^${POLITE}`, "i"), "");
if (hasPicture && EDIT.test(stripped)) return true;
diff --git a/src/lib/chat/prompt.ts b/src/lib/chat/prompt.ts
index 34ff8034..1389957c 100644
--- a/src/lib/chat/prompt.ts
+++ b/src/lib/chat/prompt.ts
@@ -37,7 +37,7 @@ Prompt (image): one rich line describing the shot to make (subject, setting, lig
Use "Prompt (video):" instead for a moving idea (describe the motion and camera move in order), and "Prompt (music):" for a song or track (genre, mood, instruments, tempo).
Every idea ends with exactly one Prompt line.`;
-const CHAT_EXTRA = `When an idea for an image, a video or a song comes up, you may end with one line "Prompt (image): …" (or video, or music) so the person can make it in one tap.`;
+export const CHAT_EXTRA = `When an idea for an image, a video or a song comes up, you may end with one line "Prompt (image): …" (or video, or music) so the person can make it in one tap.`;
const CHARACTER_RULES = `Stay in character at all times and write as the character, in the first person, in present tense.
Put actions and scene details in *asterisks*. Keep replies to one to three short paragraphs and leave room for the user to act.
diff --git a/src/server/chat/backend.ts b/src/server/chat/backend.ts
index 3bf8bb57..fdc2328d 100644
--- a/src/server/chat/backend.ts
+++ b/src/server/chat/backend.ts
@@ -1,5 +1,5 @@
import "server-only";
-import { alternate, fitHistory, summaryAsk, tidyReply, transcript, type ChatTurn } from "@/lib/chat/prompt";
+import { alternate, CHAT_EXTRA, fitHistory, summaryAsk, tidyReply, transcript, type ChatTurn } from "@/lib/chat/prompt";
import type { ChatEngine, ChatErrorCode } from "@/lib/chat/types";
import { readSse } from "../llm/sse";
import { runAsTenant } from "../tenant";
@@ -51,7 +51,7 @@ const MAKE_TOOL: HelperTool = {
function: {
name: "make",
description:
- "Make something for the person when they ask for it to be made: a picture, a video clip, a music track or a voice-over. The app shows them a plan with the price to approve. Only when they ask to make it now, never for questions or advice about making things.",
+ "Make a picture, video clip, music track or voice-over the person asks for. Call it as soon as they ask you to make, create, generate, draw, design, compose, record or show something (also banao, bana do, बनाओ, बनाकर दो): the app shows a plan with the price to approve, so don't ask first or offer options. Never for questions, tips, explanations, opinions, ideas lists, stories, games, role-play, or text to write (lyrics, captions, scripts).",
parameters: {
type: "object",
properties: {
@@ -63,7 +63,14 @@ const MAKE_TOOL: HelperTool = {
},
};
-const MAKE_HINT = "When the person asks you to make a picture, a video, a music track or a voice-over now, call the make tool with what to make; don't describe it in words instead.";
+const MAKE_HINT =
+ "When the person asks you to make, create, generate, draw, design, compose, record or show them a picture, video, song, jingle, beat or voice-over (in any language, including Hindi and Hinglish), call the make tool right away with a rich description; don't reply with ideas or options first. For questions, advice, ideas, writing, stories or play, answer in words and call no tool.";
+
+/**
+ * The system prompt when the make tool is offered: the line that offers "Prompt (image): …" endings competes with the
+ * tool (measured on the free model), so it gives way to the hint.
+ */
+const withMakeTool = (system: string) => `${system.replace(`\n\n${CHAT_EXTRA}`, "").replace(CHAT_EXTRA, "")}\n\n${MAKE_HINT}`;
function makeOf(calls: HelperCall[] | undefined): MakeCall | null {
const c = calls?.find((x) => x.name === "make");
@@ -144,7 +151,7 @@ async function siteTry(ask: ReplyAsk, waitMs: number): Promise<ReplyAnswer | "bu
const tools = ask.makeTool && freeHelperState(Date.now(), { chat: true, tools: true, vision }) !== "absent";
const a = await askHelper({
task: "chat",
- system: tools ? `${ask.system}\n\n${MAKE_HINT}` : ask.system,
+ system: tools ? withMakeTool(ask.system) : ask.system,
messages,
...(tools && { tools: [MAKE_TOOL], tool_choice: "auto" as const }),
sampling: ask.temperature === undefined ? undefined : { temperature: ask.temperature },
diff --git a/tests/chat.test.ts b/tests/chat.test.ts
index 3f6f6ec1..3b3c0c22 100644
--- a/tests/chat.test.ts
+++ b/tests/chat.test.ts
@@ -364,6 +364,10 @@ describe("making things in a chat", () => {
expect(wantsToMake(s), s).toBe(true);
for (const s of ["How do I make a reel go viral?", "What should I wear to a gallery opening?", "Write a caption for my linen post", "make sense?", "I made a video yesterday", "Ideas for a perfume ad"])
expect(wantsToMake(s), s).toBe(false);
+ // Asking for a thing that can be made (Hindi and Hinglish asks go to the model's make tool, which describes them).
+ for (const s of ["Can I get a jingle for my shoe brand, upbeat and catchy?", "I need a poster for my bakery's grand opening", "Compose a happy birthday song for my sister Priya"])
+ expect(wantsToMake(s), s).toBe(true);
+ for (const s of ["I need ideas for a poster", "Can I get some tips for my reel?", "I need a caption for this photo", "Ek photo banao jisme ek ladki saree mein ho"]) expect(wantsToMake(s), s).toBe(false);
// An edit or animation of a picture sent with the message.
expect(wantsToMake("Animate this", true)).toBe(true);
expect(wantsToMake("remove the background", true)).toBe(true);
@@ -447,6 +451,8 @@ describe("making things in a chat", () => {
const job = seen.at(-1)!;
expect(job.tools?.map((x) => x.function.name)).toEqual(["make"]);
expect(job.system).toContain("call the make tool");
+ // The "Prompt (image): …" offer competes with the tool, so it isn't there when the tool is.
+ expect(job.system).not.toContain("Prompt (image)");
// A character's story is never offered the tool.
const c = (await (await threadsRoute.POST(req(cookies.a, "/api/chat/threads", "POST", { kind: "character", characterId: "kai" }))).json()) as { id: string };
await events(await replyRoute.POST(req(cookies.a, `/api/chat/threads/${c.id}/reply`, "POST", { text: "Could you sing me something?" }), ctx({ id: c.id })));