guidance.select

guidance.select(options: Sequence[str | int | float | GrammarNode], name: str | None = None, list_append: bool = False) GrammarNode

Choose between a set of options.

This function constrains the next generation from the LLM to be one of the given options. If the list only has a single element, then that value can be returned immediately, without calling the LLM.

>>> lm += select(["Temeraire", "Redoutable", "Bucentaure"], name="my_selection")
>>> print(lm["my_selection"])
Temeraire
Parameters:
namestr or None

If this is not None then the the results of the generation will be saved as a variable on the Model object (so you can access the result as lm[“var_name”]).

optionslist

The set of available choices for the next generation

list_appendbool

If this is True then the results saved to lm[name] will not be written directly but rather appended to a list (if no list with the current name is present one will be created). This is useful for building lists inside python loops.