From 3bd28dc3cad6b8f6f238f9a017464ec5641d718a Mon Sep 17 00:00:00 2001 From: Andrew Lapp Date: Thu, 16 May 2024 20:49:30 -0500 Subject: [PATCH] use simpler xor pattern without negative lookahead for OneOf --- outlines/fsm/json_schema.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/outlines/fsm/json_schema.py b/outlines/fsm/json_schema.py index d96597d4c..2c53fd240 100644 --- a/outlines/fsm/json_schema.py +++ b/outlines/fsm/json_schema.py @@ -195,13 +195,7 @@ def to_regex( to_regex(resolver, t, whitespace_pattern) for t in instance["oneOf"] ] - xor_patterns = [] - # json schema validation ensured there is no overlapping schemas in oneOf - for subregex in subregexes: - other_subregexes = filter(lambda r: r != subregex, subregexes) - other_subregexes_str = "|".join([f"{s}" for s in other_subregexes]) - negative_lookahead = f"(?!.*({other_subregexes_str}))" - xor_patterns.append(f"({subregex}){negative_lookahead}") + xor_patterns = [f"(?:{subregex})" for subregex in subregexes] return rf"({'|'.join(xor_patterns)})"