From 33df55a5b521a3e0e193f23e8403552d5063f5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl?= Date: Mon, 25 Nov 2024 11:37:09 +0000 Subject: [PATCH] feat(choice): escape strings --- outlines/generate/choice.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/outlines/generate/choice.py b/outlines/generate/choice.py index 72b5e3efd..92213c3df 100644 --- a/outlines/generate/choice.py +++ b/outlines/generate/choice.py @@ -1,4 +1,5 @@ import json as pyjson +import re from enum import Enum from functools import singledispatch from typing import Callable, List, Union @@ -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)