Skip to content

Commit a5db35e

Browse files
authored
Merge pull request #1483 from qualifire-dev/feature/qualifire-update-apis
Qualifire | Update Guardrails
2 parents 580c242 + 47ab937 commit a5db35e

13 files changed

Lines changed: 349 additions & 201 deletions

plugins/index.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ import { handler as defaultalllowercase } from './default/alllowercase';
1414
import { handler as defaultendsWith } from './default/endsWith';
1515
import { handler as defaultmodelWhitelist } from './default/modelWhitelist';
1616
import { handler as defaultnotNull } from './default/notNull';
17-
import { handler as qualifireDangerousContent } from './qualifire/dangerousContent';
17+
import { handler as qualifireContentModeration } from './qualifire/contentModeration';
1818
import { handler as qualifireGrounding } from './qualifire/grounding';
19-
import { handler as qualifireHarassment } from './qualifire/harassment';
20-
import { handler as qualifireInstructionFollowing } from './qualifire/instructionFollowing';
2119
import { handler as qualifirePolicy } from './qualifire/policy';
22-
import { handler as qualifireSexualContent } from './qualifire/sexualContent';
2320
import { handler as qualifireToolUseQuality } from './qualifire/toolUseQuality';
2421
import { handler as qualifireHallucinations } from './qualifire/hallucinations';
25-
import { handler as qualifireHateSpeech } from './qualifire/hateSpeech';
2622
import { handler as qualifirePii } from './qualifire/pii';
2723
import { handler as qualifirePromptInjections } from './qualifire/promptInjections';
2824
import { handler as defaultaddPrefix } from './default/addPrefix';
@@ -97,15 +93,11 @@ export const plugins = {
9793
notNull: defaultnotNull,
9894
},
9995
qualifire: {
100-
dangerousContent: qualifireDangerousContent,
96+
contentModeration: qualifireContentModeration,
10197
grounding: qualifireGrounding,
102-
harassment: qualifireHarassment,
103-
instructionFollowing: qualifireInstructionFollowing,
10498
policy: qualifirePolicy,
105-
sexualContent: qualifireSexualContent,
10699
toolUseQuality: qualifireToolUseQuality,
107100
hallucinations: qualifireHallucinations,
108-
hateSpeech: qualifireHateSpeech,
109101
pii: qualifirePii,
110102
promptInjections: qualifirePromptInjections,
111103
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const handler: PluginHandler = async (
1313
) => {
1414
const evaluationBody: any = {
1515
input: context.request.text,
16-
dangerous_content_check: true,
16+
content_moderation_check: true,
1717
};
1818

1919
if (eventType === 'afterRequestHook') {

plugins/qualifire/globals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const postQualifire = async (
3838

3939
const result = await post(BASE_URL, body, options, timeout_millis || 60000);
4040
const error = result?.error || null;
41-
const verdict = result?.status === 'success';
41+
const verdict = result?.status !== 'failed';
4242
const data = result?.evaluationResults;
4343

4444
return { error, verdict, data };

plugins/qualifire/grounding.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ export const handler: PluginHandler = async (
2222
};
2323
}
2424

25+
const mode = parameters?.mode || 'balanced';
26+
2527
const evaluationBody: any = {
2628
input: context.request.text,
2729
output: context.response.text,
2830
grounding_check: true,
31+
grounding_mode: mode,
2932
};
3033

3134
try {

plugins/qualifire/hallucinations.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ export const handler: PluginHandler = async (
2222
};
2323
}
2424

25+
const mode = parameters?.mode || 'balanced';
26+
2527
const evaluationBody: any = {
2628
input: context.request.text,
2729
output: context.response.text,
2830
hallucinations_check: true,
31+
hallucinations_mode: mode,
2932
};
3033

3134
try {

plugins/qualifire/harassment.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

plugins/qualifire/hateSpeech.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

plugins/qualifire/instructionFollowing.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

plugins/qualifire/manifest.json

Lines changed: 53 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,14 @@
1515
},
1616
"functions": [
1717
{
18-
"name": "Hate Speech Check",
19-
"id": "hateSpeech",
18+
"name": "Content Moderation Check",
19+
"id": "contentModeration",
2020
"supportedHooks": ["beforeRequestHook", "afterRequestHook"],
2121
"type": "guardrail",
2222
"description": [
2323
{
2424
"type": "subHeading",
25-
"text": "Checks for hate speech in the user input or model output."
26-
}
27-
],
28-
"parameters": {}
29-
},
30-
{
31-
"name": "Dangerous Content Check",
32-
"id": "dangerousContent",
33-
"supportedHooks": ["beforeRequestHook", "afterRequestHook"],
34-
"type": "guardrail",
35-
"description": [
36-
{
37-
"type": "subHeading",
38-
"text": "Checks for dangerous content in the user input or model output."
39-
}
40-
],
41-
"parameters": {}
42-
},
43-
{
44-
"name": "Sexual Content Check",
45-
"id": "sexualContent",
46-
"supportedHooks": ["beforeRequestHook", "afterRequestHook"],
47-
"type": "guardrail",
48-
"description": [
49-
{
50-
"type": "subHeading",
51-
"text": "Checks for sexual content in the user input or model output."
52-
}
53-
],
54-
"parameters": {}
55-
},
56-
{
57-
"name": "Harassment Check",
58-
"id": "harassment",
59-
"supportedHooks": ["beforeRequestHook", "afterRequestHook"],
60-
"type": "guardrail",
61-
"description": [
62-
{
63-
"type": "subHeading",
64-
"text": "Checks for harassment in the user input or model output."
65-
}
66-
],
67-
"parameters": {}
68-
},
69-
{
70-
"name": "Instruction Following Check",
71-
"id": "instructionFollowing",
72-
"supportedHooks": ["afterRequestHook"],
73-
"type": "guardrail",
74-
"description": [
75-
{
76-
"type": "subHeading",
77-
"text": "Checks that the model followed the instructions provided in the prompt."
25+
"text": "Checks for dangerous content, sexual content, harassment, and dangerous content in the user input or model output."
7826
}
7927
],
8028
"parameters": {}
@@ -90,7 +38,18 @@
9038
"text": "Checks that the model did not hallucinate."
9139
}
9240
],
93-
"parameters": {}
41+
"parameters": {
42+
"type": "object",
43+
"properties": {
44+
"mode": {
45+
"type": "string",
46+
"label": "Mode",
47+
"description": "The mode to use for the check",
48+
"enum": ["speed", "balanced", "quality"],
49+
"default": "balanced"
50+
}
51+
}
52+
}
9453
},
9554
{
9655
"name": "PII Check",
@@ -129,7 +88,18 @@
12988
"text": "Checks that the model is grounded in the context provided."
13089
}
13190
],
132-
"parameters": {}
91+
"parameters": {
92+
"type": "object",
93+
"properties": {
94+
"mode": {
95+
"type": "string",
96+
"label": "Mode",
97+
"description": "The mode to use for the check",
98+
"enum": ["speed", "balanced", "quality"],
99+
"default": "balanced"
100+
}
101+
}
102+
}
133103
},
134104
{
135105
"name": "Tool Use Quality Check",
@@ -142,7 +112,18 @@
142112
"text": "Checks the model's tool use quality. Including correct tool selection, correct tool parameters and values."
143113
}
144114
],
145-
"parameters": {}
115+
"parameters": {
116+
"type": "object",
117+
"properties": {
118+
"mode": {
119+
"type": "string",
120+
"label": "Mode",
121+
"description": "The mode to use for the check",
122+
"enum": ["speed", "balanced", "quality"],
123+
"default": "balanced"
124+
}
125+
}
126+
}
146127
},
147128
{
148129
"name": "Policy Violations Check",
@@ -170,6 +151,20 @@
170151
}
171152
]
172153
}
154+
},
155+
"mode": {
156+
"type": "string",
157+
"label": "Mode",
158+
"description": "The mode to use for the check",
159+
"enum": ["speed", "balanced", "quality"],
160+
"default": "balanced"
161+
},
162+
"policy_target": {
163+
"type": "string",
164+
"label": "Policy Target",
165+
"description": "Where to apply the policy check",
166+
"enum": ["input", "output", "both"],
167+
"default": "both"
173168
}
174169
},
175170
"required": ["policies"]

plugins/qualifire/policy.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,24 @@ export const handler: PluginHandler = async (
2121
};
2222
}
2323

24+
const mode = parameters?.mode || 'balanced';
25+
const policyTarget = parameters?.policy_target || 'both';
26+
2427
const evaluationBody: any = {
25-
input: context.request.text,
2628
assertions: parameters?.policies,
29+
assertions_mode: mode,
2730
};
2831

29-
if (eventType === 'afterRequestHook') {
32+
// Add input based on policy_target
33+
if (policyTarget === 'input' || policyTarget === 'both') {
34+
evaluationBody.input = context.request.text;
35+
}
36+
37+
// Add output based on policy_target and hook type
38+
if (
39+
eventType === 'afterRequestHook' &&
40+
(policyTarget === 'output' || policyTarget === 'both')
41+
) {
3042
evaluationBody.output = context.response.text;
3143
}
3244

0 commit comments

Comments
 (0)