"""Validate the GGUF brain returns the same valid 3-channel JSON as the Modal backend, on the SAME inputs train/brain_serve.py was validated on. uv run --group train --with llama-cpp-python python scripts/validate_brain_gguf.py \ --gguf data/gguf/yui-brain1-sft1.Q4_K_M.gguf """ from __future__ import annotations import argparse import json import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from voice.brain import LlamaCppBrain # noqa: E402 # The exact devices_block from train/brain_serve.py main() — the Modal validation input. DEVICES = ( "light.kitchen 'Kitchen Light' = off\n" "light.living_room 'Living Room Light' = on;60%\n" "lock.front_door 'Front Door' = locked\n" "cover.garage 'Garage Door' = closed" ) TIME = "3:45 PM on Tuesday, June 10 2026" # fixed so output is reproducible CASES = [ ("turn on the kitchen light", "intents"), ("is the front door locked?", "response"), ] def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("--gguf", default="data/gguf/yui-brain1-sft1.Q4_K_M.gguf") args = ap.parse_args() brain = LlamaCppBrain(model_path=args.gguf, n_gpu_layers=0, verbose=False) for utt, expect_key in CASES: out = brain.infer(DEVICES, utt, TIME) ok = expect_key in out and not out.get("_parse_error") print(f"\nutterance : {utt}") print(f"expect : top key '{expect_key}'") print(f"output : {json.dumps(out, ensure_ascii=False)}") print(f"valid : {ok}") if __name__ == "__main__": main()