1. Go to this page and download the library: Download mrpunyapal/laravel-ai-aegis library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use MrPunyapal\LaravelAiAegis\Contracts\PiiTypeInterface;
final readonly class NhsNumberType implements PiiTypeInterface
{
public function type(): string { return 'nhs_number'; }
public function pattern(): string { return '/\b\d{3}\s\d{3}\s\d{4}\b/'; }
}
use MrPunyapal\LaravelAiAegis\Contracts\GuardRailInterface;
use MrPunyapal\LaravelAiAegis\Data\GuardRailResult;
use MrPunyapal\LaravelAiAegis\Enums\GuardRailStage;
final readonly class ToxicityGuardRail implements GuardRailInterface
{
public function stage(): GuardRailStage { return GuardRailStage::Input; }
public function check(string $content, mixed $context): GuardRailResult
{
if ($this->isToxic($content)) {
return GuardRailResult::fail(reason: 'Toxic content detected.', stage: 'input');
}
return GuardRailResult::pass();
}
}
$this->app->extend(GuardRailOrchestratorInterface::class, function ($orchestrator) {
$orchestrator->register(new ToxicityGuardRail);
return $orchestrator;
});
use MrPunyapal\LaravelAiAegis\Contracts\ApprovalHandlerInterface;
final class SlackApprovalHandler implements ApprovalHandlerInterface
{
public function approve(string $content, mixed $context): bool
{
// Send Slack notification and wait for response...
return $this->waitForSlackApproval($content);
}
}