"""Decision Index engine for Aurelis served by Ollama (/v1/systemone). Fixed rules, the same for every request of every benchmark: - Ollama refuses an empty state, so an empty state is sent as "(no state)". - Ollama accepts at most 24 options per question for a tev1 model. A question with more is answered in two rounds: the options are split into groups of 24 in their given order, each group is asked, and the group winners are asked once more. No option is dropped; an option's probability is its share inside its group times its group winner's final share. (Runs up to and including runs/aurelis-v5 used groups of 26.) - An option whose description is empty is sent without one (Ollama then uses the option's key). Prompts longer than the context window are refused by Ollama (never truncated) and recorded as "unsupported". (Ollama 0.40.5 words that refusal "prompt N has ... tokens; ... input is never truncated"; Ollama builds that serve through llama-server word it "request (N tokens) exceeds the available context size"; both are matched.) 2026-10-13: every Ollama build of Aurelis up to 2b-v5 carried the decision type under a GGUF key Ollama does not look up (decision.type instead of llama.decision.type), so Ollama used its default prompt layout, which lists every question of a request in each prompt, instead of the tev1 layout the model is trained on. One question per request still worked; several did not: the same candidate got 0.05 asked alone and 0.95 asked sixth of six. All runs up to runs/aurelis-v5 were made that way. Builds made with "RENDERER tev1" in the Modelfile (local names aurelis-VERSION-tev1) or exported after the fix in decidetrain.py answer each question on its own, the same whether asked together or alone. single=1 sends every question as a request of its own; it is only needed for an old build. """ import json, os from decision_index.engines.base import Engine, Unsupported, text from decision_index.engines.http import CAPACITY_MARKERS class AurelisOllama(Engine): name = "aurelis-ollama" latency = "HTTP request wall time against a local Ollama /v1/systemone endpoint, including prompt construction and inference." def __init__(self, base_url="http://127.0.0.1:11434", model="mrscratchcat22/aurelis:2b-v3", num_ctx=16384, timeout=600, single=0, max_options=24, **options): super().__init__(**options) self.single = str(single) not in ("0", "false", "False"); self.MAX_OPTIONS = int(max_options) import httpx self.model = model self.client = httpx.Client(base_url=base_url, timeout=timeout) self.provenance = {"kind": "ollama", "model": model, "num_ctx": num_ctx, "single": self.single, "policy": "state and questions sent unmodified, " + ("each question as its own /v1/systemone request" if self.single else "as one /v1/systemone request") + ", except that an empty state is sent as '(no state)' and questions with more options than " + str(self.MAX_OPTIONS) + " are answered in two rounds over groups of that size; prompts over the context window are refused, never truncated"} MAX_OPTIONS = 24 # Ollama's limit per choice question for a tev1 model (26 for its default layout) def post(self, st, questions): if self.single and len(questions) > 1: out = {"model": self.model, "answers": {}} for k, q in questions.items(): out["answers"].update(self.post(st, {k: q})["answers"]) return out r = self.client.post("/v1/systemone", json={"model": self.model, "state": st, "questions": questions, "keep_alive": "60m"}) if r.status_code in (400, 413, 422) and any(s in r.text for s in CAPACITY_MARKERS + ("input is never truncated", "must not exceed 64 KiB", "exceeds the available context size")): raise Unsupported(r.text[:300]) if r.status_code >= 400: raise RuntimeError(f"HTTP {r.status_code}: {r.text[:300]}") return r.json() def __call__(self, state, questions): st = text(state) if state not in ("", None, {}, []) else "(no state)" if not st.strip(): st = "(no state)" # descriptions are sent as text; a question with more options than Ollama accepts is answered in two rounds qs = {k: (dict(q, criteria={o: (None if d is None or not text(d).strip() else text(d)) for o, d in q["criteria"].items()}) if q.get("criteria") else q) for k, q in questions.items()} small = {k: q for k, q in qs.items() if len(q.get("criteria") or {}) <= self.MAX_OPTIONS} raw = self.post(st, small) if small else {"model": self.model, "answers": {}} answers = dict(raw.get("answers", {})) for k, q in qs.items(): if k in small: continue items = list(q["criteria"].items()); n = self.MAX_OPTIONS if len(items) > n * n: raise Unsupported(f"{len(items)} options per choice exceeds the limit of {n * n}") groups = [dict(items[i:i + n]) for i in range(0, len(items), n)] if len(groups[-1]) == 1: groups[-2].pop(k2 := items[-2][0]); groups[-1] = dict([items[-2], items[-1]]) first = self.post(st, {f"g{i}": dict(q, criteria=g) for i, g in enumerate(groups)})["answers"] winners = {first[f"g{i}"]["choice"]: q["criteria"][first[f"g{i}"]["choice"]] for i in range(len(groups))} final = self.post(st, {"f": dict(q, criteria=winners)})["answers"]["f"] probs = {} for i, g in enumerate(groups): w = first[f"g{i}"]["choice"]; pw = first[f"g{i}"]["probabilities"][w] or 1e-9 for o in g: probs[o] = final["probabilities"][w] * first[f"g{i}"]["probabilities"][o] / pw z = sum(probs.values()); probs = {o: min(1.0, v / z) for o, v in probs.items()} answers[k] = {"type": "choice", "choice": max(probs, key=probs.get), "probabilities": probs} out = {"model": self.model, "answers": {k: answers[k] for k in questions}} return out, out def close(self): self.client.close()