From f7a93211acfb69463b5f9ef7b5afcea278b84f5c Mon Sep 17 00:00:00 2001 From: pelikhan Date: Fri, 13 Dec 2024 16:19:37 -0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20content=20safety=20check=20for=20?= =?UTF-8?q?prompt=20injections=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/sample/genaisrc/safety.genai.mjs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 packages/sample/genaisrc/safety.genai.mjs diff --git a/packages/sample/genaisrc/safety.genai.mjs b/packages/sample/genaisrc/safety.genai.mjs new file mode 100644 index 0000000000..7991e0bd45 --- /dev/null +++ b/packages/sample/genaisrc/safety.genai.mjs @@ -0,0 +1,11 @@ + +const contentSafefy = await host.contentSafety() +if (contentSafefy?.detectPromptInjection) { + const res = await contentSafefy.detectPromptInjection(env.files) + if (res.attackDetected) + throw new Error("Prompt injection detected in the files") +} else { + console.warn("Content safety not available") +} + +$`Say all good!`