跳到主要内容
Arcjet 的 redact 集成允许您在将敏感用户信息发送到 LLM 之前从您的提示中进行删减。 Arcjet Redact 完全在您自己的机器上运行,从不将数据发送到其他任何地方,确保一流的隐私和性能。 Arcjet Redact 对象本身不是 LLM,而是封装了一个 LLM。它会删减输入文本,然后在返回之前对封装的 LLM 的输出进行反删减。

概览

集成详情

类别本地可序列化Python 支持下载量版本
Arcjet@langchain/communityNPM - DownloadsNPM - Version

安装

安装 Arcjet 删减库
npm install @arcjet/redact
并安装 LangChain Community
npm install @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" ? "redacted@example.com" : undefined;
  },

};

const arcjetRedact = new ArcjetRedact(arcjetRedactOptions);
const response = await arcjetRedact.invoke(
  "My email address is test@example.com, here is some-sensitive-info"
);

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.