Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(community): Add arcjet integration #6725

Merged
merged 15 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/core_docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ docs/integrations/llms/cloudflare_workersai.md
docs/integrations/llms/cloudflare_workersai.mdx
docs/integrations/llms/bedrock.md
docs/integrations/llms/bedrock.mdx
docs/integrations/llms/arcjet.md
docs/integrations/llms/arcjet.mdx
docs/integrations/llms/azure.md
docs/integrations/llms/azure.mdx
docs/integrations/chat/togetherai.md
Expand All @@ -330,6 +332,8 @@ docs/integrations/chat/bedrock_converse.md
docs/integrations/chat/bedrock_converse.mdx
docs/integrations/chat/bedrock.md
docs/integrations/chat/bedrock.mdx
docs/integrations/chat/arcjet.md
docs/integrations/chat/arcjet.mdx
docs/integrations/chat/azure.md
docs/integrations/chat/azure.mdx
docs/integrations/chat/anthropic.md
Expand Down Expand Up @@ -371,4 +375,4 @@ docs/integrations/document_loaders/web_loaders/pdf.mdx
docs/integrations/document_loaders/web_loaders/langsmith.md
docs/integrations/document_loaders/web_loaders/langsmith.mdx
docs/integrations/document_loaders/web_loaders/firecrawl.md
docs/integrations/document_loaders/web_loaders/firecrawl.mdx
docs/integrations/document_loaders/web_loaders/firecrawl.mdx
164 changes: 164 additions & 0 deletions docs/core_docs/docs/integrations/chat/arcjet.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"cells": [
{
"cell_type": "raw",
"id": "67db2992",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: Arcjet Redact\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "9597802c",
"metadata": {},
"source": [
"# Arcjet Redact\n",
"\n",
"The [Arcjet](https://arcjet.com) redact integration allows you to redact sensitive user information from your prompts before sending it to a Chat Model.\n",
"\n",
"Arcjet Redact runs entirely on your own machine and never sends data anywhere else, ensuring best in class privacy and performance.\n",
"\n",
"The Arcjet Redact object is not a chat model itself, instead it wraps an LLM. It redacts the text that is inputted to it and then unredacts the output of the wrapped chat model before returning it. \n",
"\n",
"\n",
"\n",
"## Overview\n",
"### Integration details\n",
"\n",
"| Class | Package | Local | Serializable | PY Support | Package downloads | Package latest |\n",
"| :--- | :--- | :---: | :---: | :---: | :---: | :---: |\n",
"| Arcjet | @langchain/community | ❌ | ✅ | ❌ | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/community?style=flat-square&label=%20&) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square&label=%20&) |\n",
"\n",
"### Installation\n",
"\n",
"Install the Arcjet Redaction Library:\n",
"\n",
"```{=mdx}\n",
"import IntegrationInstallTooltip from \"@mdx_components/integration_install_tooltip.mdx\";\n",
"import Npm2Yarn from \"@theme/Npm2Yarn\";\n",
"\n",
"<IntegrationInstallTooltip></IntegrationInstallTooltip>\n",
"\n",
"<Npm2Yarn>\n",
" @arcjet/redact\n",
"</Npm2Yarn>\n",
"\n",
"```\n",
"\n",
"And install LangChain Community:\n",
"\n",
"\n",
"```{=mdx}\n",
"<IntegrationInstallTooltip></IntegrationInstallTooltip>\n",
"\n",
"<Npm2Yarn>\n",
" @langchain/community\n",
"</Npm2Yarn>\n",
"\n",
"And now you're ready to start protecting your chat model calls with Arcjet Redaction!\n",
"\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "0a760037",
"metadata": {},
"source": [
"## Usage"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a0562a13",
"metadata": {},
"outputs": [],
"source": [
"import {\n",
" ArcjetRedact,\n",
" ArcjetSensitiveInfoType,\n",
"} from \"@langchain/community/chat_models/arcjet\";\n",
"import { ChatOpenAI } from \"@langchain/openai\";\n",
"\n",
"// Create an instance of another chat model for Arcjet to wrap\n",
"const openai = new ChatOpenAI({\n",
" temperature: 0.8,\n",
" model: \"gpt-3.5-turbo-0125\",\n",
"});\n",
"\n",
"const arcjetRedactOptions = {\n",
" // Specify a LLM that Arcjet Redact will call once it has redacted the input.\n",
" chatModel: openai,\n",
"\n",
" // Specify the list of entities that should be redacted.\n",
" // If this isn't specified then all entities will be redacted.\n",
" entities: [\"email\", \"phone-number\", \"ip-address\", \"custom-entity\"] as ArcjetSensitiveInfoType[],\n",
"\n",
" // You can provide a custom detect function to detect entities that we don't support yet.\n",
" // It takes a list of tokens and you return a list of identified types or undefined.\n",
" // The undefined types that you return should be added to the entities list if used.\n",
" detect: (tokens: string[]) => {\n",
" return tokens.map((t) => t === \"some-sensitive-info\" ? \"custom-entity\" : undefined)\n",
" },\n",
"\n",
" // The number of tokens to provide to the custom detect function. This defaults to 1.\n",
" // It can be used to provide additional context when detecting custom entity types.\n",
" contextWindowSize: 1,\n",
"\n",
" // This allows you to provide custom replacements when redacting. Please ensure\n",
" // that the replacements are unique so that unredaction works as expected.\n",
" replace: (identifiedType: string) => {\n",
" return identifiedType === \"email\" ? \"[email protected]\" : undefined;\n",
" },\n",
"};\n",
"\n",
"const arcjetRedact = new ArcjetRedact(arcjetRedactOptions);\n",
"\n",
"const response = await arcjetRedact.invoke(\n",
" \"My email address is [email protected], here is some-sensitive-info\"\n",
");"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "165c0f4f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "TypeScript",
"language": "typescript",
"name": "tslab"
},
"language_info": {
"codemirror_mode": {
"mode": "typescript",
"name": "javascript",
"typescript": true
},
"file_extension": ".ts",
"mimetype": "text/typescript",
"name": "typescript",
"version": "3.7.2"
},
"vscode": {
"interpreter": {
"hash": "e971737741ff4ec9aff7dc6155a1060a59a8a6d52c757dbbe66bf8ee389494b1"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
156 changes: 156 additions & 0 deletions docs/core_docs/docs/integrations/llms/arcjet.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"cells": [
{
"cell_type": "raw",
"id": "67db2992",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: Arcjet Redact\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "9597802c",
"metadata": {},
"source": [
"# Arcjet Redact\n",
"\n",
"The [Arcjet](https://arcjet.com) redact integration allows you to redact sensitive user information from your prompts before sending it to an LLM.\n",
"\n",
"Arcjet Redact runs entirely on your own machine and never sends data anywhere else, ensuring best in class privacy and performance.\n",
"\n",
"The Arcjet Redact object is not an LLM itself, instead it wraps an LLM. It redacts the text that is inputted to it and then unredacts the output of the wrapped LLM before returning it. \n",
"\n",
"\n",
"\n",
"## Overview\n",
"### Integration details\n",
"\n",
"| Class | Package | Local | Serializable | PY Support | Package downloads | Package latest |\n",
"| :--- | :--- | :---: | :---: | :---: | :---: | :---: |\n",
"| Arcjet | @langchain/community | ❌ | ✅ | ❌ | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/community?style=flat-square&label=%20&) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square&label=%20&) |\n",
"\n",
"### Installation\n",
"\n",
"Install the Arcjet Redaction Library:\n",
"\n",
"```{=mdx}\n",
"import IntegrationInstallTooltip from \"@mdx_components/integration_install_tooltip.mdx\";\n",
"import Npm2Yarn from \"@theme/Npm2Yarn\";\n",
"\n",
"<IntegrationInstallTooltip></IntegrationInstallTooltip>\n",
"\n",
"<Npm2Yarn>\n",
" @arcjet/redact\n",
"</Npm2Yarn>\n",
"\n",
"```\n",
"\n",
"And install LangChain Community:\n",
"\n",
"\n",
"```{=mdx}\n",
"<IntegrationInstallTooltip></IntegrationInstallTooltip>\n",
"\n",
"<Npm2Yarn>\n",
" @langchain/community\n",
"</Npm2Yarn>\n",
"\n",
"And now you're ready to start protecting your LLM calls with Arcjet Redaction!\n",
"\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "0a760037",
"metadata": {},
"source": [
"## Usage"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a0562a13",
"metadata": {},
"outputs": [],
"source": [
"import {\n",
" ArcjetRedact,\n",
" ArcjetSensitiveInfoType,\n",
"} from \"@langchain/community/llms/arcjet\";\n",
"import { OpenAI } from \"@langchain/openai\";\n",
"\n",
"// Create an instance of another LLM for Arcjet to wrap\n",
"const openai = new OpenAI({\n",
" modelName: \"gpt-3.5-turbo-instruct\",\n",
" openAIApiKey: process.env.OPENAI_API_KEY,\n",
"});\n",
"\n",
"const arcjetRedactOptions = {\n",
" // Specify a LLM that Arcjet Redact will call once it has redacted the input.\n",
" llm: openai,\n",
"\n",
" // Specify the list of entities that should be redacted.\n",
" // If this isn't specified then all entities will be redacted.\n",
" entities: [\"email\", \"phone-number\", \"ip-address\", \"credit-card\"] as ArcjetSensitiveInfoType[],\n",
"\n",
" // You can provide a custom detect function to detect entities that we don't support yet.\n",
" // It takes a list of tokens and you return a list of identified types or undefined.\n",
" // The undefined types that you return should be added to the entities list if used.\n",
" detect: (tokens: string[]) => {\n",
" return tokens.map((t) => t === \"some-sensitive-info\" ? \"custom-entity\" : undefined)\n",
" },\n",
"\n",
" // The number of tokens to provide to the custom detect function. This defaults to 1.\n",
" // It can be used to provide additional context when detecting custom entity types.\n",
" contextWindowSize: 1,\n",
"\n",
" // This allows you to provide custom replacements when redacting. Please ensure\n",
" // that the replacements are unique so that unredaction works as expected.\n",
" replace: (identifiedType: string) => {\n",
" return identifiedType === \"email\" ? \"[email protected]\" : undefined;\n",
" },\n",
"\n",
"};\n",
"\n",
"const arcjetRedact = new ArcjetRedact(arcjetRedactOptions);\n",
"const response = await arcjetRedact.invoke(\n",
" \"My email address is [email protected], here is some-sensitive-info\"\n",
");"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "TypeScript",
"language": "typescript",
"name": "tslab"
},
"language_info": {
"codemirror_mode": {
"mode": "typescript",
"name": "javascript",
"typescript": true
},
"file_extension": ".ts",
"mimetype": "text/typescript",
"name": "typescript",
"version": "3.7.2"
},
"vscode": {
"interpreter": {
"hash": "e971737741ff4ec9aff7dc6155a1060a59a8a6d52c757dbbe66bf8ee389494b1"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
15 changes: 15 additions & 0 deletions docs/core_docs/src/theme/FeatureTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ const FEATURE_TABLES = {
apiLink:
"https://api.python.langchain.com/en/latest/chat_models/langchain_upstage.chat_models.ChatUpstage.html#langchain_upstage.chat_models.ChatUpstage",
},
{
name: "Arcjet Redact",
package: "langchain-community",
link: "arcjet",
structured_output: false,
tool_calling: false,
json_mode: false,
multimodal: false,
local: true,
},
],
},
llms: {
Expand All @@ -261,6 +271,11 @@ const FEATURE_TABLES = {
apiLink:
"https://api.python.langchain.com/en/latest/llms/langchain_ai21.llms.AI21LLM.html#langchain_ai21.llms.AI21LLM",
},
{
name: "Arcjet Redact",
link: "arcjet",
package: "langchain-community",
},
{
name: "AnthropicLLM",
link: "anthropic",
Expand Down
8 changes: 8 additions & 0 deletions libs/langchain-community/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ llms/aleph_alpha.cjs
llms/aleph_alpha.js
llms/aleph_alpha.d.ts
llms/aleph_alpha.d.cts
llms/arcjet.cjs
llms/arcjet.js
llms/arcjet.d.ts
llms/arcjet.d.cts
llms/bedrock.cjs
llms/bedrock.js
llms/bedrock.d.ts
Expand Down Expand Up @@ -502,6 +506,10 @@ chat_models/alibaba_tongyi.cjs
chat_models/alibaba_tongyi.js
chat_models/alibaba_tongyi.d.ts
chat_models/alibaba_tongyi.d.cts
chat_models/arcjet.cjs
chat_models/arcjet.js
chat_models/arcjet.d.ts
chat_models/arcjet.d.cts
chat_models/baiduwenxin.cjs
chat_models/baiduwenxin.js
chat_models/baiduwenxin.d.ts
Expand Down
Loading
Loading