Feat: upgrade outlines & support compatibility with the old version (#2292)
This commit is contained in:
@@ -152,7 +152,12 @@ class OutlinesGrammarBackend(BaseGrammarBackend):
|
||||
raise ValueError(f"Invalid key_type: {key_type}")
|
||||
|
||||
try:
|
||||
guide = RegexGuide(regex, self.outlines_tokenizer)
|
||||
if hasattr(RegexGuide, "from_regex"):
|
||||
# outlines >= 0.1.1
|
||||
guide = RegexGuide.from_regex(regex, self.outlines_tokenizer)
|
||||
else:
|
||||
# outlines <= 0.0.46
|
||||
guide = RegexGuide(regex, self.outlines_tokenizer)
|
||||
except interegular.patterns.InvalidSyntax as e:
|
||||
logger.warning(f"skip invalid regex schema: {regex=}, {e=}")
|
||||
return None
|
||||
|
||||
@@ -23,7 +23,14 @@ from collections import defaultdict
|
||||
import interegular
|
||||
from interegular import InvalidSyntax
|
||||
from outlines.caching import cache as disk_cache
|
||||
from outlines.fsm.regex import FSMInfo, make_byte_level_fsm, make_deterministic_fsm
|
||||
|
||||
try:
|
||||
# outlines >= 0.1.0
|
||||
from outlines_core.fsm.outlines_core_rs import FSMInfo
|
||||
from outlines_core.fsm.regex import make_byte_level_fsm, make_deterministic_fsm
|
||||
except ImportError:
|
||||
# outlines <= 0.0.46
|
||||
from outlines.fsm.regex import FSMInfo, make_byte_level_fsm, make_deterministic_fsm
|
||||
|
||||
IP_REGEX = r"((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user