Class ValueOptions<I>
java.lang.Object
com.vaadin.flow.component.ai.form.ValueOptions<I>
- Type Parameters:
I- the per-label item type the converter must produce ? the field's value type for single-value fields, the per-element type for multi-select fields
Per-field registration of the labels the LLM may pick from for a given field.
The label set is either fixed (
options(Collection)) or supplied on
demand by a callback (options(BiFunction)); exactly one of the two
must be set, with the last call winning. Pass the configured registration to
controller.fieldValueOptions(...) to apply it; the labels are then presented
to the LLM as the field's choices.
Labels are always String values, regardless of the field's value
type. For a non-String field, supply a label-to-value converter
through fieldValueOptions(config, toValue) ? the converter resolves a chosen label
to the field's value type before the controller writes it.
- Author:
- Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V> ValueOptions<V> Starts an options registration for a single-value field.static <T,C extends Component>
ValueOptions<T> forField(MultiSelect<C, T> field) Starts an options registration for a multi-select field.options(Collection<String> options) Sets a fixed label list.Sets a callback the controller invokes whenever the LLM needs to see the field's options.
-
Method Details
-
forField
Starts an options registration for a single-value field. The field's value typeVflows through; for anyVother thanString, the controller's two-argumentFormAIController.fieldValueOptions(ValueOptions, Function)overload must be used to supply a label-to-value converter (a compile-time requirement, not a runtime check).- Type Parameters:
V- the field's value type- Parameters:
field- the single-value field whose options the LLM may pick from, notnull- Returns:
- a fresh registration ready to receive
options(Collection)oroptions(BiFunction)
-
forField
Starts an options registration for a multi-select field. Picked by the compiler overforField(HasValue)whenever the reference is statically typed asMultiSelect. The per-element typeTflows through; for anyTother thanString, the controller's two-argumentFormAIController.fieldValueOptions(ValueOptions, Function)overload must be used. The controller aggregates resolved per-label items into aLinkedHashSetbeforeHasValue.setValue(V).- Type Parameters:
T- the per-element typeC- the field's source-component type- Parameters:
field- the multi-select field whose options the LLM may pick from, notnull- Returns:
- a fresh registration ready to receive
options(Collection)oroptions(BiFunction)
-
options
Sets a fixed label list. A defensive copy is taken so later mutations of the caller's collection have no effect. Use this when the option set is known up front and small enough to enumerate; for large or dynamic sets useoptions(BiFunction)instead. Mutually exclusive withoptions(BiFunction)? calling either clears the other.- Parameters:
options- the labels the LLM may pick from, notnulland not empty- Returns:
- this registration, for chaining
- Throws:
IllegalArgumentException- ifoptionsis empty ? registering an empty fixed list leaves the field un-fillable and is always a developer mistake
-
options
Sets a callback the controller invokes whenever the LLM needs to see the field's options. Use this when the option set is too large or too dynamic for a fixed list viaoptions(Collection)? for example options that come from a database query or a remote service. The callback returns the labels the LLM may pick from; labels are alwaysStringvalues, regardless of the field's value type. Mutually exclusive withoptions(Collection)? calling either clears the other.- Parameters:
query- invoked with two arguments: a filter string the LLM picked, and a positive limit on how many labels to return. Returns the matching labels in display order, notnull(an empty list signals "no matches" to the LLM)- Returns:
- this registration, for chaining
-