-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dedent=True doesn't work in python 3.12 #942
Comments
I've noticed the dedent kwarg but didn't previously know what it was doing... Essentially we are introspecting on the source code and rewriting it as if the user had written Do you know if this behavior is documented anywhere? Is it important to maintain? @Harsha-Nori any opinions/thoughts? |
Python 3.12 had major changes to f-string behavior, so it doesn't surprise me that dedent is acting up now. Thanks for catching this! @hudson-ai I don't know that we ever documented it, but the idea is to follow the same semantics as textwrap.dedent (ignore leading spaces) so that you can do natural in-line f-strings without having to undo all the indentation if you're in an already nested python block. If we don't have this, the f-string syntax for writing guidance programs gets quite ugly since every line after the first needs to be on the 0-indent level, eg: def prog(lm):
if blah:
lm += f"""first line
second line
third line"""
return lm |
Understood. That is indeed nice to have... |
Just messing around a little with this (on Windows.... same behaviour), and the call to dedent happens here: Line 95 in 4f7bf9e
The result on Python 3.11 is @guidance(stateless=True, dedent=True)
def character_maker2(lm):
lm += f"""\
{{
"name": "{guidance.gen('name', stop='"', max_tokens=1)}",
}}"""
return lm and on Python 3.12 @guidance(stateless=True, dedent=True)
def character_maker2(lm):
lm += f"""\
{{
"name": "{guidance.gen('name', stop='"', max_tokens=1)}",
}}"""
return lm which looks rather similar. |
And continued prodding, this is definitely to do with something changing in how f-strings are handled, rather than In Python 3.12, the next portion of
Note in particular the line |
The bug
The
dedend=True
argument to@guidance
decorator seems to work in 3.10 and 3.11 but not in 3.12.To Reproduce
The test below passes in 3.11 but not 3.12 on macOS x86.
System info (please complete the following information):
guidance.__version__
): 0.1.15The text was updated successfully, but these errors were encountered: