Skip to content

Commit 9d458bc

Browse files
committed
Fix commit point hiding
1 parent 0afe462 commit 9d458bc

File tree

5 files changed

+89
-76
lines changed

5 files changed

+89
-76
lines changed

guidance/_parser.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ def consume_byte(self, byte, log_prob=0.0):
252252
found_invalid = False
253253
hidden_start = 10000000000
254254
for item in self.state_sets[self.state_set_pos + 1]:
255-
if item.pos > 0 and isinstance(item.values[item.pos - 1], Terminal):
255+
token_span = self.token_counts[-1] - self.token_counts[item.start]
256+
if item.node.max_tokens <= token_span:
257+
found_invalid = True
258+
continue
259+
elif item.pos > 0 and isinstance(item.values[item.pos - 1], Terminal):
256260
last_inner_node = item.values[item.pos - 1]
257261
if not last_inner_node.match_byte(byte):
258262
found_invalid = True
@@ -390,10 +394,12 @@ def parse_tree(self):
390394
self._compute_parse_tree(0, root_item, reversed_state_sets)
391395
return root_item
392396

393-
def get_captures(self):
397+
def get_captures(self, data=None, log_prob_data=None):
394398
root_node = self.parse_tree()
395-
data = {}
396-
log_prob_data = {}
399+
if data is None:
400+
data = {}
401+
if log_prob_data is None:
402+
log_prob_data = {}
397403
if root_node is not None:
398404
# parse complete, so we can get the captures
399405
self._record_captures_from_root(root_node, data, log_prob_data)

0 commit comments

Comments
 (0)