oracle7-slim / workbench /kernel /kernel_v5.py
psiloceyeben's picture
Release 12.0 (slim): one browser harness that converses, writes from held sources and builds what you describe, keeping each request through corrections and restarts. No language model. (part 4)
2419253 verified
Raw History Blame Contribute Delete
3.04 kB
#!/usr/bin/env python3
"""The Oracle7 kernel, v5: kernel v4 plus the class fix from KERNEL SEALED 2 (m13: "What power, in kilowatts, must the
motor supply? (Neglect friction.)" was answered in watts: the goal reader read the LAST sentence, the parenthetical, so the
asked-for unit was never seen). The goal, like the wanted quantity since v4, is read from the ASKING sentence.
Also the pack front door: Kernel5() with no arguments reads the specialists the released head stands (the union of its
standing lists) from this install, and `python oracle7.py kernel "question"` asks it.
usage: python oracle7.py kernel "question" [--json] | python oracle7.py kernel faces"""
from __future__ import annotations
import json
import os
import sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
sys.path.insert(0, str(HERE))
from kernel_v4 import Kernel4, reader # noqa: E402
INSTALL = Path(os.environ.get("O7_KERNEL_TREE", HERE.parents[1]))
SPEC = INSTALL / "root" / "specialists"
GATE = SPEC / "_gate"
LISTS = ("standing_v2.txt", "standing_new_v1.txt", "standing_new_v2.txt", "standing_new_v3.txt", "standing_new_v4.txt",
"standing_new_v5.txt", "standing_owner_v1.txt", "standing_stars_v1.txt", "standing_net_v6.txt")
def pack_standing():
ids = set()
for n in LISTS:
p = GATE / n
if p.exists():
ids |= set(p.read_text(encoding="utf-8").split())
return sorted(ids)
class Kernel5(Kernel4):
def __init__(self, standing=None, spec_root=None, combo=None):
super().__init__(standing or pack_standing(), str(spec_root or SPEC), str(combo or GATE))
def goal_of(self, text):
t = reader.normalise(text)
g = reader.read_goal(self._asking(t)) # the asked-for unit is in the asking sentence
if g is not None:
return g
return super().goal_of(text)
def cli(rest):
as_json = "--json" in rest
rest = [x for x in rest if x != "--json"]
k = Kernel5()
if rest[:1] == ["faces"]:
print("declared faces (formula parts): %d over %d (quantity, dimension) keys" % (len(k.declared.parts), len(k.declared.keys)))
print("induced faces (specialists, learned from their own examples): %d" % len(k.induced.faces))
return 0
if not rest:
print(__doc__)
return 0
r = k.solve(" ".join(rest))
if as_json:
print(json.dumps(r, indent=1, default=str))
return 0
if r.get("status") == "answered":
print(r["answer"])
path = r.get("path") or [t.get("node") for t in r.get("trace", []) if t.get("node")]
print(" [answered, %s reading] path: %s" % (r.get("reading", "induced"), " -> ".join(map(str, path)) or "core arithmetic"))
else:
print("I can't answer that with a checked path: %s" % (r.get("reason") or "no path"))
print(" [declined] this goes to the holes as: %s" % json.dumps(r.get("hole") or {"question": " ".join(rest)})[:300])
return 0
if __name__ == "__main__":
sys.exit(cli(sys.argv[1:]))