diff --git a/controllers/llguidance_ctrl/run_g.py b/controllers/llguidance_ctrl/run_g.py index 5f054293..c4483098 100644 --- a/controllers/llguidance_ctrl/run_g.py +++ b/controllers/llguidance_ctrl/run_g.py @@ -266,9 +266,19 @@ def character_maker2(lm, id, description, valid_weapons): assert grm.match("null") grm = guidance.json( - schema={"type": "object", "properties": {"a": {"type": "integer"}}} + "OBJ", + schema={ + "type": "object", + "additionalProperties": False, + "properties": {"age": {"type": "integer"}}, + } ) - assert grm.match('{"a": 1}') + # assert grm.match('{"a": 1}') + prompt = "" + grm = "Here's some JSON:\n" + grm # + "\nAnd some more:\n" + grm + + # g = zero_or_more("a") + "b" + # assert not g.match("b") max_tokens = 250 @@ -282,6 +292,9 @@ def character_maker2(lm, id, description, valid_weapons): print("JSON size:", len(llguidance_arg), "saved to tmp/llguidance_arg.json") # print(json.dumps(llguidance_json, indent=2)) + # with open("tmp/long_json_grammar_req.json", "r") as f: + # llguidance_arg = f.read() + # read current script file # with open(__file__) as f: # script = f.read() diff --git a/controllers/llguidance_ctrl/src/tokenparser.rs b/controllers/llguidance_ctrl/src/tokenparser.rs index 7dcb3322..db8b13b1 100644 --- a/controllers/llguidance_ctrl/src/tokenparser.rs +++ b/controllers/llguidance_ctrl/src/tokenparser.rs @@ -114,7 +114,9 @@ impl TokenParser { idx += self.grm_prefix.len(); let endp = std::cmp::min( self.llm_bytes.len(), - self.previous_grm_bytes.len() + self.parser.hidden_start(), + self.previous_grm_bytes + .len() + .saturating_add(self.parser.hidden_start()), ); if idx >= self.llm_bytes.len() || idx >= endp { return &[]; diff --git a/py/llguidance/pyproject.toml b/py/llguidance/pyproject.toml index 380e42ad..db3e2153 100644 --- a/py/llguidance/pyproject.toml +++ b/py/llguidance/pyproject.toml @@ -17,4 +17,5 @@ find = { where = ["python"] } target = "llguidance._lib" binding = "PyO3" debug = false +# features = ["aici_llguidance_ctrl/logging"] # See reference for RustExtension in https://setuptools-rust.readthedocs.io/en/latest/reference.html