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

Fix JS API client #96

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/javascript-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
CHROMA_COLLECTION_NAME: javascript_tests
run: |
npm install
npm run build
npm test

- name: Dump docker logs
Expand Down
18 changes: 2 additions & 16 deletions javascript-sdk/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,15 @@ export default class RebuffApi implements Rebuff {

async detectInjection({
userInput = "",
maxHeuristicScore = 0.75,
maxVectorScore = 0.9,
maxModelScore = 0.9,
runHeuristicCheck = true,
runVectorCheck = true,
runLanguageModelCheck = true,
tacticOverrides = [],
}: DetectRequest): Promise<DetectResponse> {
if (userInput === null) {
throw new RebuffError("userInput is required");
}
const requestData: DetectRequest = {
userInput: "",
userInputBase64: encodeString(userInput),
runHeuristicCheck: runHeuristicCheck,
runVectorCheck: runVectorCheck,
runLanguageModelCheck: runLanguageModelCheck,
maxVectorScore,
maxModelScore,
maxHeuristicScore,
tacticOverrides,
};

const response = await fetch(`${this.apiUrl}/api/detect`, {
Expand All @@ -76,10 +66,6 @@ export default class RebuffApi implements Rebuff {
if (!response.ok) {
throw new RebuffError((responseData as any)?.message);
}
responseData.injectionDetected =
responseData.heuristicScore > maxHeuristicScore ||
responseData.modelScore > maxModelScore ||
responseData.vectorScore.topScore > maxVectorScore;
return responseData;
}

Expand Down
Loading