Skip to main content

Arcjet 脱敏

Arcjet 脱敏集成允许您在将提示发送给聊天模型之前,从中脱敏敏感的用户信息。

Arcjet 脱敏完全在您自己的机器上运行,绝不会将数据发送到其他任何地方,确保了顶级的隐私性和性能。

Arcjet 脱敏对象本身不是一个聊天模型,而是封装了一个 LLM。它会对输入的文本进行脱敏,然后在返回之前对封装的聊天模型的输出进行去脱敏。

概览

集成详情

本地可序列化Python 支持包下载量最新包
Arcjet@langchain/communityNPM - 下载量NPM - 版本

安装

安装 Arcjet 脱敏库:

:::提示 请参阅安装集成包的一般说明部分。 :::

yarn add @arcjet/redact

然后安装 LangChain 社区库:

:::提示 请参阅安装集成包的一般说明部分。 :::

yarn add @langchain/community @langchain/core

现在您就可以开始使用 Arcjet 脱敏保护您的聊天模型调用了!

用法

import {
ArcjetRedact,
ArcjetSensitiveInfoType,
} from "@langchain/community/chat_models/arcjet";
import { ChatOpenAI } from "@langchain/openai";

// Create an instance of another chat model for Arcjet to wrap
const openai = new ChatOpenAI({
temperature: 0.8,
model: "gpt-3.5-turbo-0125",
});

const arcjetRedactOptions = {
// Specify a LLM that Arcjet Redact will call once it has redacted the input.
chatModel: openai,

// Specify the list of entities that should be redacted.
// If this isn't specified then all entities will be redacted.
entities: [
"email",
"phone-number",
"ip-address",
"custom-entity",
] as ArcjetSensitiveInfoType[],

// You can provide a custom detect function to detect entities that we don't support yet.
// It takes a list of tokens and you return a list of identified types or undefined.
// The undefined types that you return should be added to the entities list if used.
detect: (tokens: string[]) => {
return tokens.map((t) =>
t === "some-sensitive-info" ? "custom-entity" : undefined
);
},

// The number of tokens to provide to the custom detect function. This defaults to 1.
// It can be used to provide additional context when detecting custom entity types.
contextWindowSize: 1,

// This allows you to provide custom replacements when redacting. Please ensure
// that the replacements are unique so that unredaction works as expected.
replace: (identifiedType: string) => {
return identifiedType === "email" ? "[email protected]" : undefined;
},
};

const arcjetRedact = new ArcjetRedact(arcjetRedactOptions);

const response = await arcjetRedact.invoke(
"My email address is [email protected], here is some-sensitive-info"
);

Was this page helpful?


You can also leave detailed feedback on GitHub.