From 084489605b08f32451c7f1c16995f37c14d7d68c Mon Sep 17 00:00:00 2001 From: Scott Lundberg Date: Tue, 18 Apr 2023 11:10:54 -0700 Subject: [PATCH] fix regex stop --- guidance/llms/_transformers.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/guidance/llms/_transformers.py b/guidance/llms/_transformers.py index 7791718e4..ec27ffb5f 100644 --- a/guidance/llms/_transformers.py +++ b/guidance/llms/_transformers.py @@ -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):