guidance icon indicating copy to clipboard operation
guidance copied to clipboard

Select causes UnboundLocalError

Open dstoc opened this issue 1 year ago • 1 comments

The bug Select fails with the following, possibly when one option is the prefix of another:

File ~/anaconda3/lib/python3.9/site-packages/guidance/library/_select.py:68, in select.<locals>.recursive_select(current_prefix, allow_token_extension)
     66         if len(set([o[0][i] for o in extension_options])) > 1:
     67             break
---> 68     if i > 0:
     69         current_prefix += extension_options[0][0][:i]
     70         # extension_options = [(option[i:], index) for option,index in extension_options]
     71 
     72 # bias the logits towards valid options

UnboundLocalError: local variable 'i' referenced before assignment

To Reproduce

options = ['a', 'aa']
program = guidance("'{{select options=options}}")
program(options=options)

System info (please complete the following information):

  • OS: WSL2
  • Guidance Version: 0.0.49

dstoc avatar May 20 '23 11:05 dstoc

Thanks! I added that when cleaning up select yesterday. Will push a fix soon, and add options that are prefixes of another to the unit tests.

slundberg avatar May 20 '23 14:05 slundberg