1. Go to this page and download the library: Download thejenos/smart-pii-redactor 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/ */
thejenos / smart-pii-redactor example snippets
'providers' => [
'openai' => [
'driver' => 'openai',
'key' => env('OPENAI_API_KEY'),
],
'redactor' => [
'driver' => 'redactor_wrapper_driver',
// The provider (from this file) that receives the redacted requests.
'base_driver' => 'openai',
// 'mask' swaps PII for reversible placeholders like [PERSON_0].
// 'redact' replaces it with *** for good (nothing is restored).
'method' => 'mask',
// Limit detection to some entities, or skip some. Use one or the other.
'only' => [],
'except' => [],
// Log the raw HTTP traffic with the base provider (see below).
'log' => env('PII_REDACTOR_LOG', false),
'log_channel' => null,
],
],
use TheJenos\SmartPiiRedactor\SmartPiiRedactorEntites;
'except' => [SmartPiiRedactorEntites::LOCATION, 'ORGANIZATION'],
use Laravel\Ai\Attributes\Provider;
#[Provider('redactor')]
class SupportAgent implements Agent
{
use Promptable;
// ...
}
$response = (new SupportAgent)->prompt(
'Summarise the ticket from Dana Whitcombe ([email protected]).',
provider: 'redactor',
);
$response->text; // Contains "Dana Whitcombe", never a placeholder.
return (new SupportAgent)->stream($prompt, provider: 'redactor');
'default' => 'redactor',
use Illuminate\Support\Str;
use TheJenos\SmartPiiRedactor\SmartPiiRedactor;
use TheJenos\SmartPiiRedactor\SmartPiiRedactorEntites;
$redactor = app(SmartPiiRedactor::class);
// Detect entities: [['text' => 'Dana Whitcombe', 'tag' => 'PERSON'], ...]
$entities = $redactor->getEntities($text);
// Or restrict detection.
$entities = $redactor->getEntities($text, onlyEntities: [SmartPiiRedactorEntites::EMAIL]);
$entities = $redactor->getEntities($text, exceptEntities: ['LOCATION']);
// Irreversible: replace every entity with ***.
$redacted = $redactor->redact($text, $entities);
// Reversible: replace entities with [TAG_N] placeholders.
$key = Str::random(10);
$masked = $redactor->mask($text, $entities, $key);
// ...send $masked somewhere, get $reply back...
$restored = SmartPiiRedactor::reapplyMaskedText($reply, $key);
// The placeholder => value map, if you need it.
$map = SmartPiiRedactor::getCacheReplacement($key);
ini
ffi.enable = true
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.