Repository navigation
1.2.0
You can now ask the same questions about many states in one call. laya-serve 0.3.22 answers them in shared forward passes instead of one request per state. Results also tell you when laya cut a state off, so you know when to raise maxLen.
$results = $laya->predictMany($tickets->pluck('body', 'id')->all(), $questions);
$results[42]->choice('department');
$triages = $laya->decideMany($tickets->pluck('body', 'id')->all(), Triage::class, maxLen: 4096);New
-
predictMany()anddecideMany()(experimental). They ask one set of questions about many states. Results keep the keys you pass in, so$results[42]belongs to ticket 42. Cached states aren't sent again, and the rest go out in requests of at most 64 states. They share the cache withpredict(), so a state you already predicted on its own costs nothing in a batch. -
maxLenandheadMaxLenon batches. They work the same as onpredict()and apply to every state in the batch. -
$result->truncated. It'struewhen laya cut the state off at its token budget. Check it and retry with a highermaxLen:$result = $laya->predict($contract, $questions); if ($result->truncated) { $result = $laya->predict($contract, $questions, maxLen: 4096); }
-
Laya::fake()supports batches. Each state in a batch is recorded as its own prediction, soassertPredicted(),assertDecided()andassertPredictedCount()work the same whether your code batches or not. -
New example.
examples/06-contract-fields.phpasks which contract fields a clause is relevant to.
Good to know
- One state that laya-serve rejects fails the whole batch with an exception, the same way
predict()throws. predictMany()anddecideMany()are experimental, so their signatures may change in a minor release.
Upgrading
No breaking changes. Existing calls send the same requests as in 1.1.1 and hit the same cache entries.
Each feature needs a minimum laya-serve version:
| Feature | laya-serve |
|---|---|
predictMany(), decideMany(), $result->truncated |
0.3.22 |
maxLen / headMaxLen on batches |
0.3.23 |
A server older than 0.3.22 answers a batch with a ServerException that names the version it needs, and always reports truncated as false. A 0.3.22 server ignores batch budgets without an error.
compose.yaml now builds laya v0.3.23 (d8a2e59) for local development and the integration tests.