Arcjet 红除
该 Arcjet 红除集成允许您在将提示发送到聊天模型之前从提示中删除敏感用户数据。
Arcjet Redact 完全在您的机器上运行,绝不会将数据发送到任何其他地方,确保一流的隐私和性能。
Arcjet Redact 对象本身不是聊天模型,而是包装了一个 LLM。它会删除输入到它的文本,然后在返回之前删除包装的聊天模型的输出。
概述
集成详细信息
类 | 包 | 本地 | 可序列化 | PY 支持 | 包下载 | 包最新版本 |
---|---|---|---|---|---|---|
Arcjet | @langchain/community | ❌ | ✅ | ❌ |
安装
安装 Arcjet Redaction 库
提示
有关安装集成包的一般说明,请参阅 本节。
- npm
- yarn
- pnpm
npm i @arcjet/redact
yarn add @arcjet/redact
pnpm add @arcjet/redact
并安装 LangChain Community
提示
有关安装集成包的一般说明,请参阅 本节。
- npm
- yarn
- pnpm
npm i @langchain/community @langchain/core
yarn add @langchain/community @langchain/core
pnpm add @langchain/community @langchain/core
现在,您已经准备好使用 Arcjet Redaction 来保护您的聊天模型调用!
用法
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"
);