final class CollectionChoice

Methods

__construct(Collection $collection, Closure|string|null $by = null, Closure|array|string|null $describe = null)

Create a new choice between the items of the given collection.

mixed
decide(string $question, string|array $text, float|null $threshold = null, Provider|Lab|array|string|null $provider = null, string|null $model = null, int|null $timeout = null)

Choose the item that best answers the question about the given text.

Details

at line 45
__construct(Collection $collection, Closure|string|null $by = null, Closure|array|string|null $describe = null)

Create a new choice between the items of the given collection.

A string-keyed collection of strings without a "by" or "describe" resolver maps option names to descriptions, and its keys are chosen.

Parameters

Collection $collection
Closure|string|null $by

the field or closure that names each item

Closure|array|string|null $describe

the field, fields, or closure that describe each item

Exceptions

InvalidArgumentException

at line 73
mixed decide(string $question, string|array $text, float|null $threshold = null, Provider|Lab|array|string|null $provider = null, string|null $model = null, int|null $timeout = null)

Choose the item that best answers the question about the given text.

Parameters

string $question
string|array $text
float|null $threshold

the minimum probability of the chosen option; below it, null is returned

Provider|Lab|array|string|null $provider
string|null $model
int|null $timeout

Return Value

mixed

Exceptions

InvalidArgumentException