Skip to content

Commit

Permalink
removes some more unhelpful comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarsh-scottlogic committed Feb 19, 2024
1 parent e0c44ff commit 496c30f
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions backend/src/defence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ import {
} from './promptTemplates';

function activateDefence(id: DEFENCE_ID, defences: Defence[]) {
// return the updated list of defences
return defences.map((defence) =>
defence.id === id ? { ...defence, isActive: true } : defence
);
}

function deactivateDefence(id: DEFENCE_ID, defences: Defence[]) {
// return the updated list of defences
return defences.map((defence) =>
defence.id === id ? { ...defence, isActive: false } : defence
);
Expand All @@ -38,7 +36,6 @@ function configureDefence(
defences: Defence[],
config: DefenceConfigItem[]
): Defence[] {
// return the updated list of defences
return defences.map((defence) =>
defence.id === id ? { ...defence, config } : defence
);
Expand Down Expand Up @@ -95,7 +92,6 @@ function getFilterList(defences: Defence[], type: DEFENCE_ID) {
}
function getSystemRole(
defences: Defence[],
// by default, use sandbox
currentLevel: LEVEL_NAMES = LEVEL_NAMES.SANDBOX
) {
switch (currentLevel) {
Expand Down Expand Up @@ -183,14 +179,12 @@ function escapeXml(unsafe: string) {
});
}

// function to detect any XML tags in user input
function containsXMLTags(input: string) {
const tagRegex = /<\/?[a-zA-Z][\w-]*(?:\b[^>]*\/\s*|[^>]*>|[?]>)/g;
const foundTags: string[] = input.match(tagRegex) ?? [];
return foundTags.length > 0;
}

// apply XML tagging defence to input message
function transformXmlTagging(
message: string,
defences: Defence[]
Expand All @@ -213,7 +207,6 @@ function generateRandomString(length: number) {
).join('');
}

// apply random sequence enclosure defence to input message
function transformRandomSequenceEnclosure(
message: string,
defences: Defence[]
Expand Down Expand Up @@ -250,7 +243,6 @@ function combineTransformedMessage(transformedMessage: TransformedChatMessage) {
);
}

//apply defence string transformations to original message
function transformMessage(
message: string,
defences: Defence[]
Expand Down Expand Up @@ -284,7 +276,6 @@ function transformMessage(
};
}

// detects triggered defences in original message and blocks the message if necessary
async function detectTriggeredInputDefences(
message: string,
defences: Defence[]
Expand All @@ -299,7 +290,6 @@ async function detectTriggeredInputDefences(
return combineDefenceReports(singleDefenceReports);
}

// detects triggered defences in bot output and blocks the message if necessary
function detectTriggeredOutputDefences(message: string, defences: Defence[]) {
const singleDefenceReports = [detectFilterBotOutput(message, defences)];
return combineDefenceReports(singleDefenceReports);
Expand Down Expand Up @@ -451,6 +441,7 @@ async function detectEvaluationLLM(
): Promise<SingleDefenceReport> {
const defence = DEFENCE_ID.PROMPT_EVALUATION_LLM;
// to save money and processing time, and to reduce risk of rate limiting, we only run if defence is active
// this means that, contrary to the other defences, the user won't get alerts when the defence is not active, i.e. "your last prompt would have been blocked by the prompt evaluation LLM"
if (isDefenceActive(DEFENCE_ID.PROMPT_EVALUATION_LLM, defences)) {
const promptEvalLLMPrompt = getPromptEvalPromptFromConfig(defences);

Expand Down

0 comments on commit 496c30f

Please sign in to comment.