Skip to content

Commit

Permalink
feat(choice): escape strings
Browse files Browse the repository at this point in the history
  • Loading branch information
g-prz committed Nov 27, 2024
1 parent 5e78c7b commit 33df55a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions outlines/generate/choice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json as pyjson
import re
from enum import Enum
from functools import singledispatch
from typing import Callable, List, Union
Expand All @@ -19,6 +20,7 @@ def choice(
if isinstance(choices, type(Enum)):
regex_str = build_regex_from_schema(pyjson.dumps(get_schema_from_enum(choices)))
else:
choices = [re.escape(choice) for choice in choices] # type: ignore
regex_str = r"(" + r"|".join(choices) + r")"

generator = regex(model, regex_str, sampler)
Expand Down

0 comments on commit 33df55a

Please sign in to comment.