@langchain/community
Version:
Third-party integrations for LangChain.js
45 lines (44 loc) • 1.55 kB
JavaScript
import { test } from "@jest/globals";
import { LLM } from "@langchain/core/language_models/llms";
import { LayerupSecurity, } from "../layerup_security.js";
// Mock LLM for testing purposes
export class MockLLM extends LLM {
constructor() {
super(...arguments);
Object.defineProperty(this, "lc_serializable", {
enumerable: true,
configurable: true,
writable: true,
value: true
});
}
static lc_name() {
return "MockLLM";
}
_llmType() {
return "mock_llm";
}
async _call(_input, _options) {
return "Hi Bob! How are you?";
}
}
test("Test LayerupSecurity with invalid API key", async () => {
const mockLLM = new MockLLM({});
const layerupSecurityOptions = {
llm: mockLLM,
layerupApiKey: "-- invalid API key --",
layerupApiBaseUrl: "https://api.uselayerup.com/v1",
promptGuardrails: [],
responseGuardrails: ["layerup.hallucination"],
mask: false,
metadata: { customer: "example@uselayerup.com" },
handleResponseGuardrailViolation: (violation) => ({
role: "assistant",
content: `Custom canned response with dynamic data! The violation rule was ${violation.offending_guardrail}.`,
}),
};
await expect(async () => {
const layerupSecurity = new LayerupSecurity(layerupSecurityOptions);
await layerupSecurity.invoke("My name is Bob Dylan. My SSN is 123-45-6789.");
}).rejects.toThrowError();
}, 50000);