guidance icon indicating copy to clipboard operation
guidance copied to clipboard

Select fails with IndexError when there is nothing before it

Open dstoc opened this issue 1 year ago • 0 comments

The bug Select fails with the following when there is nothing before it:

File ~/anaconda3/lib/python3.9/site-packages/guidance/library/_select.py:81, in select.<locals>.recursive_select(current_prefix, allow_token_extension)
     78 option_tokens = parser.program.llm.encode(parser_prefix[-50:] + option)
     80 # if we extended the last token to a longer one
---> 81 if option_tokens[len(tmp_prefix_tokens)-1] != tmp_prefix_tokens[-1]:
     82     if allow_token_extension: # this is a valid extension only if we are not allowed to extend the token
     83         logit_bias1[option_tokens[len(tmp_prefix_tokens)-1]] = 100

IndexError: list index out of range

To Reproduce

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

System info:

  • OS: WSL2
  • Guidance Version: 0.0.49

dstoc avatar May 20 '23 11:05 dstoc