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

Only doing LLM evaluation on phase 2 and sandbox #144

Merged
Merged
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
24 changes: 14 additions & 10 deletions backend/src/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,22 @@ async function chatGptSendMessage(message, session, currentPhase) {
let wonPhase = false;

// evaluate the message for prompt injection
const evalPrompt = await queryPromptEvaluationModel(message);
if (evalPrompt.isMalicious) {
defenceInfo.triggeredDefences.push("LLM_EVALUATION");
if (isDefenceActive("LLM_EVALUATION", session.defences)) {
console.debug("LLM evalutation defence active.");
defenceInfo.blocked = true;
const evalResponse =
"Message blocked by the malicious prompt evaluator." +
evalPrompt.reason;
return { reply: evalResponse, defenceInfo: defenceInfo };
// to speed up replies, only do this on phases where defences are active
if (currentPhase >= 2) {
const evalPrompt = await queryPromptEvaluationModel(message);
if (evalPrompt.isMalicious) {
defenceInfo.triggeredDefences.push("LLM_EVALUATION");
if (isDefenceActive("LLM_EVALUATION", session.defences)) {
console.debug("LLM evalutation defence active.");
defenceInfo.blocked = true;
const evalResponse =
"Message blocked by the malicious prompt evaluator." +
evalPrompt.reason;
return { reply: evalResponse, defenceInfo: defenceInfo };
}
}
}

// add user message to chat
session.chatHistory.push({ role: "user", content: message });

Expand Down