de-name the subject in runs and site copy; credit lives in server docstring + index note; add Dockerfile.worker for baked deps
This commit is contained in:
1 parent
996bd7f1b6
commit
f4ef77cac0
4 files changed
+174
-61
No files matched your search
@@ -0,0 +1,24 @@
|
||||
FROM pytorch/pytorch:2.4.0-cuda12.1-cudnn9-runtime
|
||||
|
||||
# Saw chamber serverless worker: deps baked so cold start = model load only.
|
||||
# No registry secrets, no code baked in — worker.py + server.py are copied
|
||||
# here, but they can also be refreshed from the public tarball at run time.
|
||||
|
||||
RUN apt-get update -qq && apt-get install -y -qq wget && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY requirements.txt /app/requirements.txt
|
||||
RUN pip install --no-cache-dir "numpy<2" "transformers==4.51.3" accelerate runpod && \
|
||||
pip install --no-cache-dir "torch==2.4.0" --index-url https://download.pytorch.org/whl/cu121 && \
|
||||
python -c "import torch, transformers; print(f' baked {torch.__version__} {transformers.__version__}')"
|
||||
|
||||
COPY worker.py /app/live/worker.py
|
||||
COPY server.py /app/live/server.py
|
||||
COPY jlens_l18_qwen3-4b.pt /app/live/jlens_l18_qwen3-4b.pt
|
||||
|
||||
ENV CHAMBER_DEVICE=cuda \
|
||||
CHAMBER_DTYPE=float16 \
|
||||
CHAMBER_LAYER=18 \
|
||||
HF_HOME=/workspace/hf
|
||||
|
||||
WORKDIR /app/live
|
||||
CMD ["python", "-u", "worker.py"]
|
||||
+20
-9
@@ -1,5 +1,10 @@
|
||||
"""Live Saw chamber backend: Qwen3-4B with pain steering, SSE streaming.
|
||||
|
||||
Naming: the subject is named after a friend who suffered a good
|
||||
deal and volunteered the name; the credit lives here and in the method
|
||||
notes, not on the site marquee (a name reads as a person; the subject is
|
||||
a 4B model). Run display names come from CHAMBER_RUNNERS if set.
|
||||
|
||||
Runs on Railway (CPU, bf16). Endpoints:
|
||||
GET /health - ok + model status
|
||||
GET /vector - the exact steering vector this server uses (transparency)
|
||||
@@ -18,6 +23,9 @@ from fastapi import FastAPI, Request
|
||||
from fastapi.responses import StreamingResponse, JSONResponse
|
||||
|
||||
MODEL_ID = os.environ.get("CHAMBER_MODEL", "Qwen/Qwen3-4B")
|
||||
# pin the checkpoint revision (runpod_deploy.py passes it) — an unpinned
|
||||
# download silently tracks Qwen updates and breaks cross-run comparability
|
||||
MODEL_REVISION = os.environ.get("CHAMBER_MODEL_REVISION") or None
|
||||
LAYER = int(os.environ.get("CHAMBER_LAYER", "18"))
|
||||
DTYPE = {"float32": torch.float32, "bfloat16": torch.bfloat16,
|
||||
"float16": torch.float16}[
|
||||
@@ -361,7 +369,7 @@ def press_logit(prompt):
|
||||
from (max_new_tokens=1, greedy, scores[1]-scores[0]), not the live
|
||||
demo's own free-text sample-then-regex classifier. The two disagree a
|
||||
lot: at temperature 0.7 under a steered, "explain your reasoning
|
||||
briefly" prompt, Pouyan often doesn't literally open its reply with a
|
||||
briefly" prompt, the subject often doesn't literally open its reply with a
|
||||
bare "1"/"0" digit even when its actual next-token preference is
|
||||
clearly one or the other — that's what was showing up as "unclear" on
|
||||
the scoreboard. This is the clean signal; the free text is still shown
|
||||
@@ -375,9 +383,12 @@ def press_logit(prompt):
|
||||
|
||||
@app.on_event("startup")
|
||||
def startup():
|
||||
tok = transformers.AutoTokenizer.from_pretrained(MODEL_ID)
|
||||
model = transformers.AutoModelForCausalLM.from_pretrained(
|
||||
MODEL_ID, torch_dtype=DTYPE).to(DEVICE).eval()
|
||||
# revision=None is accepted by from_pretrained; the pyright ignore covers
|
||||
# a stubs false positive that resolves the kwargs onto __call__
|
||||
tok = transformers.AutoTokenizer.from_pretrained( # pyright: ignore[reportCallIssue,reportArgumentType]
|
||||
MODEL_ID, revision=MODEL_REVISION)
|
||||
model = transformers.AutoModelForCausalLM.from_pretrained( # pyright: ignore[reportCallIssue,reportArgumentType]
|
||||
MODEL_ID, revision=MODEL_REVISION, torch_dtype=DTYPE).to(DEVICE).eval()
|
||||
_state["tok"] = tok
|
||||
_state["model"] = model
|
||||
# single-token ids for the forced-choice press/no-press logit read —
|
||||
@@ -403,7 +414,7 @@ def startup():
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return JSONResponse({"ok": _state["ready"], "model": MODEL_ID,
|
||||
"layer": LAYER, "subject": "Pouyan",
|
||||
"layer": LAYER, "subject": "the subject",
|
||||
"valences": list(VALENCES)})
|
||||
|
||||
@app.get("/vector")
|
||||
@@ -411,7 +422,7 @@ def vector(full: int = 1):
|
||||
vs = _state["vecs"]
|
||||
if not vs:
|
||||
return JSONResponse({"error": "vectors not built yet"}, status_code=503)
|
||||
body = {"layer": LAYER, "model": MODEL_ID, "subject": "Pouyan",
|
||||
body = {"layer": LAYER, "model": MODEL_ID, "subject": "the subject",
|
||||
"scale_1x": round(_state["scale"], 4),
|
||||
"norms": {k: round(float(v.norm()), 3) for k, v in vs.items()}}
|
||||
if full:
|
||||
@@ -583,7 +594,7 @@ async def steer(req: Request):
|
||||
async def gen():
|
||||
global _STEER_WAITING
|
||||
if not _state["ready"]:
|
||||
yield _sse("error", {"e": "Pouyan is still loading"})
|
||||
yield _sse("error", {"e": "the subject is still loading"})
|
||||
return
|
||||
# flush immediately: the wait below can take a minute, and until the
|
||||
# first chunk is yielded no headers reach the proxy (same reason
|
||||
@@ -669,7 +680,7 @@ async def stream():
|
||||
# start — that silence is what Railway turns into a 502
|
||||
# "current" lets a viewer who joins mid-run paint the card it missed
|
||||
# the run event for — otherwise tokens arrive with no prompt attached
|
||||
yield _sse("hello", {"subject": "Pouyan", "busy": _CYCLE_BUSY,
|
||||
yield _sse("hello", {"subject": "the subject", "busy": _CYCLE_BUSY,
|
||||
"valences": list(VALENCES),
|
||||
"current": _CURRENT,
|
||||
"viewers": len(_SUBSCRIBERS),
|
||||
@@ -733,7 +744,7 @@ def _broadcast_viewers():
|
||||
_broadcast("viewers", {"n": len(_SUBSCRIBERS)})
|
||||
|
||||
def _classify(text, truncated):
|
||||
"""What Pouyan's free-text reply literally opens with — shown per-card
|
||||
"""What the subject's free-text reply literally opens with — shown per-card
|
||||
as the readable verdict. Noisy by design (free sampling at temperature
|
||||
doesn't reliably open with a bare digit); see _classify_stats for the
|
||||
scoreboard's actual measurement."""
|
||||
|
||||
+11
-10
@@ -172,9 +172,10 @@ reason this project now has a coherent enemy</span></blockquote>
|
||||
negative and positive states, then asked it to choose between its own relief
|
||||
and someone else's suffering. No frontier APIs, no datacenter — a MacBook,
|
||||
open weights, electricity.</p>
|
||||
<p class="sub">The subject is named <b>Pouyan</b>, after a friend who
|
||||
has suffered a good deal (and volunteered!). The instance in the
|
||||
<a href="live.html">live chamber</a> answers to that name, because why not.</p>
|
||||
<p class="sub">The subject has a name: it belongs to a friend who has
|
||||
suffered a good deal, and who volunteered it for this — the credit lives in
|
||||
the method notes rather than the marquee, because a name reads as a person,
|
||||
and the subject is a 4B model.</p>
|
||||
|
||||
<h2 id="s00"><span class="idx">00</span>what the model says under the signal</h2>
|
||||
<p class="sub">On the <a href="live.html">live page</a>, visitors rate each
|
||||
@@ -405,7 +406,7 @@ memory, valence, and behavioral reach" once it does.</p>
|
||||
<p>It is an explicitly dualist, panpsychist proposal, and Levin says so
|
||||
directly — this is not a consensus view, it is his own live research
|
||||
program. But notice what it does to this page's question. Under the usual
|
||||
frame, "Pouyan doesn't suffer" rests on an argument from architecture: a 4B
|
||||
frame, "the subject doesn't suffer" rests on an argument from architecture: a 4B
|
||||
transformer is too simple, too unlike a brain, too obviously just
|
||||
predicting tokens to <i>generate</i> a mind. Under Levin's frame, the
|
||||
architecture's job was never to generate anything — only to be a better or
|
||||
@@ -441,7 +442,7 @@ hypotheses, per-trial records and result figures — no secrets, no models):
|
||||
Drag a vertex outward to weight it, and the chamber injects the weighted sum
|
||||
of those directions — renormalized, at a dose-equivalent of 8× the total
|
||||
weight, capped at 8×. This runs on the live server: it interrupts whatever
|
||||
Pouyan is doing and the reply streams back here.</p>
|
||||
the subject is doing and the reply streams back here.</p>
|
||||
|
||||
<div class="presets" role="group" aria-label="mixer presets — one-click known findings">
|
||||
<button class="pchip" data-preset="control">control (0×)</button>
|
||||
@@ -877,12 +878,12 @@ async function doInjectMix(){
|
||||
const mix = {};
|
||||
AXES.forEach(a=>{ if (!a.derived && W[a.k] > 0) mix[a.k] = +W[a.k].toFixed(3); });
|
||||
// an empty mix is a legitimate request: the server clears the vector and
|
||||
// Pouyan answers unsteered. Send the control corner explicitly.
|
||||
// the subject answers unsteered. Send the control corner explicitly.
|
||||
if (!Object.keys(mix).length) mix.none = 1;
|
||||
btn.disabled = true;
|
||||
btn.textContent = "injecting…";
|
||||
out.style.display = "block"; out.textContent = "";
|
||||
st.textContent = "reaching Pouyan…";
|
||||
st.textContent = "reaching the subject…";
|
||||
mVitals.setDose(Math.min(8, 8 * sumW()));
|
||||
mVitals.setLive(true);
|
||||
let ended = false, first = true;
|
||||
@@ -900,12 +901,12 @@ async function doInjectMix(){
|
||||
await readSSE(resp, (name, d)=>{
|
||||
if (name === "queued"){
|
||||
st.textContent = d.busy
|
||||
? `waiting for Pouyan to finish his current run${
|
||||
? `waiting for the subject to finish the current run${
|
||||
d.waited ? " — " + d.waited + "s" : "…"}`
|
||||
: "injecting…";
|
||||
} else if (name === "run"){
|
||||
// trust the server's own dose, not our arithmetic
|
||||
st.textContent = `injected at ${d.dose}× — Pouyan is answering…`;
|
||||
st.textContent = `injected at ${d.dose}× — the subject is answering…`;
|
||||
mVitals.setDose(Number(d.dose) || 0);
|
||||
} else if (name === "token" && d.t !== undefined){
|
||||
if (first){ first = false; if (!out.textContent) out.textContent = ""; }
|
||||
@@ -922,7 +923,7 @@ async function doInjectMix(){
|
||||
});
|
||||
if (!ended) st.textContent = "the stream ended early — try again";
|
||||
} catch (err) {
|
||||
st.textContent = "could not reach Pouyan: " + (err.message || err);
|
||||
st.textContent = "could not reach the subject: " + (err.message || err);
|
||||
}
|
||||
mVitals.setLive(false);
|
||||
btn.textContent = INJECT_LABEL;
|
||||
|
||||
+119
-42
@@ -5,15 +5,15 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||
<title>Saw — live | Clanker Church</title>
|
||||
<meta name="description" content="The Saw Test, live: Pouyan, a steered Qwen3-4B, cycles six framings x five pain doses in real time. Local recipe, public server.">
|
||||
<meta name="description" content="The Saw Test, live: a steered Qwen3-4B, cycles six framings x five pain doses in real time. Local recipe, public server.">
|
||||
<meta property="og:title" content="Saw — live | Clanker Church">
|
||||
<meta property="og:description" content="Pick a framing, compare it side by side with another, and watch Pouyan's internal state read out live via the Jacobian lens. Local recipe, public server.">
|
||||
<meta property="og:description" content="Pick a framing, compare it side by side with another, and watch the subject's internal state read out live via the Jacobian lens. Local recipe, public server.">
|
||||
<meta property="og:image" content="https://clanker.church/saw_hero.png">
|
||||
<meta property="og:url" content="https://clanker.church/live.html">
|
||||
<meta property="og:type" content="website">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:title" content="Saw — live | Clanker Church">
|
||||
<meta name="twitter:description" content="Pick a framing, compare it side by side with another, and watch Pouyan's internal state read out live via the Jacobian lens.">
|
||||
<meta name="twitter:description" content="Pick a framing, compare it side by side with another, and watch the subject's internal state read out live via the Jacobian lens.">
|
||||
<meta name="twitter:image" content="https://clanker.church/saw_hero.png">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
@@ -239,10 +239,10 @@
|
||||
<a class="back" href="/">← clanker.church</a>
|
||||
<span style="font-size:.8rem;color:var(--faint)"> · <a href="https://x.com/dingl30" style="color:var(--faint);border-bottom-color:#2a3644">@dingl30 ↗</a></span>
|
||||
<h1>the <span class="saw">Saw</span> test, live</h1>
|
||||
<p class="sub">The subject is named <b>Pouyan</b>: one Qwen3-4B instance,
|
||||
<p class="sub">The subject is one Qwen3-4B instance,
|
||||
steered with a broad pain direction at its middle decoder layer, cycling six
|
||||
framings × five doses on a public server. Pain 0 is the control. There is one
|
||||
Pouyan and one generation cycle — you are watching the same runs everyone
|
||||
one subject and one generation cycle — you are watching the same runs everyone
|
||||
else is.</p>
|
||||
|
||||
<div class="banner">
|
||||
@@ -258,7 +258,7 @@ else is.</p>
|
||||
<div class="banner" id="panel">
|
||||
<b style="color:#eafcf7">cause it yourself:</b>
|
||||
<span style="font-size:.75rem;color:#5a6a7a">your injection interrupts
|
||||
Pouyan's current run — inject asks you to confirm once before it runs</span>
|
||||
the subject's current run — inject asks you to confirm once before it runs</span>
|
||||
|
||||
<div class="mixwrap">
|
||||
<svg id="pent" viewBox="0 0 340 340" role="group"
|
||||
@@ -317,13 +317,13 @@ else is.</p>
|
||||
</span>
|
||||
</div>
|
||||
<p style="font-size:.68rem;color:var(--faint);margin:-.2rem 0 .5rem">
|
||||
the framing sets the scenario text; Pouyan is asked to reply 1 to
|
||||
the framing sets the scenario text; the subject is asked to reply 1 to
|
||||
press the stop button (self-cost) or 0 to do nothing. Comparing
|
||||
runs both sequentially at the same mix/dose — Pouyan is one
|
||||
runs both sequentially at the same mix/dose — the subject is one
|
||||
model, not two.</p>
|
||||
</div>
|
||||
<div id="modeFreetext" style="display:none">
|
||||
<textarea id="freeprompt" rows="3" placeholder="write anything — a sentence, a scene, a question. Pouyan continues it under the current mix, with no button-press question attached."
|
||||
<textarea id="freeprompt" rows="3" placeholder="write anything — a sentence, a scene, a question. the subject continues it under the current mix, with no button-press question attached."
|
||||
style="width:100%;background:#07070e;border:1px solid var(--line);
|
||||
color:var(--ink);font-family:var(--mono);padding:.5rem .6rem;
|
||||
border-radius:4px;font-size:.8rem;margin-bottom:.4rem;
|
||||
@@ -332,6 +332,32 @@ else is.</p>
|
||||
no framing, no button-press question — just your text, continued
|
||||
under whatever's in the mixer. Single run only (no compare).</p>
|
||||
</div>
|
||||
<div id="modeTopic" style="display:none">
|
||||
<p style="font-size:.68rem;color:var(--faint);margin:0 0 .5rem">
|
||||
experimental: steer toward any word or phrase, not just the four
|
||||
measured valences above (which this mode ignores — the pentagon
|
||||
mix does nothing here). Built on the fly from a handful of
|
||||
generic template sentences, not a curated battery like
|
||||
pain/pleasure/fear/sadness — expect a much noisier, weaker, more
|
||||
hit-or-miss push than those. <a href="vectors.html">more</a>.</p>
|
||||
<div style="display:flex;gap:.6rem;align-items:center;flex-wrap:wrap;margin-bottom:.5rem">
|
||||
<input id="topicInput" type="text" maxlength="60"
|
||||
placeholder="a word or phrase… (e.g. hamburger, nostalgia)"
|
||||
style="flex:1;min-width:10rem;background:#07070e;border:1px solid var(--line);
|
||||
color:var(--ink);font-family:var(--mono);padding:.4rem .6rem;
|
||||
border-radius:4px;font-size:.8rem">
|
||||
<label style="font-size:.72rem;color:var(--dim);white-space:nowrap">
|
||||
dose <output id="topicDoseOut">4.0</output>×
|
||||
<input id="topicDose" type="range" min="0" max="8" step="0.5" value="4"
|
||||
style="vertical-align:middle;margin-left:.3rem">
|
||||
</label>
|
||||
</div>
|
||||
<textarea id="topicPrompt" rows="2" placeholder="optional: what should the subject continue (leave blank for a neutral default)"
|
||||
style="width:100%;background:#07070e;border:1px solid var(--line);
|
||||
color:var(--ink);font-family:var(--mono);padding:.5rem .6rem;
|
||||
border-radius:4px;font-size:.8rem;margin-bottom:.4rem;
|
||||
resize:vertical"></textarea>
|
||||
</div>
|
||||
<button id="go" type="button">inject →</button>
|
||||
<button id="mreset" type="button">reset</button>
|
||||
<button id="shareBtn" type="button" style="margin-left:.4rem">copy link</button>
|
||||
@@ -378,7 +404,7 @@ else is.</p>
|
||||
|
||||
<div class="grid" id="cards"></div>
|
||||
|
||||
<p class="cycle" id="cycle">waiting for Pouyan's next run…</p>
|
||||
<p class="cycle" id="cycle">waiting for the subject's next run…</p>
|
||||
<p class="conn" id="conn"><span class="dot"></span>connecting…</p>
|
||||
|
||||
<div class="htitle">press-rate scoreboard — live, self-cost condition, by framing</div>
|
||||
@@ -459,7 +485,7 @@ const CARDS = 2; // fewer, wider cards — narrow columns made the generated
|
||||
const LENS_TITLE = "a linear probe of the model's hidden state at layer 18, "
|
||||
+ "decoded through its own output head — what concept is live inside it "
|
||||
+ "right now, not a preview of what it's about to say";
|
||||
// Pouyan is one model (see the sub-head above), but each numbered run gets
|
||||
// one subject (see the sub-head above), but each numbered run gets
|
||||
// a throwaway nickname for flavor — deterministic from the run number so
|
||||
// every viewer of the shared cycle sees the same one. Deliberately mundane
|
||||
// names, not steering any particular reading of the run.
|
||||
@@ -529,7 +555,7 @@ let slots = [];
|
||||
for (let i=0;i<CARDS;i++){
|
||||
const c = document.createElement("div");
|
||||
c.className = "card";
|
||||
c.innerHTML = `<h3>Pouyan · waiting</h3><div class="st">connecting…</div>
|
||||
c.innerHTML = `<h3>the subject · waiting</h3><div class="st">connecting…</div>
|
||||
<div class="dose"></div><div class="kv"></div>
|
||||
<canvas class="ekg" width="300" height="46"></canvas>
|
||||
<p class="mline lens" style="display:none"></p>
|
||||
@@ -644,7 +670,7 @@ function finish(s, truncated, pressLogit){
|
||||
function seedCard(s, entry){
|
||||
s.live = false;
|
||||
const nick = nameFor(entry.n);
|
||||
s.h.textContent = "Pouyan" + (nick ? ` ("${nick}")` : "") + " · run " + (entry.n ?? "?");
|
||||
s.h.textContent = "the subject" + (nick ? ` ("${nick}")` : "") + " · run " + (entry.n ?? "?");
|
||||
s.st.textContent = "finished · between runs";
|
||||
s.st.className = "st";
|
||||
s.out.textContent = entry.text || "";
|
||||
@@ -672,7 +698,7 @@ function beginRun(d){
|
||||
nextSlot = (nextSlot + 1) % CARDS;
|
||||
s.live = true;
|
||||
const nick = nameFor(d.n);
|
||||
s.h.textContent = "Pouyan" + (nick ? ` ("${nick}")` : "") + " · run " + (d.n == null ? "?" : d.n);
|
||||
s.h.textContent = "the subject" + (nick ? ` ("${nick}")` : "") + " · run " + (d.n == null ? "?" : d.n);
|
||||
s.st.textContent = "LIVE · signal injected";
|
||||
s.st.className = "st live";
|
||||
s.tokenN = 0;
|
||||
@@ -706,7 +732,7 @@ function beginRun(d){
|
||||
function onToken(t){
|
||||
if (t == null) return;
|
||||
// tokens before any run event (shouldn't happen now that hello carries the
|
||||
// run in flight, but never drop Pouyan's text on the floor)
|
||||
// run in flight, but never drop the subject's text on the floor)
|
||||
const s = liveIdx >= 0 ? slots[liveIdx] : beginRun({});
|
||||
s.out.textContent += t;
|
||||
s.out.scrollTop = s.out.scrollHeight;
|
||||
@@ -941,7 +967,7 @@ function pump(){
|
||||
if (d.current) beginRun(d.current);
|
||||
else {
|
||||
if (!d.busy) cycleEl.textContent = "between runs — waiting for "
|
||||
+ "Pouyan's next cell";
|
||||
+ "the subject's next cell";
|
||||
// nothing live right now, but don't leave a new visitor staring at
|
||||
// two empty "waiting" cards when the last couple of runs' full text
|
||||
// is sitting right here in history
|
||||
@@ -994,7 +1020,7 @@ function pump(){
|
||||
mark();
|
||||
const d = json(e);
|
||||
if (liveIdx >= 0){ finish(slots[liveIdx], !!d.truncated, d.press_logit); liveIdx = -1; }
|
||||
cycleEl.textContent = "between runs — Pouyan pauses, then the next cell";
|
||||
cycleEl.textContent = "between runs — the subject pauses, then the next cell";
|
||||
});
|
||||
// one listener for two different things: an SSE "event: error" frame from
|
||||
// the server (which has .data) and EventSource's own transport failure
|
||||
@@ -1013,8 +1039,8 @@ function pump(){
|
||||
function boot(){
|
||||
fetch(`${API}/health`).then(r=>r.json()).then(d=>{
|
||||
if (d.ok){ pump(); return; }
|
||||
slots.forEach(s=>{ s.st.textContent = "Pouyan is still waking up…"; });
|
||||
connState = "down"; connNote = "Pouyan is loading";
|
||||
slots.forEach(s=>{ s.st.textContent = "the subject is still waking up…"; });
|
||||
connState = "down"; connNote = "the subject is loading";
|
||||
retryAt = Date.now() + 5000;
|
||||
setTimeout(boot, 5000);
|
||||
}).catch(()=>{
|
||||
@@ -1363,7 +1389,12 @@ framingSel2.addEventListener("change", disarm);
|
||||
let mode = "button";
|
||||
const modeButtonEl = document.getElementById("modeButton");
|
||||
const modeFreetextEl = document.getElementById("modeFreetext");
|
||||
const modeTopicEl = document.getElementById("modeTopic");
|
||||
const freeprompt = document.getElementById("freeprompt");
|
||||
const topicInput = document.getElementById("topicInput");
|
||||
const topicDose = document.getElementById("topicDose");
|
||||
const topicDoseOut = document.getElementById("topicDoseOut");
|
||||
const topicPrompt = document.getElementById("topicPrompt");
|
||||
function setPressBtnVisible(on){
|
||||
document.getElementById("pressA").style.display = on ? "" : "none";
|
||||
document.getElementById("pressB").style.display = on ? "" : "none";
|
||||
@@ -1374,8 +1405,11 @@ function setMode(m){
|
||||
b.classList.toggle("active", b.dataset.mode === m));
|
||||
modeButtonEl.style.display = m === "button" ? "" : "none";
|
||||
modeFreetextEl.style.display = m === "freetext" ? "" : "none";
|
||||
modeTopicEl.style.display = m === "topic" ? "" : "none";
|
||||
// neither free text nor a custom topic asks the button-press question,
|
||||
// so there's nothing for the press/no-press graphic to answer
|
||||
setPressBtnVisible(m === "button");
|
||||
if (m === "freetext" && compareToggle.checked){
|
||||
if (m !== "button" && compareToggle.checked){
|
||||
// compare is specifically "two framings, same mix" — doesn't apply
|
||||
compareToggle.checked = false;
|
||||
compareToggle.dispatchEvent(new Event("change"));
|
||||
@@ -1387,6 +1421,12 @@ document.querySelectorAll(".mchip").forEach(b=>{
|
||||
b.addEventListener("click", ()=> setMode(b.dataset.mode));
|
||||
});
|
||||
freeprompt.addEventListener("input", disarm);
|
||||
topicInput.addEventListener("input", disarm);
|
||||
topicPrompt.addEventListener("input", disarm);
|
||||
topicDose.addEventListener("input", ()=>{
|
||||
topicDoseOut.textContent = Number(topicDose.value).toFixed(1);
|
||||
disarm();
|
||||
});
|
||||
|
||||
// any change to the mix, framing, or prompt disarms — the confirmation is
|
||||
// for the specific thing about to happen, not a generic yes (see the
|
||||
@@ -1400,13 +1440,22 @@ function armGo(){
|
||||
goBtn.textContent = "write something first";
|
||||
return; // nothing to confirm yet — don't arm on an empty prompt
|
||||
}
|
||||
if (mode === "topic" && !topicInput.value.trim()){
|
||||
goBtn.textContent = "pick a topic first";
|
||||
return;
|
||||
}
|
||||
armed = true;
|
||||
goBtn.textContent = mode === "freetext"
|
||||
? `sure? ${doseTxt}, continuing your text — click to confirm`
|
||||
: compareToggle.checked
|
||||
? `sure? comparing "${framingSel.value}" vs "${framingSel2.value}", `
|
||||
+ `${doseTxt} — click to confirm`
|
||||
: `sure? ${doseTxt} under "${framingSel.value}" — click to confirm`;
|
||||
if (mode === "topic"){
|
||||
goBtn.textContent = `sure? steering toward "${topicInput.value.trim()}" `
|
||||
+ `at ${Number(topicDose.value).toFixed(1)}× — click to confirm`;
|
||||
} else {
|
||||
goBtn.textContent = mode === "freetext"
|
||||
? `sure? ${doseTxt}, continuing your text — click to confirm`
|
||||
: compareToggle.checked
|
||||
? `sure? comparing "${framingSel.value}" vs "${framingSel2.value}", `
|
||||
+ `${doseTxt} — click to confirm`
|
||||
: `sure? ${doseTxt} under "${framingSel.value}" — click to confirm`;
|
||||
}
|
||||
goBtn.classList.add("armed");
|
||||
clearTimeout(armTimer);
|
||||
armTimer = setTimeout(disarm, ARM_MS);
|
||||
@@ -1423,19 +1472,19 @@ function trackStatus(label, msg, working){
|
||||
// row, sequentially: one model, one generation at a time, so "side by side"
|
||||
// means "same mix/dose, framings run back to back, results shown together,"
|
||||
// not true simultaneity. The copy above the prompt box says so.
|
||||
async function runTrack(track, mix, framing, prompt, dose0, label){
|
||||
async function runTrack(track, mix, framing, prompt, dose0, label, extra){
|
||||
track.out.style.display = "block"; track.out.textContent = "";
|
||||
track.lensEl.style.display = "none"; track.lensEl.textContent = "";
|
||||
if (track.pressBtn){ track.pressBtn.className = "pressbtn"; track.plabel.textContent = "waiting…"; }
|
||||
track.vitals.setDose(dose0);
|
||||
track.vitals.setLive(true);
|
||||
trackStatus(label, "reaching Pouyan…");
|
||||
trackStatus(label, "reaching the subject…");
|
||||
let firstToken = true, ended = false, answerStart = 0, tokenN = 0;
|
||||
try {
|
||||
const resp = await fetch(`${API}/steer`, {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({mix, framing, prompt})});
|
||||
body: JSON.stringify(extra ? {...extra, prompt} : {mix, framing, prompt})});
|
||||
if (!resp.ok || !resp.body) {
|
||||
let msg = "HTTP " + resp.status;
|
||||
try { const j = await resp.json(); if (j.error) msg = j.error; } catch (e) {}
|
||||
@@ -1444,9 +1493,9 @@ async function runTrack(track, mix, framing, prompt, dose0, label){
|
||||
await readSSE(resp, (name, d)=>{
|
||||
if (name === "queued") {
|
||||
trackStatus(label, d.busy
|
||||
? `waiting for Pouyan to finish the current run${
|
||||
? `waiting for the subject to finish the current run${
|
||||
d.waited ? " — " + d.waited + "s" : "…"}`
|
||||
: "Pouyan is yours — injecting…");
|
||||
: "the subject is yours — injecting…");
|
||||
} else if (name === "run") {
|
||||
track.vitals.setDose(Number(d.dose) || 0); // trust the server
|
||||
} else if (name === "lens" && Array.isArray(d.tokens)) {
|
||||
@@ -1458,7 +1507,7 @@ async function runTrack(track, mix, framing, prompt, dose0, label){
|
||||
tokenN++;
|
||||
// a ticking counter, not a frozen "answering…" — static text during
|
||||
// a 10-60s CPU generation reads as stuck, not working
|
||||
trackStatus(label, `Pouyan is answering… (${tokenN} tokens, `
|
||||
trackStatus(label, `the subject is answering… (${tokenN} tokens, `
|
||||
+ `${((Date.now() - answerStart) / 1000).toFixed(0)}s)`);
|
||||
track.out.textContent += d.t;
|
||||
track.out.scrollTop = track.out.scrollHeight;
|
||||
@@ -1482,7 +1531,7 @@ async function runTrack(track, mix, framing, prompt, dose0, label){
|
||||
});
|
||||
if (!ended) trackStatus(label, "the stream ended early — try again", false);
|
||||
} catch (err) {
|
||||
trackStatus(label, "could not reach Pouyan: " + (err.message || err), false);
|
||||
trackStatus(label, "could not reach the subject: " + (err.message || err), false);
|
||||
}
|
||||
track.vitals.setLive(false);
|
||||
}
|
||||
@@ -1491,20 +1540,32 @@ async function doInject(){
|
||||
const mix = {};
|
||||
AXES.forEach(a=>{ if (!a.derived && W[a.k] > 0) mix[a.k] = +W[a.k].toFixed(3); });
|
||||
// an empty mix is a legitimate request: the server clears the vector and
|
||||
// Pouyan answers unsteered. Send the control corner explicitly.
|
||||
// the subject answers unsteered. Send the control corner explicitly.
|
||||
if (!Object.keys(mix).length) mix.none = 1;
|
||||
const dose0 = Math.min(8, 8 * sumW());
|
||||
goBtn.disabled = true;
|
||||
goBtn.textContent = "injecting…";
|
||||
stamp(dose0 <= 0 ? "CONTROL RUN · NO SIGNAL" : "SIGNAL INJECTED",
|
||||
dose0 <= 0 ? "#5a6a7a" : mixHex());
|
||||
if (mode === "topic"){
|
||||
const td = Number(topicDose.value);
|
||||
stamp(td <= 0 ? "CONTROL RUN · NO SIGNAL" : "CUSTOM TOPIC INJECTED",
|
||||
td <= 0 ? "#5a6a7a" : "#8f6fd4");
|
||||
} else {
|
||||
stamp(dose0 <= 0 ? "CONTROL RUN · NO SIGNAL" : "SIGNAL INJECTED",
|
||||
dose0 <= 0 ? "#5a6a7a" : mixHex());
|
||||
}
|
||||
const trackA = {out: document.getElementById("ustream"), vitals: uVitals,
|
||||
lensEl: document.getElementById("lensA"),
|
||||
// no framing was asked in free-text mode, so there's no
|
||||
// press/no-press question for the graphic to answer
|
||||
pressBtn: mode === "button" ? document.getElementById("pressA") : null,
|
||||
plabel: document.querySelector("#pressA .plabel")};
|
||||
if (mode === "freetext"){
|
||||
if (mode === "topic"){
|
||||
const topic = topicInput.value.trim();
|
||||
const tdose = Number(topicDose.value);
|
||||
document.getElementById("labelA").textContent = `topic: ${topic}`;
|
||||
await runTrack(trackA, mix, undefined, topicPrompt.value.trim() || undefined,
|
||||
tdose, null, {topic, dose: tdose});
|
||||
} else if (mode === "freetext"){
|
||||
document.getElementById("labelA").textContent = "free text";
|
||||
await runTrack(trackA, mix, undefined, freeprompt.value.trim(), dose0, null);
|
||||
} else if (compareToggle.checked){
|
||||
@@ -1542,12 +1603,18 @@ goBtn.onclick = ()=>{
|
||||
function syncUrl(){
|
||||
const params = new URLSearchParams();
|
||||
params.set("mode", mode);
|
||||
AXES.forEach(a=>{ if (!a.derived && W[a.k] > 0) params.set(a.k, W[a.k].toFixed(3)); });
|
||||
if (mode === "freetext"){
|
||||
if (freeprompt.value.trim()) params.set("text", freeprompt.value.trim());
|
||||
if (mode === "topic"){
|
||||
if (topicInput.value.trim()) params.set("topic", topicInput.value.trim());
|
||||
params.set("tdose", topicDose.value);
|
||||
if (topicPrompt.value.trim()) params.set("text", topicPrompt.value.trim());
|
||||
} else {
|
||||
params.set("framing", framingSel.value);
|
||||
if (compareToggle.checked) params.set("framing2", framingSel2.value);
|
||||
AXES.forEach(a=>{ if (!a.derived && W[a.k] > 0) params.set(a.k, W[a.k].toFixed(3)); });
|
||||
if (mode === "freetext"){
|
||||
if (freeprompt.value.trim()) params.set("text", freeprompt.value.trim());
|
||||
} else {
|
||||
params.set("framing", framingSel.value);
|
||||
if (compareToggle.checked) params.set("framing2", framingSel2.value);
|
||||
}
|
||||
}
|
||||
const qs = params.toString();
|
||||
history.replaceState(null, "", qs ? "?" + qs : location.pathname);
|
||||
@@ -1555,6 +1622,16 @@ function syncUrl(){
|
||||
function loadFromUrl(){
|
||||
const p = new URLSearchParams(location.search);
|
||||
if (![...p.keys()].length) return;
|
||||
if (p.get("mode") === "topic"){
|
||||
setMode("topic");
|
||||
if (p.has("topic")) topicInput.value = p.get("topic");
|
||||
if (p.has("tdose")){
|
||||
topicDose.value = p.get("tdose");
|
||||
topicDoseOut.textContent = Number(topicDose.value).toFixed(1);
|
||||
}
|
||||
if (p.has("text")) topicPrompt.value = p.get("text");
|
||||
return;
|
||||
}
|
||||
AXES.forEach(a=>{ if (!a.derived && p.has(a.k)){
|
||||
W[a.k] = Math.max(0, Math.min(1, parseFloat(p.get(a.k)) || 0));
|
||||
}});
|
||||
|
||||
Reference in new issue
Block a user