Something went wrong. Try again.
a tiny pet with a GPT-2 brain, living in your browser
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142// Checks the shared rules (core/, as the browser's WebAssembly build) render// prompts byte-identically to train/world.py. Run core/wasm/build.sh first.import { execFileSync } from "node:child_process";import { readFileSync } from "node:fs";import { fileURLToPath } from "node:url";import * as C from "../web/core.ts";const here = fileURLToPath(new URL(".", import.meta.url));C.initCoreSync(readFileSync(new URL("../core/wasm/pkg/tokenling_core_bg.wasm", import.meta.url)));const { cases, lists } = JSON.parse(execFileSync("python3", [here + "parity_states.py", "1"], { maxBuffer: 1 << 26 }));let bad = 0;for (const [k, py] of Object.entries(lists)) { if (JSON.stringify(C.L[k]) !== JSON.stringify(py)) { bad++; console.log(k, JSON.stringify(C.L[k]), "!=", JSON.stringify(py)); }}// Every app event line must match exactly one Python pattern (the training// validator), and offers must be recognised as offers.const E = (name, o, p, arg) => C.event(name, o, p, arg);for (const c of cases) { const wake = ["talk", "touch", "light"].flatMap((k) => Array.from({ length: 6 }, (_, n) => C.wakeChance(c.st.stats.energy, k, n + 1))); if (wake.some((v, i) => Math.abs(v - c.wake[i]) > 1e-12)) { bad++; console.log("wake chance mismatch"); } for (const [k, got] of [["chat", C.header("chat", c.st)], ["diary", C.header("diary", c.st)], ["look", C.toolResult(c.st, "look")], ["clock", C.toolResult(c.st, "clock")], ["recall", C.recall(c.st.memories, c.q)], ["recall", C.toolResult(c.st, "recall", c.q)]]) { if (got !== c[k]) { bad++; if (bad < 4) console.log(k, JSON.stringify(got), "!=", JSON.stringify(c[k])); } } const o = c.st.owner, p = c.st.pet; const evs = c.events.map((r) => new RegExp("^" + r + "$")), offers = c.offers.map((r) => new RegExp("^" + r + "$")); const lines = [...C.L.FOODS.map((f) => [E("offerFood", o, p, f), true]), [E("offerBath", o, p), true], [E("offerMedicine", o, p), true], [E("offerCatch", o, p), true], [E("caught", o, p, "1"), false], [E("caught", o, p, "7"), false], [E("pat", o, p), false], [E("lights", o, p, "on"), false], [E("lights", o, p, "off"), false], [E("woke", o, p), false], [E("pooped", o, p), false], [E("cleaned", o, p), false], [E("back", o, p, "3 hours"), false], [E("back", o, p, "1 day"), false], ...["kid", "teen", "adult"].map((s) => [E("grew", o, p, s), false])]; for (const [line, isOffer] of lines) { if (evs.filter((r) => r.test(line)).length !== 1 || offers.some((r) => r.test(line)) !== isOffer) { bad++; if (bad < 8) console.log("event", JSON.stringify(line), isOffer ? "(offer)" : ""); } }}// The parity fixture names the lists Python has; the core also lists body colours.const extra = Object.keys(C.L).filter((k) => !(k in lists));if (JSON.stringify(extra) !== JSON.stringify(["COLORS"])) { bad++; console.log("unexpected lists", extra); }console.log(`${cases.length} states, ${Object.keys(lists).length} word lists, ${bad} mismatches`);process.exit(bad ? 1 : 0);