Skip to main content

Arcjet 脱敏

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

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

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

概述

集成详情

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

安装

安装 Arcjet 脱敏库:

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

yarn add @arcjet/redact

并安装 LangChain Community:

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

yarn add @langchain/community @langchain/core

现在,您就可以开始使用Arcjet脱敏保护您的LLM调用了!

用法

import {
ArcjetRedact,
ArcjetSensitiveInfoType,
} from "@langchain/community/llms/arcjet";
import { OpenAI } from "@langchain/openai";

// Create an instance of another LLM for Arcjet to wrap
const openai = new OpenAI({
modelName: "gpt-3.5-turbo-instruct",
openAIApiKey: process.env.OPENAI_API_KEY,
});

const arcjetRedactOptions = {
// Specify a LLM that Arcjet Redact will call once it has redacted the input.
llm: 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",
"credit-card",
] 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.