隐私过滤器:使用 Laravel 检测文本中的个人身份信息

发布日期 经过

隐私过滤器:检测 Laravel 图片文本中的个人身份信息

Privacy Filter is a Laravel package that detects private entities — names, emails, and other personally identifiable information — in arbitrary text. It wraps the privacy-filter.cpp command-line binary, a GGML inference engine for OpenAI's privacy-filter token-classification models, and exposes the results through a PHP API.

Classifying Text into Entities

The main entry point is the entities() method, which runs the model over a string and returns Entity instances. Each entity carries its type, the matched text, the start and end byte offsets, and a confidence score:

使用 DirectoryTree\PrivacyFilter\Facades\PrivacyFilter ;
$entities = PrivacyFilter :: entities 'Contact John Doe at jdoe@example.com.' (英文):
foreach ($entities 作为 $entity) {
回声 实体 -> type; // private_email
回声 实体 -> 文本; // jdoe@example.com
}

Because the offsets are exact UTF-8 byte positions, you can map each detected entity back to its location in the original text rather than relying on string matching alone.

Confidence Thresholds

Classifications default to a 0.5 confidence threshold. You can raise or lower it per call to trade recall for precision — a higher threshold returns fewer, more certain entities:

$entities = PrivacyFilter :: entities
文本 : 'Contact John Doe at jdoe@example.com.' ,
临界点 : 0.75 ,
(英文):

Redacting Detected Text

The package detects entities; what you do with them is up to you. A redaction pass is a reduce over the returned entities:

已编辑 = 收集 ($entities) -> 减少 功能 细绳 $text, $entity) {
返回 str_replace ($entity -> text, '[redacted]' , $text);
}, $text);

Faking Classifications in Tests

Running the binary and loading the model in a test suite is slow, so Privacy Filter ships a fake() method that returns predetermined entities without invoking the binary:

使用 DirectoryTree\PrivacyFilter\Entity ;
使用 DirectoryTree\PrivacyFilter\Facades\PrivacyFilter ;
PrivacyFilter :: 伪造的 ([
新的 Entity 类型 : 'private_email' , 开始 : 20 , 结尾 : 36 , 分数 : 0.98 ),
]);

Your code under test then receives those entities as if the model had produced them.

安装和设置

Install the package with Composer, then run the installer to fetch the compiled binary for your operating system and download the required GGUF model:

作曲家 要求 directorytree/privacy-filter
php 工匠 privacy-filter:install

Prebuilt binaries for Linux, macOS (including ARM64), and Windows are distributed through PrivacyFilterBinaries . Pass --force to overwrite existing files. To customize the binary path, model path, process timeout, model URL, or release source, publish the configuration file:

php 工匠 供应商:发布 --tag=privacy-filter-config

Every classification loads the model into memory, so the package recommends running classifications on dedicated queue workers in production to keep memory usage predictable.

You can find the source and documentation on GitHub

保罗·雷德蒙德照片

Laravel News 特约撰稿人。全栈 Web 开发人员兼作家。

归档于:
立方体

Laravel 时事通讯

加入超过 4 万名开发者的行列,不错过任何新的技巧、教程等内容。

图像
廷克威尔

这款编辑器专为快速反馈和快速迭代而设计,让您尽享编码和调试的乐趣。它就像您应用程序的一个外壳——但具备多行编辑、代码自动完成等更多功能。

参观廷克韦尔
Lucky Media 标志

幸运传媒

Get Lucky Now——拥有十余年经验的 Laravel 开发理想之选!

幸运传媒
Shift 标志

转移

还在运行旧版本的 Laravel?立即实现 Laravel 自动升级和代码现代化,让您的应用程序保持最新状态。

转移
SaaSykit:Laravel SaaS 入门套件徽标

SaaSykit:Laravel SaaS 入门套件

SaaSykit 是一个多租户 Laravel SaaS 入门套件,包含运行现代 SaaS 所需的所有功能,例如支付、美观的结账界面、管理面板、用户仪表盘、身份验证、现成组件、统计数据、博客、文档等等。

SaaSykit:Laravel SaaS 入门套件
Kirschbaum 标志

樱桃树

提供创新和稳定性,确保您的Web应用程序取得成功。

樱桃树
Laravel Cloud 标志

Laravel 云

轻松创建和管理服务器,并在几秒钟内部署 Laravel 应用程序。

Laravel 云
PhpStorm 标志

PhpStorm

首选的 PHP IDE,对 Laravel 及其生态系统提供广泛的开箱即用支持。

PhpStorm
Tinkerwell 徽标

廷克威尔

Laravel 开发者必备的代码运行器。可在本地和生产环境中体验 AI、自动补全和即时反馈功能。

廷克威尔
了解 Softtech 的标志

了解软科技

Acquaint Softtech 提供 AI 就绪的 Laravel 开发人员,48 小时内即可上手,每月费用为 3000 美元,没有冗长的销售流程,并提供 100% 退款保证。

了解软科技
绝不妥协标志

绝不妥协

来自 No Compromises 播客的两位经验丰富的开发者 Joel 和 Aaron 现在可以为您的 Laravel 项目提供服务。⬧ 固定费用 9500 美元/月。⬧ 无冗长的销售流程。⬧ 无需签订合同。⬧ 100% 退款保证。

绝不妥协
鱼叉:新一代时间跟踪和发票标志

Harpoon:新一代时间跟踪和发票系统

新一代时间跟踪和计费软件,帮助您的机构规划和预测盈利的未来。

Harpoon:新一代时间跟踪和发票系统
Yammi Audit Log: Track Who Really Made a Change Across Jobs and Queues image

Yammi Audit Log: Track Who Really Made a Change Across Jobs and Queues

阅读文章
Route Metadata Support in Laravel 13.17 image

Route Metadata Support in Laravel 13.17

阅读文章
Ship AI with Laravel: Failover, Queues, and Middleware for AI Agents image

Ship AI with Laravel: Failover, Queues, and Middleware for AI Agents

阅读文章
Monitor and Control Schedules, Queues, and Errors in Laravel with Watchtower image

Monitor and Control Schedules, Queues, and Errors in Laravel with Watchtower

阅读文章
在 LinkedIn 图片上展示您的 PhpStorm 专业技能

在 LinkedIn 上展示您的 PhpStorm 专业技能

阅读文章
NationForge:面向公民组织的自托管管理面板

NationForge:面向公民组织的自托管管理面板

阅读文章