Choice

Choice#

Gives the assistant the ability to present multiple-choice options to the user for selection.

Instructions

The options can be provided as a question on the first line and each option on a separate line.
When using the ``options`` keyword argument, options may also be comma-separated.

The tool will present an interactive menu allowing the user to select an option using arrow keys and Enter, or by typing the number of the option.

### When to use choice

Use when you need to present the user with a discrete set of named alternatives and free-text input would be ambiguous. Don't use for simple yes/no confirmations; don't use when the next step is already clear from context.

Examples

Basic usage with options

User
What should we do next?
Assistant
Let me present you with some options:
choice
What would you like to do next?
Write documentation
Fix bugs
Add new features
Run tests
System
User selected: Add new features
User
What should we do next?
Assistant
Let me present you with some options:
choice
Example question?
1. Option one
2. Option two
System
User selected: Option two
gptme.tools.choice.execute_choice(code: str | None, args: list[str] | None, kwargs: dict[str, str] | None) Generator[Message, None, None]

Present multiple-choice options to the user and return their selection.

gptme.tools.choice.parse_options_from_content(content: str) tuple[str | None, list[str]]

Parse options from content, returning (question, options).

gptme.tools.choice.parse_options_from_kwargs(kwargs: dict[str, str]) tuple[str | None, list[str]]

Parse options from args and kwargs, returning (question, options).