Repository navigation
1.0.0
Classify text in PHP without paying for an LLM API. laya-php is a typed SDK for Laya, a self-hosted model that answers classification questions about text in 100+ languages, and gives you calibrated confidence with every answer.
1.0.0 is the first stable release. From here on the public API follows semver.
$triage = $laya->decide($ticket, Triage::class);
$triage->department; // Department::Billing
$triage->churn; // trueWhat's in 1.0
- Three question types.
Question::choice(),Question::score()andQuestion::yesNo()return typed answers with probabilities and a calibratedanswerConfidence, which is comparable across question types. - Decisions into objects.
$laya->decide($text, Triage::class)reads#[Ask],#[Describe]and#[Levels]attributes from a class and returns a hydrated instance. Backed enums map to choices, bools to yes/no and#[Levels]ints to scores. - Any PSR-18 client. Guzzle, Symfony HttpClient and others are auto-discovered, or you can pass your own client, for example one with retries.
- Laravel integration (new since 0.0.1). For Laravel 13+, the service provider is auto-discovered and reads
LAYA_URLandLAYA_API_KEY. Publish the config withphp artisan vendor:publish --tag=laya-config. - Testing without a server.
Laya::fake([...])answers from values you register, and offersassertPredicted(),assertPredictedCount()andassertNothingPredicted(). In Laravel it also replaces the container binding, so injected code and queued jobs get the fake. - Typed exceptions. They cover authentication, validation, a busy server, a failed transport and other server errors, and all implement
LayaException. - Checkpoint pinning. Pass
model: Model::English,Model::MultilingualorModel::TypedDecisions. Otherwise Laya's router picks a checkpoint by language. - Jev-compatible. laya-serve speaks the same
/v1/systemonewire protocol, which makes this a self-hosted alternative to Jev AI. It hasn't been tested against the hosted Jev API.
Quality
- 100% line coverage and a 100% mutation score (Pest), both enforced in CI
- PHPStan at level max
- Tested on PHP 8.4 and 8.5
- Integration-tested against a live laya-serve;
compose.yamlpins upstream Laya to commit4066d5d
Requirements
- PHP 8.4+
- A running laya-serve; the repository's
compose.yamlstarts one - Laravel 13+ (optional)
Upgrading from 0.0.1
No breaking changes. Laravel users can drop any manual Laya binding and use the auto-discovered provider.
composer require marcreichel/laya-php:^1.0