commit a79067753aaa5f1971f520f5a6ad7b5e68a7da8f
parent e5dbbbd79e5a443c29585fe8a4c0823583648a58
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 17 Nov 2026 13:56:05 -0500
review 3: the Tune's baseline read again, said when it fails, and a way back to the character
- The item's pieces are read again on every mount and before a press that
asks a sampler value of the line's own; a baseline that changed under an
edited draft is said and nothing is sent -- the next press reads what is
shown.
- A failed read of the pieces is kept as unknown (never "no characters"),
said in place with a retry; an untouched press still goes (nothing of its
own), an edited one waits.
- "Use <character>'s" on a line whose last read was its own: the draft at the
character's tuning, the next press asks nothing of its own ("preset").
- A line with no character now starts its Tune from the last read's numbers
(S3's rule).
- Tests: tuneAsk.test.mjs (each item); the e2e's way back to the character.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
9 files changed, 263 insertions(+), 43 deletions(-)
diff --git a/umtool/components/projects/PostNarrationPanel.tsx b/umtool/components/projects/PostNarrationPanel.tsx
@@ -822,6 +822,10 @@ export default function PostNarrationPanel({
onReadEdited={(t) => void press(() => readEdited(t))}
madeWith={madeWith}
baseline={readsAs.baseline}
+ madeOwn={readsAs.madeOwn}
+ refreshBaseline={readsAs.refresh}
+ baselineError={readsAs.error}
+ onRetryBaseline={readsAs.retry}
character={readsAs.character ?? null}
keepForCharacter={keepForCharacter ?? readsAs.keepForCharacter}
autoplay={autoplay}
diff --git a/umtool/components/projects/PostThreadPanel.tsx b/umtool/components/projects/PostThreadPanel.tsx
@@ -177,6 +177,10 @@ export default function PostThreadPanel({
onReadAgain={(t) => void readThreadAgain(t)}
madeWith={postPart?.tuning ?? null}
baseline={readsAs.baseline}
+ madeOwn={readsAs.madeOwn}
+ refreshBaseline={readsAs.refresh}
+ baselineError={readsAs.error}
+ onRetryBaseline={readsAs.retry}
character={readsAs.character}
keepForCharacter={readsAs.keepForCharacter}
error={again?.state === "failed" ? again.error ?? "failed" : null}
diff --git a/umtool/components/projects/ScreenLineVoice.tsx b/umtool/components/projects/ScreenLineVoice.tsx
@@ -250,6 +250,10 @@ export function ScreenLineVoice({ role, n, voice, dirty, options, chosen, onChoo
onReadEdited={(t) => void voice.readLine(role, t)}
madeWith={playedLine?.tuning ?? null}
baseline={readsAs.baseline}
+ madeOwn={readsAs.madeOwn}
+ refreshBaseline={readsAs.refresh}
+ baselineError={readsAs.error}
+ onRetryBaseline={readsAs.retry}
character={readsAs.character}
keepForCharacter={readsAs.keepForCharacter}
autoplay={voice.autoplay}
diff --git a/umtool/components/projects/read/ReadAgain.tsx b/umtool/components/projects/read/ReadAgain.tsx
@@ -5,7 +5,7 @@ import { buttonVariants } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { ls } from "../useMic";
import { ORPHEUS_DEFAULT_TAKES, ORPHEUS_TUNING_DEFAULTS, TTS_TUNING_FIELDS, TTS_TUNING_RANGES, ttsTuningNameOf } from "yt-dlp-transcript-common/lib/ttsTuning.mjs";
-import { keepAskOf, madeOwnOf as tuneMadeOwnOf, tuneAskOf, tuneStartOf } from "@/lib/report/tuneAsk.mjs";
+import { asksSampler, characterTuneOf, keepAskOf, madeOwnOf as tuneMadeOwnOf, sameBaseline, tuneAskOf, tuneStartOf, unknownBaselineAskOf } from "@/lib/report/tuneAsk.mjs";
// ---------------------------------------------------------------------------
// READ AGAIN (lane line-rerun, S3 of the Orpheus re-tune plan): one line's
@@ -94,7 +94,7 @@ export function madeWithText(t: { reading?: number | null; tuning?: Tuning | nul
}
export default function ReadAgain({
- what = "", busy = false, waiting = null, canReadAgain = true, edited = false, onReadAgain, onReadEdited, madeWith = null, baseline = undefined, character = null, keepForCharacter, error = null, note = null, autoplay, onAutoplay,
+ what = "", busy = false, waiting = null, canReadAgain = true, edited = false, onReadAgain, onReadEdited, madeWith = null, baseline = undefined, madeOwn = false, refreshBaseline, baselineError = null, onRetryBaseline, character = null, keepForCharacter, error = null, note = null, autoplay, onAutoplay,
}: {
/** What is read, in the controls' names: "" (the post), "line 2", "the thread", "the card". */
what?: string;
@@ -115,6 +115,13 @@ export default function ReadAgain({
* line's own); absent: S3's rule (the last read's numbers).
*/
baseline?: TuneBaseline | null;
+ /** Its last read was the line's own (known before the baseline is: an untouched press while it is read). */
+ madeOwn?: boolean;
+ /** The baseline as it is NOW: a press asking a sampler value of its own checks it first (review 3 #1). */
+ refreshBaseline?: () => Promise<TuneBaseline | null>;
+ /** Why the baseline could not be read, and a retry: said in place. */
+ baselineError?: string | null;
+ onRetryBaseline?: () => void;
/** The character this line is read by, when known: S2 keeps a tuning for it. */
character?: { id: string; name: string; layer?: string } | null;
keepForCharacter?: KeepForCharacter;
@@ -127,29 +134,76 @@ export default function ReadAgain({
}) {
// The numbers a plain press would read with now: the line's own last numbers, else its character's, else the
// defaults; the takes the last read's (lib/report/tuneAsk.mjs).
- const start = (): Record<string, string> => tuneStartOf({ madeWith, baseline }) as Record<string, string>;
+ // "Use <character>'s" (review 3 #3): the line back to its character -- the baseline as if its last read were the
+ // character's, until a new read lands.
+ const [fromCharacter, setFromCharacter] = useState(false);
+ const eff: TuneBaseline | null | undefined = baseline && fromCharacter ? (characterTuneOf(madeWith, baseline).baseline as TuneBaseline) : baseline;
+ const start = (): Record<string, string> => tuneStartOf({ madeWith, baseline: eff }) as Record<string, string>;
const [draft, setDraft] = useState<Record<string, string>>(start);
const [kept, setKept] = useState<string | null>(null);
const [keeping, setKeeping] = useState(false);
const keepingRef = useRef(false);
// The takes field typed by the operator (a Keep pins takes only then: the draft's are the last read's recorded).
const [takesTyped, setTakesTyped] = useState(false);
+ // A field edited: the draft is the operator's -- a baseline read again does not replace it (it is said instead).
+ const [dirty, setDirty] = useState(false);
+ const [notice, setNotice] = useState<string | null>(null);
+ const pressing = useRef(false);
+ useEffect(() => setFromCharacter(false), [JSON.stringify(madeWith)]);
useEffect(() => {
+ if (dirty) return;
setDraft(start());
setTakesTyped(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [JSON.stringify(madeWith), JSON.stringify(baseline)]);
+ }, [JSON.stringify(madeWith), JSON.stringify(eff)]);
+ const edit = (next: Record<string, string>) => {
+ setDraft(next);
+ setDirty(true);
+ setNotice(null);
+ };
/**
* What a press asks as the line's own: with no character, S3's rule (what differs from the defaults); with one,
* what differs from the character's tuning -- all of the sampler when the last read was the line's own -- and the
* takes when given (S3's rule).
*/
- const ask = (): Tuning | null => (baseline?.character ? (tuneAskOf(draft, baseline) as Tuning | null) : tuningAsked(draft));
- // The baseline is being read: no press yet (it would start from the last read's numbers).
+ const ask = (): Tuning | null => (eff?.character ? (tuneAskOf(draft, eff) as Tuning | null) : tuningAsked(draft));
+ // The baseline is not known (being read, or its read failed): an untouched press asks nothing of its own; an edited
+ // one waits for it (review 3 #2).
const loading = baseline === null;
+ const waits = loading && dirty;
+ const words = (b: TuneBaseline | null | undefined) => (!b ? "unknown" : b.madeOwn ? "this line's own" : b.character ? `${b.character.name}: ${NAMED[ttsTuningNameOf(b.character.tuning ?? {})] ?? "custom"}` : "defaults");
+ /**
+ * A PRESS (review 3 #1): with the baseline unknown, the untouched ask; else the ask -- and one that names a sampler
+ * value of its own is sent only if the baseline is still the one the draft was made against (read again first). If
+ * it changed under the draft, nothing is sent: the new baseline is said, and the next press reads what is shown.
+ */
+ const press = async (send: (t: Tuning | null) => void) => {
+ if (pressing.current) return;
+ if (loading) {
+ const u = unknownBaselineAskOf(draft, { madeOwn, dirty });
+ if (!u.waits) {
+ send(u.ask as Tuning | null);
+ setDirty(false);
+ }
+ return;
+ }
+ const a = ask();
+ if (baseline && refreshBaseline && asksSampler(a)) {
+ pressing.current = true;
+ const fresh = await refreshBaseline().catch(() => null);
+ pressing.current = false;
+ if (fresh && !sameBaseline({ ...fresh, madeOwn: baseline.madeOwn }, baseline)) {
+ setNotice(`it starts from ${words({ ...fresh, madeOwn: false })} now (it changed): press again to read with the numbers shown`);
+ return;
+ }
+ }
+ setNotice(null);
+ setDirty(false);
+ send(a);
+ };
/** What a Keep keeps: the sampler as it stands, top k and min p when not their defaults, the takes only when typed. */
const keepAsk = (): Tuning => keepAskOf(draft, { takesTyped }) as Tuning;
- const baseWords = !baseline ? null : baseline.madeOwn ? "this line's own" : baseline.character ? `${baseline.character.name}: ${NAMED[ttsTuningNameOf(baseline.character.tuning ?? {})] ?? "custom"}` : "defaults";
+ const baseWords = !eff ? null : words(eff);
const btn = cn(buttonVariants({ variant: "outline", size: "sm" }));
const bad = TTS_TUNING_FIELDS.some((k: string) => {
const r = (TTS_TUNING_RANGES as Record<string, { min: number; max: number; integer: boolean }>)[k];
@@ -160,11 +214,11 @@ export default function ReadAgain({
});
return (
<div className="flex flex-wrap items-center gap-1.5" data-read-again={what || "post"}>
- <button type="button" className={btn} disabled={busy || bad || loading || !canReadAgain} onClick={() => onReadAgain(ask())} aria-label={what ? `Read ${what} again` : "Read again"} data-read-again-button="">
+ <button type="button" className={btn} disabled={busy || bad || waits || !canReadAgain} onClick={() => void press(onReadAgain)} aria-label={what ? `Read ${what} again` : "Read again"} data-read-again-button="">
Read again
</button>
{onReadEdited && (
- <button type="button" className={btn} disabled={busy || bad || loading || !edited} onClick={() => onReadEdited(ask())} aria-label={what ? `Read ${what} as edited` : "Read the edited text"} data-read-edited-button="">
+ <button type="button" className={btn} disabled={busy || bad || waits || !edited} onClick={() => void press(onReadEdited)} aria-label={what ? `Read ${what} as edited` : "Read the edited text"} data-read-edited-button="">
Read edited text
</button>
)}
@@ -185,19 +239,36 @@ export default function ReadAgain({
<label key={k} className="flex items-center justify-between gap-2">
<span>{LABEL[k]}</span>
<input type="number" min={r.min} max={r.max} step={r.integer ? 1 : 0.01} value={draft[k]} placeholder={k === "takes" ? "settings" : undefined} onChange={(e) => {
- setDraft({ ...draft, [k]: e.target.value });
+ edit({ ...draft, [k]: e.target.value });
if (k === "takes") setTakesTyped(true);
}} className="w-20 rounded border border-seam bg-ground px-1 py-0.5" aria-label={`${LABEL[k]}, this line only`} data-read-tune-field={k} />
</label>
);
})}
<div className="flex flex-wrap gap-1.5 pt-1">
- <button type="button" className={btn} disabled={busy || bad || loading || !canReadAgain} onClick={() => onReadAgain(ask())} aria-label={what ? `Read ${what} again with this tuning` : "Read again with this tuning"} data-read-tune-read="">
+ <button type="button" className={btn} disabled={busy || bad || waits || !canReadAgain} onClick={() => void press(onReadAgain)} aria-label={what ? `Read ${what} again with this tuning` : "Read again with this tuning"} data-read-tune-read="">
Read with these
</button>
- <button type="button" className={btn} onClick={() => setDraft(Object.fromEntries(TTS_TUNING_FIELDS.map((k: string) => [k, k in DEFAULTS ? String(DEFAULTS[k]) : ""])))} aria-label="Tuning back to the defaults" data-read-tune-defaults="">
+ <button type="button" className={btn} onClick={() => edit(Object.fromEntries(TTS_TUNING_FIELDS.map((k: string) => [k, k in DEFAULTS ? String(DEFAULTS[k]) : ""])))} aria-label="Tuning back to the defaults" data-read-tune-defaults="">
Defaults
</button>
+ {baseline?.character && baseline.madeOwn && !fromCharacter && (
+ <button
+ type="button"
+ className={btn}
+ onClick={() => {
+ // Back to the character: its numbers, and the next press asks nothing of the line's own ("preset").
+ setFromCharacter(true);
+ setDraft(characterTuneOf(madeWith, baseline).draft as Record<string, string>);
+ setDirty(false);
+ setNotice(null);
+ }}
+ aria-label={`Use ${baseline.character.name}'s tuning for this line`}
+ data-read-tune-character=""
+ >
+ Use {baseline.character.name}'s
+ </button>
+ )}
{keepForCharacter && character && (
<button
type="button"
@@ -230,6 +301,17 @@ export default function ReadAgain({
play when ready
</label>
{busy && <span className="text-text-2" data-read-busy="">{waiting ?? "reading…"}</span>}
+ {notice && <span className="text-[var(--color-warn,#c80)]" data-read-tune-notice="">{notice}</span>}
+ {baselineError && (
+ <span className="text-[var(--color-warn,#c80)]" data-read-baseline-error="">
+ the character's tuning could not be read ({baselineError}){waits ? ": an edited press waits for it" : ""}{" "}
+ {onRetryBaseline && (
+ <button type="button" className="ink-link" onClick={onRetryBaseline} aria-label="Read the character's tuning again" data-read-baseline-retry="">
+ retry
+ </button>
+ )}
+ </span>
+ )}
{!busy && note && <span className="text-text-2" data-read-note="">{note}</span>}
{error && <span className="text-[var(--color-blocking,#c33)]" data-read-error="">{error}</span>}
</div>
diff --git a/umtool/components/projects/read/keepForCharacter.ts b/umtool/components/projects/read/keepForCharacter.ts
@@ -17,50 +17,75 @@ export type ReadCharacter = { id: string; name: string; layer: "cast" | "project
type Piece = { character: ReadCharacter | null; tuning: Tuning | null };
type Pieces = Record<string, Piece>;
-const store = new Map<string, { data: Pieces | null; loading: boolean; subs: Set<(p: Pieces | null) => void> }>();
+type Slot = { data: Pieces | null; error: string | null; loading: Promise<Pieces | null> | null; subs: Set<() => void> };
+const store = new Map<string, Slot>();
const keyOf = (project: string, id: string) => `${project}\u0000${id}`;
function slot(project: string, id: string) {
const k = keyOf(project, id);
let s = store.get(k);
if (!s) {
- s = { data: null, loading: false, subs: new Set() };
+ s = { data: null, error: null, loading: null, subs: new Set() };
store.set(k, s);
}
return s;
}
-/** Read an item's pieces again (after a Keep, or a cast change made on the page): every panel of it is told. */
-export async function refreshReads(project: string, id: string): Promise<void> {
+/**
+ * Read an item's pieces again (on every mount, after a Keep, before a press that asks a sampler value of its own):
+ * every panel of it is told. The value kept meanwhile is the last one read; a read that fails leaves it as it was and
+ * says why (`error`) -- never "no characters". Returns the pieces as they are now (null: not known).
+ */
+export function refreshReads(project: string, id: string): Promise<Pieces | null> {
const s = slot(project, id);
- s.loading = true;
- const j = (await fetch(`/api/report/post-narration?project=${encodeURIComponent(project)}&id=${encodeURIComponent(id)}&reads=all`, { cache: "no-store" })
- .then((r) => (r.ok ? r.json() : null))
- .catch(() => null)) as { pieces?: Pieces } | null;
- s.loading = false;
- const pieces: Pieces = {};
- for (const [role, p] of Object.entries(j?.pieces ?? {})) {
- const c = p?.character;
- pieces[role] = { character: c && (c.layer === "cast" || c.layer === "project") ? c : null, tuning: p?.tuning ?? null };
- }
- s.data = pieces;
- for (const f of s.subs) f(pieces);
+ if (s.loading) return s.loading;
+ const tell = () => {
+ for (const f of s.subs) f();
+ };
+ s.loading = (async () => {
+ type Answer = { pieces?: Record<string, { character?: ReadCharacter | null; tuning?: Tuning | null }>; error?: string };
+ let r = null as Response | null;
+ let j = null as Answer | null;
+ try {
+ r = await fetch(`/api/report/post-narration?project=${encodeURIComponent(project)}&id=${encodeURIComponent(id)}&reads=all`, { cache: "no-store" });
+ j = (await r.json().catch(() => null)) as Answer | null;
+ } catch (e) {
+ s.error = `umtool could not be reached (${e instanceof Error ? e.message : String(e)})`;
+ }
+ if (r?.ok && j && typeof j.pieces === "object" && j.pieces) {
+ const pieces: Pieces = {};
+ for (const [role, p] of Object.entries(j.pieces)) {
+ const c = p?.character;
+ pieces[role] = { character: c && (c.layer === "cast" || c.layer === "project") ? c : null, tuning: p?.tuning ?? null };
+ }
+ s.data = pieces;
+ s.error = null;
+ } else if (r) s.error = j?.error ?? `HTTP ${r.status}`;
+ s.loading = null;
+ tell();
+ return s.data;
+ })();
+ tell();
+ return s.loading;
}
-/** An item's pieces as the bench reads them (null until known). */
-export function useReads(project: string | null | undefined, id: string): Pieces | null {
- const [data, setData] = useState<Pieces | null>(() => (project ? store.get(keyOf(project, id))?.data ?? null : null));
+/** An item's pieces as the bench reads them (null until known), why they could not be read, and a retry. */
+export function useReads(project: string | null | undefined, id: string): { pieces: Pieces | null; error: string | null; retry: () => void } {
+ const [, setTick] = useState(0);
useEffect(() => {
if (!project) return;
const s = slot(project, id);
- s.subs.add(setData);
- if (s.data) setData(s.data);
- else if (!s.loading) void refreshReads(project, id);
+ const f = () => setTick((n) => n + 1);
+ s.subs.add(f);
+ // Read again on EVERY mount (review 3 #1): a character changed on the Voices page or in another tab is seen; the
+ // value kept meanwhile is the last one read.
+ void refreshReads(project, id);
return () => {
- s.subs.delete(setData);
+ s.subs.delete(f);
};
}, [project, id]);
- return data;
+ const s = project ? store.get(keyOf(project, id)) : undefined;
+ return { pieces: s?.data ?? null, error: s?.error ?? null, retry: () => void (project ? refreshReads(project, id) : null) };
}
const words = (t: Tuning) => Object.entries(t).map(([k, v]) => `${k.replace("_", " ")} ${v}`).join(", ") || "the defaults";
@@ -90,8 +115,11 @@ export function keepTuningFor(project: string, item: string, c: ReadCharacter):
* One piece of one item (`role`): its character and keeper (none: no button), and its Tune's baseline from how it was
* last made (`made`: its recorded tuning and `tuningAsked`) -- null until the item's pieces are known.
*/
-export function useKeepForCharacter(project: string | null | undefined, id: string, role = "post", made: { tuning?: Tuning | null; tuningAsked?: unknown } | null = null): { character: ReadCharacter | null; keepForCharacter: KeepForCharacter | undefined; baseline: TuneBaseline | null } {
- const pieces = useReads(project, id);
+export function useKeepForCharacter(project: string | null | undefined, id: string, role = "post", made: { tuning?: Tuning | null; tuningAsked?: unknown } | null = null): {
+ character: ReadCharacter | null; keepForCharacter: KeepForCharacter | undefined; baseline: TuneBaseline | null; madeOwn: boolean;
+ error: string | null; retry: () => void; refresh: () => Promise<TuneBaseline | null>;
+} {
+ const { pieces, error, retry } = useReads(project, id);
const piece = pieces?.[role] ?? null;
const character = piece?.character ?? null;
const keepForCharacter = useMemo(() => (project && character ? keepTuningFor(project, id, character) : undefined), [project, id, character]);
@@ -102,5 +130,13 @@ export function useKeepForCharacter(project: string | null | undefined, id: stri
// eslint-disable-next-line react-hooks/exhaustive-deps
[pieces, character?.id, character?.name, tuningKey, madeOwn],
);
- return { character, keepForCharacter, baseline };
+ // The baseline as it is NOW (read again): a press that asks a sampler value of its own checks it first.
+ const refresh = async (): Promise<TuneBaseline | null> => {
+ if (!project) return null;
+ const p = await refreshReads(project, id);
+ if (!p) return null;
+ const c = p[role]?.character ?? null;
+ return { character: c ? { name: c.name, tuning: p[role]?.tuning ?? null } : null, madeOwn };
+ };
+ return { character, keepForCharacter, baseline, madeOwn, error, retry, refresh };
}
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md
@@ -1878,8 +1878,12 @@ editor's `tts.orpheus.takes`, and the preset and `--json` say that number, never
defaults), unless its last read was the line's own (`tuningAsked` true) -- then those numbers, and they stay its
own. A press asks as the line's own only what differs from the character's (`umtool/lib/report/tuneAsk.mjs`), so a
plain Read again of a character's line asks the character's tuning as it is then; Defaults on a Lively line asks the
- three defaults as its own. The panel says where it starts ("The Teller: Lively", "defaults", "this line's own"). A
- thread read's Tune starts from his own piece.
+ three defaults as its own. The panel says where it starts ("The Teller: Lively", "defaults", "this line's own"), and
+ on a line whose last read was its own offers **Use <character>'s** (back to the character: "preset" again). A
+ thread read's Tune starts from his own piece. The baseline is read again on every mount and before a press that
+ asks a number of the line's own: one that changed under an edited draft is said and nothing is sent (the next press
+ reads what is shown); a baseline that cannot be read is said with a retry (an untouched press still goes: it asks
+ nothing of its own).
- **Keep for the character, on the bench:** the Tune's **Keep this tuning for <character>** (a post's script, a thread
read, a screen line: the character whose preset reads that piece, one `GET /api/report/post-narration?reads=all`
per item, the playing read's voice overrides kept -- a piece given another voice on purpose has no button) runs the
diff --git a/umtool/e2e/character-tuning.spec.ts b/umtool/e2e/character-tuning.spec.ts
@@ -328,6 +328,16 @@ test("review 2: a plain Read again asks the character's tuning as it is now (\"p
const dflt = benchAsks().at(-1)!.tuning ?? {};
expect([dflt.temperature, dflt.top_p]).toEqual([0.55, 0.85]);
expect(takesOf("p-1")[4].tuningAsked).toBe(true);
+ // Back to the character (review 3 #3): the line's own last read, its Tune's "Use The Teller's" -- the next press
+ // asks nothing of its own, Steady is read, recorded "preset".
+ await expect(panel.locator("[data-read-tune-baseline]")).toContainText("this line's own", { timeout: 15_000 });
+ await panel.locator('[aria-label="Use The Teller\'s tuning for this line"]').click();
+ await expect(panel.locator("[data-read-tune-baseline]")).toContainText("The Teller: Steady");
+ await panel.locator('[aria-label="Read again with this tuning"]').click();
+ await expect(panel.locator("[data-post-take]")).toHaveCount(6, { timeout: 30_000 });
+ const back = benchAsks().at(-1)!.tuning ?? {};
+ expect([back.temperature, back.top_p]).toEqual([0.4, 0.8]);
+ expect(takesOf("p-1")[5].tuningAsked).toBe("preset");
// The card draws what it drew (take 3 plays: words as drafted).
await page.reload();
expect(await drawnCard(page)).toEqual(before);
diff --git a/umtool/lib/report/tuneAsk.mjs b/umtool/lib/report/tuneAsk.mjs
@@ -41,7 +41,8 @@ export function defaultsAskOf(draft) {
* @param {{ madeWith?: Record<string, number> | null, baseline?: { character: { tuning: Record<string, number> | null } | null, madeOwn: boolean } | null }} o
*/
export function tuneStartOf({ madeWith = null, baseline = null } = {}) {
- const b = !baseline ? madeWith : baseline.madeOwn ? madeWith : baseline.character?.tuning ?? null;
+ // No character (none now, or one since removed): S3's rule -- the last read's numbers (review 3 #4).
+ const b = !baseline || baseline.madeOwn || !baseline.character ? madeWith : baseline.character.tuning ?? null;
return Object.fromEntries(TTS_TUNING_FIELDS.map((k) => {
const v = k === "takes" ? madeWith?.takes : b?.[k];
return [k, v !== undefined && v !== null ? String(v) : k in DEFAULTS ? String(DEFAULTS[k]) : ""];
@@ -90,3 +91,36 @@ export function threadTuneMadeOf(parts) {
const p = (Array.isArray(parts) ? parts : []).find((x) => x?.role === "post" && typeof x?.take !== "string") ?? null;
return p ? { tuning: p.tuning ?? null, tuningAsked: p.tuningAsked } : null;
}
+
+/** Does an ask name a sampler value (anything but the takes)? -- a press that does is checked against a fresh baseline. */
+export const asksSampler = (ask) => !!ask && Object.keys(ask).some((k) => k !== "takes");
+
+/** Two baselines the same (the character, its tuning, whose the last read was)? */
+export function sameBaseline(a, b) {
+ const key = (x) => JSON.stringify(x ? [x.character?.name ?? null, x.character ? x.character.tuning ?? {} : null, !!x.madeOwn] : null);
+ return key(a) === key(b);
+}
+
+/**
+ * A press while the baseline is NOT KNOWN (being read, or its read failed): an untouched draft asks nothing of its
+ * own -- only the takes -- unless the last read was the line's own (then S3's rule: its numbers again); an edited
+ * draft waits for the baseline (null: no press).
+ */
+export function unknownBaselineAskOf(draft, { madeOwn = false, dirty = false } = {}) {
+ if (dirty) return { waits: true, ask: null };
+ if (madeOwn) return { waits: false, ask: defaultsAskOf(draft) };
+ const takes = num(draft?.takes);
+ return { waits: false, ask: takes !== null ? { takes } : null };
+}
+
+/**
+ * "Use <character>'s" (review 3 #3): a line whose last read was its own, back to its character -- the draft at the
+ * character's tuning, and the baseline as if the last read were the character's, so the next press asks nothing of
+ * its own (the takes only) and records "preset".
+ * @param {Record<string, number> | null} madeWith
+ * @param {{ character: { tuning: Record<string, number> | null } | null, madeOwn: boolean }} baseline
+ */
+export function characterTuneOf(madeWith, baseline) {
+ const b = { ...baseline, madeOwn: false };
+ return { baseline: b, draft: tuneStartOf({ madeWith, baseline: b }) };
+}
diff --git a/umtool/lib/report/tuneAsk.test.mjs b/umtool/lib/report/tuneAsk.test.mjs
@@ -4,7 +4,7 @@
// line's own).
import assert from "node:assert/strict";
import { test } from "node:test";
-import { defaultsAskOf, keepAskOf, madeOwnOf, threadTuneMadeOf, tuneAskOf, tuneStartOf } from "./tuneAsk.mjs";
+import { asksSampler, characterTuneOf, defaultsAskOf, keepAskOf, madeOwnOf, sameBaseline, threadTuneMadeOf, tuneAskOf, tuneStartOf, unknownBaselineAskOf } from "./tuneAsk.mjs";
const LIVELY = { temperature: 0.75, top_p: 0.92, repeat_penalty: 1.25 };
const STEADY = { temperature: 0.4, top_p: 0.8 };
@@ -68,3 +68,45 @@ test("review 2 #5: a Keep pins the character's takes only when the takes field w
// Top k and min p go only when not their defaults (a character does not keep them: the route says so).
assert.deepEqual(keepAskOf({ ...draft, top_k: "40" }).top_k, 40);
});
+
+test("review 3 #1: a draft edited against Lively while the character became Steady is NOT sent; pressed again, what is shown is read", () => {
+ // Loaded as Lively; the operator changes only top_p.
+ const was = asCharacter(LIVELY, false);
+ const draft = { ...tuneStartOf({ madeWith: MADE_LIVELY, baseline: was }), top_p: "0.9" };
+ const a = tuneAskOf(draft, was);
+ assert.deepEqual(a, { top_p: 0.9, takes: 3 });
+ assert.equal(asksSampler(a), true, "it names a sampler value of its own: the baseline is read again before it is sent");
+ // Read again: Steady now. It changed under the draft -- nothing is sent (the press is refused, the new baseline said).
+ const now = asCharacter(STEADY, false);
+ assert.equal(sameBaseline(now, was), false);
+ assert.equal(sameBaseline(asCharacter({ ...LIVELY }, false), was), true);
+ // Sent as it was, it would have read {temperature 0.4 (Steady's), top_p 0.9} while the Tune showed 0.75.
+ // Pressed again against Steady, the draft as shown is the line's own: every number that differs from Steady's.
+ assert.deepEqual(tuneAskOf(draft, now), { temperature: 0.75, top_p: 0.9, repeat_penalty: 1.25, takes: 3 });
+ // An untouched press names no sampler value: sent at once (the character's is asked as it is then).
+ assert.equal(asksSampler({ takes: 3 }), false);
+});
+
+test("review 3 #2: the baseline unknown -- an untouched press asks nothing of its own, an edited one waits", () => {
+ const draft = tuneStartOf({ madeWith: MADE_LIVELY, baseline: null });
+ assert.deepEqual(unknownBaselineAskOf(draft, { madeOwn: false }), { waits: false, ask: { takes: 3 } });
+ assert.deepEqual(unknownBaselineAskOf(draft, { madeOwn: false, dirty: true }), { waits: true, ask: null });
+ // A line whose last read was its own: its numbers again (S3's rule), still its own.
+ assert.deepEqual(unknownBaselineAskOf(tuneStartOf({ madeWith: { ...MADE_LIVELY, temperature: 0.9 }, baseline: null }), { madeOwn: true }).ask, { temperature: 0.9, top_p: 0.92, repeat_penalty: 1.25, takes: 3 });
+});
+
+test("review 3 #3: Use <character>'s -- a line whose last read was its own goes back to its character: nothing of its own asked", () => {
+ const b = asCharacter(STEADY, true);
+ const own = { ...MADE_LIVELY, temperature: 0.9 };
+ assert.ok(asksSampler(tuneAskOf(tuneStartOf({ madeWith: own, baseline: b }), b)), "before: its own numbers, asked as its own");
+ const back = characterTuneOf(own, b);
+ assert.deepEqual([back.draft.temperature, back.draft.top_p, back.draft.repeat_penalty], ["0.4", "0.8", "1.2"], "the draft at the character's");
+ assert.deepEqual(tuneAskOf(back.draft, back.baseline), { takes: 3 }, "the next press asks only the takes: recorded \"preset\"");
+});
+
+test("review 3 #4: no character now, the last read the character's since removed -- the Tune starts from the last read's numbers (S3)", () => {
+ const none = { character: null, madeOwn: false };
+ const d = tuneStartOf({ madeWith: MADE_LIVELY, baseline: none });
+ assert.deepEqual([d.temperature, d.top_p, d.repeat_penalty, d.takes], ["0.75", "0.92", "1.25", "3"]);
+ assert.deepEqual(tuneStartOf({ madeWith: MADE_LIVELY, baseline: none }), tuneStartOf({ madeWith: MADE_LIVELY }), "S3's start, exactly");
+});