Skip to content

Commit

Permalink
Optimistically try to trace all functions
Browse files Browse the repository at this point in the history
  • Loading branch information
slundberg committed May 6, 2024
1 parent 631ff1a commit 7d7a96b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions guidance/_guidance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import inspect

from . import models
from ._grammar import Placeholder, RawFunction, Terminal, replace_grammar_node, string
from ._grammar import Placeholder, RawFunction, Terminal, replace_grammar_node, string, StatefulException
from ._utils import strip_multiline_string_indents


Expand Down Expand Up @@ -36,9 +36,7 @@ def _decorator(f, *, stateless, cache, dedent, model):
def wrapped(*args, **kwargs):

# make a stateless grammar if we can
if stateless is True or (
callable(stateless) and stateless(*args, **kwargs)
):
try:

# if we have a placeholder set then we must be in a recursive definition and so we return the placeholder
placeholder = getattr(f, "_self_call_placeholder_", None)
Expand Down Expand Up @@ -66,7 +64,7 @@ def wrapped(*args, **kwargs):
return node

# otherwise must be stateful (which means we can't be inside a select() call)
else:
except StatefulException:
return RawFunction(f, args, kwargs)

# Remove the first argument from the wrapped function
Expand Down

0 comments on commit 7d7a96b

Please sign in to comment.