"""Shared: build the exact jev-ultrafast systemone request for a page + goal, with the server-side compaction.""" import importlib.util, json, sys, types JEV = "/home/ckl/projects/S/jev-ultrafast/jev_ultrafast" # load model.py / questions.py without running the package __init__ (which pulls in browser-harness) if "jev_ultrafast" not in sys.modules: _pkg = types.ModuleType("jev_ultrafast"); _pkg.__path__ = [JEV]; sys.modules["jev_ultrafast"] = _pkg for _name in ("questions", "model"): _spec = importlib.util.spec_from_file_location(f"jev_ultrafast.{_name}", f"{JEV}/{_name}.py") _m = importlib.util.module_from_spec(_spec); sys.modules[_spec.name] = _m; _spec.loader.exec_module(_m) from jev_ultrafast.model import action_space # noqa: E402 from jev_ultrafast.questions import GOAL_DONE, NEXT_ACTION, TARGET # noqa: E402 import os import re FMT = os.environ.get("LAYA_FMT", "v1") # v1: jev's state verbatim (page text up to 6000 chars + the whole element table as JSON) -- the 1024-token budget truncates # most of it, so the model often never sees the candidates' context. 3000 chars was tried (v7): -0.04 top-1. # v2: elements live only in the option list (full label + role + value); state keeps title/url/history and 1500 chars of text. # v3: v2 + option labels capped at 50 chars and 1200 chars of text (~30% fewer tokens; for the 322M base to hit ~20 ms/step) # v4: v3 + no duplicate "[key] " before each option label, and option ("[i:k] Field label → Option") keep the option name.""" el = str(el) if len(el) <= n: return el if " → " in el: head, opt = el.rsplit(" → ", 1) opt = " ".join(opt.split())[:40] keep = max(12, n - len(opt) - 3) return " ".join(head.split())[:keep] + " → " + opt return el[:n] def compact(v): if isinstance(v, dict) and "element" in v: el = str(v["element"]) if FMT in ("v4", "v5", "v6"): # v4: the option key is already rendered by laya (": ..."), so drop the duplicate "[key] "; a