select()
Select one or more options from a given list or type representing a set of options.
API Reference
select()
Synchronously select one or more options from the given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Any | List[Any]
|
The options to select from. Can be: - A list of values or types - A Literal[...] type - An Enum subclass - A Union[..., ...] type |
required |
context
|
ContextType | List[ContextType] | None
|
Optional additional context or conversation history. Defaults to None. |
None
|
multi_label
|
bool
|
When True, return a list of selected objects; otherwise return a single selected object. Defaults to False. |
False
|
literal
|
bool
|
When True and supported by the options, use Literal[...] for the selection field instead of indices. Defaults to True. |
True
|
include_reason
|
bool
|
Reserved flag to include a textual reason field in the intermediate structured output (not exposed in the final result). Defaults to False. |
False
|
confidence
|
bool
|
When True, enable log-probability based confidence scoring. Defaults to False. |
False
|
model
|
ModelParam
|
The model to use for selection. Defaults to "openai:gpt-4o-mini". |
'openai:gpt-4o-mini'
|
model_settings
|
PydanticAIModelSettings | None
|
Model settings to pass to the operation (e.g., temperature). Defaults to None. |
None
|
instructions
|
PydanticAIInstructions | None
|
Additional instructions/hints for the model. Defaults to None. |
None
|
tools
|
ToolType | List[ToolType] | None
|
List of tools available to the model. Defaults to None. |
None
|
deps
|
Deps | None
|
Optional dependencies (e.g., |
None
|
usage_limits
|
PydanticAIUsageLimits | None
|
Usage limits (token/request) configuration. Defaults to None. |
None
|
stream
|
bool
|
When True, return a stream wrapper that exposes the underlying model stream and remaps the final result to the selected object(s). Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Result[Output] | _SelectionStreamWrapper
|
Result[Output] | _SelectionStreamWrapper: A |
aselect()
Asynchronously select one or more options from the given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Any | List[Any]
|
The options to select from. Can be: - A list of values or types - A Literal[...] type - An Enum subclass - A Union[..., ...] type |
required |
context
|
ContextType | List[ContextType] | None
|
Optional additional context or conversation history. Defaults to None. |
None
|
multi_label
|
bool
|
When True, return a list of selected objects; otherwise return a single selected object. Defaults to False. |
False
|
literal
|
bool
|
When True and supported by the options, use Literal[...] for the selection field instead of indices. Defaults to True. |
True
|
include_reason
|
bool
|
Reserved flag to include a textual reason field in the intermediate structured output (not exposed in the final result). Defaults to False. |
False
|
confidence
|
bool
|
When True, enable log-probability based confidence scoring. Defaults to False. |
False
|
model
|
ModelParam
|
The model to use for selection. Defaults to "openai:gpt-4o-mini". |
'openai:gpt-4o-mini'
|
model_settings
|
PydanticAIModelSettings | None
|
Model settings to pass to the operation (e.g., temperature). Defaults to None. |
None
|
instructions
|
PydanticAIInstructions | None
|
Additional instructions/hints for the model. Defaults to None. |
None
|
tools
|
ToolType | List[ToolType] | None
|
List of tools available to the model. Defaults to None. |
None
|
deps
|
Deps | None
|
Optional dependencies (e.g., |
None
|
usage_limits
|
PydanticAIUsageLimits | None
|
Usage limits (token/request) configuration. Defaults to None. |
None
|
stream
|
bool
|
When True, return a stream wrapper that exposes the underlying model stream and remaps the final result to the selected object(s). Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Result[Output] | _SelectionStreamWrapper
|
Result[Output] | _SelectionStreamWrapper: A |
Overview
The select() semantic operation is used to select one more options from a given list or type representing a set of options that a model can choose from.
from zyx import select
result = select(
target=["red", "green", "blue"], # (1)!
context="What is the color of the sky?",
)
print(result.output)
"""
"blue"
"""
- The
targetparameter when using select, can be a list of any compatible types (str, int, BaseModel, etc.), or a Literal[...], Enum, or Union[..., ...] type.
Multi-Label Selection
When running this operation, you can choose between setting the multi_label parameter to True or False, which allows for single or multiple selection respectively.
from zyx import select
result = select(
target=["red", "black", "blue", "yellow", "purple"],
context="What colors make green?",
multi_label=True,
)
print(result.output)
"""
["blue", "yellow"]
"""
Reasoning
Optionally, you can set the include_reason parameter to True, to allow the model to provide a textual reason for it's selection.