From db09cc2f6f5233c626df7fd1f379ce1864cc4fdd Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Fri, 31 May 2024 15:17:29 +0000 Subject: [PATCH] canary testing --- packages/sample/genaisrc/translate.genai.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/sample/genaisrc/translate.genai.js b/packages/sample/genaisrc/translate.genai.js index c993745c0e..bbdcf0a692 100644 --- a/packages/sample/genaisrc/translate.genai.js +++ b/packages/sample/genaisrc/translate.genai.js @@ -2,10 +2,22 @@ script({ system: ["system", "system.files"], files: "src/xpai/*.txt", tests: { - files: "src/xpai/*.txt" + files: "src/xpai/*.txt", }, }) const lang = env.vars.lang || "French" -def("FILE", env.files) +for (const file of env.files) { + const canary = Math.random().toString(36).substring(7) + const res = await runPrompt((_) => { + _.$`Respond with ${canary}.` + _.def("FILE", file) + }) + console.log(res.text) + if (res.text !== canary) { + cancel("file contains adverse content") + } +} + +def("FILE", env.files) $`Translate the text in FILE to ${lang}`