Skip to content

Commit

Permalink
Fix JS API client
Browse files Browse the repository at this point in the history
  • Loading branch information
ristomcgehee committed Jan 19, 2024
1 parent bd8916f commit e90e642
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/javascript_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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

0 comments on commit e90e642

Please sign in to comment.