Unverified Commit 906d795f authored by gobraves's avatar gobraves Committed by GitHub
Browse files

Feat: upgrade outlines & support compatibility with the old version (#2292)

parent 118b6af3
...@@ -152,7 +152,12 @@ class OutlinesGrammarBackend(BaseGrammarBackend): ...@@ -152,7 +152,12 @@ class OutlinesGrammarBackend(BaseGrammarBackend):
raise ValueError(f"Invalid key_type: {key_type}") raise ValueError(f"Invalid key_type: {key_type}")
try: 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: except interegular.patterns.InvalidSyntax as e:
logger.warning(f"skip invalid regex schema: {regex=}, {e=}") logger.warning(f"skip invalid regex schema: {regex=}, {e=}")
return None return None
......
...@@ -23,7 +23,14 @@ from collections import defaultdict ...@@ -23,7 +23,14 @@ from collections import defaultdict
import interegular import interegular
from interegular import InvalidSyntax from interegular import InvalidSyntax
from outlines.caching import cache as disk_cache 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?)" IP_REGEX = r"((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment