Skip to content

1.1.0

Choose a tag to compare

@marcreichel marcreichel released this 27 Sep 19:07
· 101 commits to main since this release
35ecc6c

Until now, decide() gave you a typed object and dropped the confidence behind it. So the moment you wanted to send unsure tickets to a human, you had to fall back to predict(). 1.1.0 moves that check into the decision class, and adds caching and a health check for production.

final readonly class Triage
{
    public function __construct(
        #[Ask('Which department should handle this?', minConfidence: 0.7)]
        public ?Department $department, // null when laya isn't sure

        #[Ask('Does the user threaten to cancel?', yes: 'says they will cancel or switch', threshold: 0.3)]
        public bool $churn,
    ) {}
}

New

  • minConfidence on #[Ask]. A nullable parameter is null when the calibrated answerConfidence is below the threshold. If the parameter isn't nullable, decide() throws before it sends a request.
  • yes, no and threshold for bools. yes and no describe what each answer means, the same as Question::yesNo(). threshold sets the P(yes) at which the value becomes true, instead of the fixed 0.5. Setting any of them on a parameter that isn't a bool throws, so a typo can't be silently ignored.
  • Fake a decision object. Laya::fake(new Triage(...)) takes its answers from the object's public properties, so tests build the same type your code gets back, and there are no string keys to go stale when you rename a field.
  • Unsure fake answers. Register null and the fake answers with even probabilities and zero confidence. That lets you test the minConfidence path without a server.
  • assertDecided(Triage::class). It passes when a recorded request asked exactly that class's questions. An optional callback gets the state and the model.
  • PSR-16 caching. Pass cache: and cacheTtl: to the constructor. The key is a hash of the state, the questions and the pinned model. Laya gives the same answer to the same input, so repeat requests never reach the server. The key doesn't include the checkpoint revision, so clear the cache or set a TTL when you upgrade laya-serve.
  • Laravel caching. Set LAYA_CACHE_STORE (e.g. redis) and optionally LAYA_CACHE_TTL in seconds. Caching stays off by default.
  • php artisan laya:health. It prints the server's status, device and loaded checkpoints, and exits with 1 when laya-serve is unhealthy or unreachable. Put it in your deploy checks.

Upgrading

No breaking changes. The one new dependency is psr/simple-cache ^3.0, which only contains interfaces. A published config/laya.php picks up the new cache block from the package defaults, so the env vars work without republishing.