diff --git a/guidance/models/_model.py b/guidance/models/_model.py index 1b366118e..082138119 100644 --- a/guidance/models/_model.py +++ b/guidance/models/_model.py @@ -14,13 +14,16 @@ import time import numpy as np import logging -from .. import cpp as cpp +logger = logging.getLogger(__name__) +try: + from .. import cpp +except ImportError: + logger.warn("Failed to load guidance.cpp, falling back to Python mirror implementations...") + from .. import _cpp as cpp from .._utils import ByteTrie, log_softmax, softmax from .._parser import EarleyCommitParser from .._grammar import StatelessFunction, string, _call_pool, _tag_pattern, Null, replace_model_variables, unreplace_model_variables, select, Terminal -logger = logging.getLogger(__name__) - # define some constants we will reuse many times _null_grammar = string('') format_pattern = re.compile(r"<\|\|_.*?_\|\|>", flags=re.DOTALL)