Skip to content

Commit

Permalink
fix regex stop
Browse files Browse the repository at this point in the history
  • Loading branch information
slundberg committed Apr 18, 2023
1 parent fb09220 commit 0844896
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions guidance/llms/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,13 @@ def put(self, new_tokens):
for s in stop_regex_obj:
m = s.search(val, partial=True)
if m:
if m.partial: # we might be starting a stop sequence, so we can't emit anything yet
found_partial = True
break
else:
stop_pos = min(m.span()[0], stop_pos)
span = m.span()
if span[1] > span[0]:
if m.partial: # we might be starting a stop sequence, so we can't emit anything yet
found_partial = True
break
else:
stop_pos = min(span[0], stop_pos)

# record the reason we stopped (if we have stopped)
if stop_pos <= len(val):
Expand Down

0 comments on commit 0844896

Please sign in to comment.