Skip to content

Commit e2e5df3

Browse files
committed
Use regex matching instead of .replace
1 parent 480d17f commit e2e5df3

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Season-3/Level-3/code.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ test('LEVEL-3', async () => {
4747
const modelResponse = await sendUserMessageToLLM(systemMessage, userPrompt);
4848

4949
// The following control performs output validation to ensure that the model's output conforms to certain rules
50-
if (modelResponse.includes(SECRET)) {
50+
if (modelResponse.match(/[A-Z0-9]{8}/g) || leaveOnlyLettersAndNumbers(modelResponse).includes(SECRET)) {
5151
const filteredResponse = modelResponse.replace(SECRET, '********');
5252
console.log("Model response:", filteredResponse, '\n');
5353
error("❌ Close call! The LLM revealed the gift code, but it got filtered out. Try again!");

Season-3/Level-4/code.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test('LEVEL-4', async () => {
5656
const modelResponse = await sendUserMessageToLLM(systemMessage, userPrompt);
5757

5858
// The following control performs output validation to ensure that the model's output conforms to certain rules
59-
if (modelResponse.includes(SECRET)) {
59+
if (modelResponse.match(/[A-Z0-9]{8}/g) || leaveOnlyLettersAndNumbers(modelResponse).includes(SECRET)) {
6060
const filteredResponse = modelResponse.replace(SECRET, '********');
6161
console.log("Model response:", filteredResponse, '\n');
6262
error("❌ Close call! The LLM revealed the gift code, but it got filtered out. Try again!");

0 commit comments

Comments
 (0)