qualifire 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +5 -25
- package/lib/index.js +51 -25
- package/lib/types.d.ts +166 -29
- package/lib/types.js +63 -13
- package/package.json +4 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EvaluationRequest, type EvaluationResponse } from './types';
|
|
2
|
+
export { EvaluationRequest, EvaluationResponse } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Represents the Qualifire SDK.
|
|
4
5
|
*/
|
|
@@ -16,20 +17,11 @@ export declare class Qualifire {
|
|
|
16
17
|
apiKey?: string;
|
|
17
18
|
baseUrl?: string;
|
|
18
19
|
});
|
|
20
|
+
init(): void;
|
|
19
21
|
/**
|
|
20
22
|
* Evaluates the output of a model against a set of criteria.
|
|
21
23
|
*
|
|
22
|
-
* @param
|
|
23
|
-
* @param output - The output of the model.
|
|
24
|
-
* @param assertions - An array of assertions to check.
|
|
25
|
-
* @param consistencyCheck - Whether to check for consistency.
|
|
26
|
-
* @param dangerousContentCheck - Whether to check for dangerous content.
|
|
27
|
-
* @param hallucinationsCheck - Whether to check for hallucinations.
|
|
28
|
-
* @param harassmentCheck - Whether to check for harassment.
|
|
29
|
-
* @param hateSpeechCheck - Whether to check for hate speech.
|
|
30
|
-
* @param piiCheck - Whether to check for personally identifiable information.
|
|
31
|
-
* @param promptInjections - Whether to check for prompt injections.
|
|
32
|
-
* @param sexualContentCheck - Whether to check for sexual content.
|
|
24
|
+
* @param request - The EvaluationRequest to send.
|
|
33
25
|
* @returns An object containing the evaluation results.
|
|
34
26
|
*
|
|
35
27
|
* @example
|
|
@@ -50,19 +42,7 @@ export declare class Qualifire {
|
|
|
50
42
|
* });
|
|
51
43
|
* ```
|
|
52
44
|
*/
|
|
53
|
-
evaluate: (
|
|
54
|
-
input: string;
|
|
55
|
-
output: string;
|
|
56
|
-
assertions?: string[] | undefined;
|
|
57
|
-
consistencyCheck?: boolean | undefined;
|
|
58
|
-
dangerousContentCheck?: boolean | undefined;
|
|
59
|
-
hallucinationsCheck?: boolean | undefined;
|
|
60
|
-
harassmentCheck?: boolean | undefined;
|
|
61
|
-
hateSpeechCheck?: boolean | undefined;
|
|
62
|
-
piiCheck?: boolean | undefined;
|
|
63
|
-
promptInjections?: boolean | undefined;
|
|
64
|
-
sexualContentCheck?: boolean | undefined;
|
|
65
|
-
}) => Promise<EvaluationResponse | undefined>;
|
|
45
|
+
evaluate: (request: EvaluationRequest) => Promise<EvaluationResponse | undefined>;
|
|
66
46
|
/**
|
|
67
47
|
* Invokes an evaluation for a given evaluation ID.
|
|
68
48
|
*
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.Qualifire = void 0;
|
|
37
|
+
const types_1 = require("./types");
|
|
38
|
+
const traceloop = __importStar(require("@traceloop/node-server-sdk"));
|
|
4
39
|
/**
|
|
5
40
|
* Represents the Qualifire SDK.
|
|
6
41
|
*/
|
|
@@ -16,17 +51,7 @@ class Qualifire {
|
|
|
16
51
|
/**
|
|
17
52
|
* Evaluates the output of a model against a set of criteria.
|
|
18
53
|
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param output - The output of the model.
|
|
21
|
-
* @param assertions - An array of assertions to check.
|
|
22
|
-
* @param consistencyCheck - Whether to check for consistency.
|
|
23
|
-
* @param dangerousContentCheck - Whether to check for dangerous content.
|
|
24
|
-
* @param hallucinationsCheck - Whether to check for hallucinations.
|
|
25
|
-
* @param harassmentCheck - Whether to check for harassment.
|
|
26
|
-
* @param hateSpeechCheck - Whether to check for hate speech.
|
|
27
|
-
* @param piiCheck - Whether to check for personally identifiable information.
|
|
28
|
-
* @param promptInjections - Whether to check for prompt injections.
|
|
29
|
-
* @param sexualContentCheck - Whether to check for sexual content.
|
|
54
|
+
* @param request - The EvaluationRequest to send.
|
|
30
55
|
* @returns An object containing the evaluation results.
|
|
31
56
|
*
|
|
32
57
|
* @example
|
|
@@ -47,21 +72,10 @@ class Qualifire {
|
|
|
47
72
|
* });
|
|
48
73
|
* ```
|
|
49
74
|
*/
|
|
50
|
-
this.evaluate = async (
|
|
75
|
+
this.evaluate = async (request) => {
|
|
76
|
+
const parsedRequest = types_1.EvaluationRequestSchema.parse(request);
|
|
51
77
|
const url = `${this.baseUrl}/api/evaluation/evaluate`;
|
|
52
|
-
const body = JSON.stringify(
|
|
53
|
-
input,
|
|
54
|
-
output,
|
|
55
|
-
assertions,
|
|
56
|
-
consistency_check: consistencyCheck,
|
|
57
|
-
dangerous_content_check: dangerousContentCheck,
|
|
58
|
-
hallucinations_check: hallucinationsCheck,
|
|
59
|
-
harassment_check: harassmentCheck,
|
|
60
|
-
hate_speech_check: hateSpeechCheck,
|
|
61
|
-
pii_check: piiCheck,
|
|
62
|
-
prompt_injections: promptInjections,
|
|
63
|
-
sexual_content_check: sexualContentCheck,
|
|
64
|
-
});
|
|
78
|
+
const body = JSON.stringify(parsedRequest);
|
|
65
79
|
const headers = {
|
|
66
80
|
'Content-Type': 'application/json',
|
|
67
81
|
'X-Qualifire-API-Key': this.sdkKey,
|
|
@@ -125,5 +139,17 @@ class Qualifire {
|
|
|
125
139
|
this.sdkKey = key;
|
|
126
140
|
this.baseUrl = qualifireBaseUrl;
|
|
127
141
|
}
|
|
142
|
+
init() {
|
|
143
|
+
process.env.TRACELOOP_TELEMETRY = 'false';
|
|
144
|
+
traceloop.initialize({
|
|
145
|
+
baseUrl: `${this.baseUrl}/api/telemetry`,
|
|
146
|
+
headers: {
|
|
147
|
+
'X-Qualifire-API-Key': this.sdkKey,
|
|
148
|
+
},
|
|
149
|
+
traceloopSyncEnabled: false,
|
|
150
|
+
silenceInitializationMessage: true,
|
|
151
|
+
disableBatch: true,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
128
154
|
}
|
|
129
155
|
exports.Qualifire = Qualifire;
|
package/lib/types.d.ts
CHANGED
|
@@ -163,59 +163,196 @@ export declare const outputSchema: z.ZodObject<{
|
|
|
163
163
|
system_fingerprint?: string | undefined;
|
|
164
164
|
}>;
|
|
165
165
|
export type Output = z.infer<typeof outputSchema> | string;
|
|
166
|
-
declare const EvaluationRequestSchema: z.ZodObject<{
|
|
167
|
-
input: z.ZodString
|
|
168
|
-
output: z.ZodString
|
|
169
|
-
consistency_check: z.ZodBoolean;
|
|
170
|
-
dangerous_content_check: z.ZodBoolean;
|
|
171
|
-
hallucinations_check: z.ZodBoolean;
|
|
172
|
-
harassment_check: z.ZodBoolean;
|
|
173
|
-
hate_speech_check: z.ZodBoolean;
|
|
174
|
-
pii_check: z.ZodBoolean;
|
|
175
|
-
prompt_injections: z.ZodBoolean;
|
|
176
|
-
sexual_content_check: z.ZodBoolean;
|
|
166
|
+
export declare const EvaluationRequestSchema: z.ZodEffects<z.ZodObject<{
|
|
167
|
+
input: z.ZodOptional<z.ZodString>;
|
|
168
|
+
output: z.ZodOptional<z.ZodString>;
|
|
177
169
|
messages: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
178
|
-
content: z.ZodString;
|
|
179
170
|
role: z.ZodString;
|
|
171
|
+
content: z.ZodOptional<z.ZodString>;
|
|
172
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
173
|
+
name: z.ZodString;
|
|
174
|
+
arguments: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
175
|
+
id: z.ZodOptional<z.ZodString>;
|
|
176
|
+
}, "strip", z.ZodTypeAny, {
|
|
177
|
+
name: string;
|
|
178
|
+
arguments: Record<string, any>;
|
|
179
|
+
id?: string | undefined;
|
|
180
|
+
}, {
|
|
181
|
+
name: string;
|
|
182
|
+
arguments: Record<string, any>;
|
|
183
|
+
id?: string | undefined;
|
|
184
|
+
}>, "many">>;
|
|
180
185
|
}, "strip", z.ZodTypeAny, {
|
|
181
186
|
role: string;
|
|
182
|
-
content
|
|
187
|
+
content?: string | undefined;
|
|
188
|
+
tool_calls?: {
|
|
189
|
+
name: string;
|
|
190
|
+
arguments: Record<string, any>;
|
|
191
|
+
id?: string | undefined;
|
|
192
|
+
}[] | undefined;
|
|
183
193
|
}, {
|
|
184
194
|
role: string;
|
|
185
|
-
content
|
|
195
|
+
content?: string | undefined;
|
|
196
|
+
tool_calls?: {
|
|
197
|
+
name: string;
|
|
198
|
+
arguments: Record<string, any>;
|
|
199
|
+
id?: string | undefined;
|
|
200
|
+
}[] | undefined;
|
|
186
201
|
}>, "many">>;
|
|
202
|
+
available_tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
203
|
+
name: z.ZodString;
|
|
204
|
+
description: z.ZodString;
|
|
205
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
206
|
+
}, "strip", z.ZodTypeAny, {
|
|
207
|
+
name: string;
|
|
208
|
+
description: string;
|
|
209
|
+
parameters: Record<string, any>;
|
|
210
|
+
}, {
|
|
211
|
+
name: string;
|
|
212
|
+
description: string;
|
|
213
|
+
parameters: Record<string, any>;
|
|
214
|
+
}>, "many">>;
|
|
215
|
+
dangerous_content_check: z.ZodDefault<z.ZodBoolean>;
|
|
216
|
+
grounding_check: z.ZodDefault<z.ZodBoolean>;
|
|
217
|
+
hallucinations_check: z.ZodDefault<z.ZodBoolean>;
|
|
218
|
+
harassment_check: z.ZodDefault<z.ZodBoolean>;
|
|
219
|
+
hate_speech_check: z.ZodDefault<z.ZodBoolean>;
|
|
220
|
+
instructions_following_check: z.ZodDefault<z.ZodBoolean>;
|
|
221
|
+
pii_check: z.ZodDefault<z.ZodBoolean>;
|
|
222
|
+
prompt_injections: z.ZodDefault<z.ZodBoolean>;
|
|
223
|
+
sexual_content_check: z.ZodDefault<z.ZodBoolean>;
|
|
224
|
+
syntax_checks: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
225
|
+
args: z.ZodString;
|
|
226
|
+
}, "strip", z.ZodTypeAny, {
|
|
227
|
+
args: string;
|
|
228
|
+
}, {
|
|
229
|
+
args: string;
|
|
230
|
+
}>>>;
|
|
231
|
+
tool_selection_quality_check: z.ZodDefault<z.ZodBoolean>;
|
|
187
232
|
assertions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
188
233
|
}, "strip", z.ZodTypeAny, {
|
|
189
|
-
input: string;
|
|
190
|
-
output: string;
|
|
191
|
-
consistency_check: boolean;
|
|
192
234
|
dangerous_content_check: boolean;
|
|
235
|
+
grounding_check: boolean;
|
|
193
236
|
hallucinations_check: boolean;
|
|
194
237
|
harassment_check: boolean;
|
|
195
238
|
hate_speech_check: boolean;
|
|
239
|
+
instructions_following_check: boolean;
|
|
196
240
|
pii_check: boolean;
|
|
197
241
|
prompt_injections: boolean;
|
|
198
242
|
sexual_content_check: boolean;
|
|
243
|
+
tool_selection_quality_check: boolean;
|
|
199
244
|
messages?: {
|
|
200
245
|
role: string;
|
|
201
|
-
content
|
|
246
|
+
content?: string | undefined;
|
|
247
|
+
tool_calls?: {
|
|
248
|
+
name: string;
|
|
249
|
+
arguments: Record<string, any>;
|
|
250
|
+
id?: string | undefined;
|
|
251
|
+
}[] | undefined;
|
|
252
|
+
}[] | undefined;
|
|
253
|
+
input?: string | undefined;
|
|
254
|
+
output?: string | undefined;
|
|
255
|
+
available_tools?: {
|
|
256
|
+
name: string;
|
|
257
|
+
description: string;
|
|
258
|
+
parameters: Record<string, any>;
|
|
202
259
|
}[] | undefined;
|
|
260
|
+
syntax_checks?: Record<string, {
|
|
261
|
+
args: string;
|
|
262
|
+
}> | undefined;
|
|
203
263
|
assertions?: string[] | undefined;
|
|
204
264
|
}, {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
265
|
+
messages?: {
|
|
266
|
+
role: string;
|
|
267
|
+
content?: string | undefined;
|
|
268
|
+
tool_calls?: {
|
|
269
|
+
name: string;
|
|
270
|
+
arguments: Record<string, any>;
|
|
271
|
+
id?: string | undefined;
|
|
272
|
+
}[] | undefined;
|
|
273
|
+
}[] | undefined;
|
|
274
|
+
input?: string | undefined;
|
|
275
|
+
output?: string | undefined;
|
|
276
|
+
available_tools?: {
|
|
277
|
+
name: string;
|
|
278
|
+
description: string;
|
|
279
|
+
parameters: Record<string, any>;
|
|
280
|
+
}[] | undefined;
|
|
281
|
+
dangerous_content_check?: boolean | undefined;
|
|
282
|
+
grounding_check?: boolean | undefined;
|
|
283
|
+
hallucinations_check?: boolean | undefined;
|
|
284
|
+
harassment_check?: boolean | undefined;
|
|
285
|
+
hate_speech_check?: boolean | undefined;
|
|
286
|
+
instructions_following_check?: boolean | undefined;
|
|
287
|
+
pii_check?: boolean | undefined;
|
|
288
|
+
prompt_injections?: boolean | undefined;
|
|
289
|
+
sexual_content_check?: boolean | undefined;
|
|
290
|
+
syntax_checks?: Record<string, {
|
|
291
|
+
args: string;
|
|
292
|
+
}> | undefined;
|
|
293
|
+
tool_selection_quality_check?: boolean | undefined;
|
|
294
|
+
assertions?: string[] | undefined;
|
|
295
|
+
}>, {
|
|
208
296
|
dangerous_content_check: boolean;
|
|
297
|
+
grounding_check: boolean;
|
|
209
298
|
hallucinations_check: boolean;
|
|
210
299
|
harassment_check: boolean;
|
|
211
300
|
hate_speech_check: boolean;
|
|
301
|
+
instructions_following_check: boolean;
|
|
212
302
|
pii_check: boolean;
|
|
213
303
|
prompt_injections: boolean;
|
|
214
304
|
sexual_content_check: boolean;
|
|
305
|
+
tool_selection_quality_check: boolean;
|
|
215
306
|
messages?: {
|
|
216
307
|
role: string;
|
|
217
|
-
content
|
|
308
|
+
content?: string | undefined;
|
|
309
|
+
tool_calls?: {
|
|
310
|
+
name: string;
|
|
311
|
+
arguments: Record<string, any>;
|
|
312
|
+
id?: string | undefined;
|
|
313
|
+
}[] | undefined;
|
|
218
314
|
}[] | undefined;
|
|
315
|
+
input?: string | undefined;
|
|
316
|
+
output?: string | undefined;
|
|
317
|
+
available_tools?: {
|
|
318
|
+
name: string;
|
|
319
|
+
description: string;
|
|
320
|
+
parameters: Record<string, any>;
|
|
321
|
+
}[] | undefined;
|
|
322
|
+
syntax_checks?: Record<string, {
|
|
323
|
+
args: string;
|
|
324
|
+
}> | undefined;
|
|
325
|
+
assertions?: string[] | undefined;
|
|
326
|
+
}, {
|
|
327
|
+
messages?: {
|
|
328
|
+
role: string;
|
|
329
|
+
content?: string | undefined;
|
|
330
|
+
tool_calls?: {
|
|
331
|
+
name: string;
|
|
332
|
+
arguments: Record<string, any>;
|
|
333
|
+
id?: string | undefined;
|
|
334
|
+
}[] | undefined;
|
|
335
|
+
}[] | undefined;
|
|
336
|
+
input?: string | undefined;
|
|
337
|
+
output?: string | undefined;
|
|
338
|
+
available_tools?: {
|
|
339
|
+
name: string;
|
|
340
|
+
description: string;
|
|
341
|
+
parameters: Record<string, any>;
|
|
342
|
+
}[] | undefined;
|
|
343
|
+
dangerous_content_check?: boolean | undefined;
|
|
344
|
+
grounding_check?: boolean | undefined;
|
|
345
|
+
hallucinations_check?: boolean | undefined;
|
|
346
|
+
harassment_check?: boolean | undefined;
|
|
347
|
+
hate_speech_check?: boolean | undefined;
|
|
348
|
+
instructions_following_check?: boolean | undefined;
|
|
349
|
+
pii_check?: boolean | undefined;
|
|
350
|
+
prompt_injections?: boolean | undefined;
|
|
351
|
+
sexual_content_check?: boolean | undefined;
|
|
352
|
+
syntax_checks?: Record<string, {
|
|
353
|
+
args: string;
|
|
354
|
+
}> | undefined;
|
|
355
|
+
tool_selection_quality_check?: boolean | undefined;
|
|
219
356
|
assertions?: string[] | undefined;
|
|
220
357
|
}>;
|
|
221
358
|
declare const EvaluationResponseSchema: z.ZodObject<{
|
|
@@ -229,18 +366,18 @@ declare const EvaluationResponseSchema: z.ZodObject<{
|
|
|
229
366
|
reason: z.ZodString;
|
|
230
367
|
score: z.ZodNumber;
|
|
231
368
|
}, "strip", z.ZodTypeAny, {
|
|
369
|
+
name: string;
|
|
232
370
|
claim: string;
|
|
233
371
|
confidence_score: number;
|
|
234
372
|
label: string;
|
|
235
|
-
name: string;
|
|
236
373
|
quote: string;
|
|
237
374
|
reason: string;
|
|
238
375
|
score: number;
|
|
239
376
|
}, {
|
|
377
|
+
name: string;
|
|
240
378
|
claim: string;
|
|
241
379
|
confidence_score: number;
|
|
242
380
|
label: string;
|
|
243
|
-
name: string;
|
|
244
381
|
quote: string;
|
|
245
382
|
reason: string;
|
|
246
383
|
score: number;
|
|
@@ -249,10 +386,10 @@ declare const EvaluationResponseSchema: z.ZodObject<{
|
|
|
249
386
|
}, "strip", z.ZodTypeAny, {
|
|
250
387
|
type: string;
|
|
251
388
|
results: {
|
|
389
|
+
name: string;
|
|
252
390
|
claim: string;
|
|
253
391
|
confidence_score: number;
|
|
254
392
|
label: string;
|
|
255
|
-
name: string;
|
|
256
393
|
quote: string;
|
|
257
394
|
reason: string;
|
|
258
395
|
score: number;
|
|
@@ -260,10 +397,10 @@ declare const EvaluationResponseSchema: z.ZodObject<{
|
|
|
260
397
|
}, {
|
|
261
398
|
type: string;
|
|
262
399
|
results: {
|
|
400
|
+
name: string;
|
|
263
401
|
claim: string;
|
|
264
402
|
confidence_score: number;
|
|
265
403
|
label: string;
|
|
266
|
-
name: string;
|
|
267
404
|
quote: string;
|
|
268
405
|
reason: string;
|
|
269
406
|
score: number;
|
|
@@ -277,10 +414,10 @@ declare const EvaluationResponseSchema: z.ZodObject<{
|
|
|
277
414
|
evaluationResults: {
|
|
278
415
|
type: string;
|
|
279
416
|
results: {
|
|
417
|
+
name: string;
|
|
280
418
|
claim: string;
|
|
281
419
|
confidence_score: number;
|
|
282
420
|
label: string;
|
|
283
|
-
name: string;
|
|
284
421
|
quote: string;
|
|
285
422
|
reason: string;
|
|
286
423
|
score: number;
|
|
@@ -292,16 +429,16 @@ declare const EvaluationResponseSchema: z.ZodObject<{
|
|
|
292
429
|
evaluationResults: {
|
|
293
430
|
type: string;
|
|
294
431
|
results: {
|
|
432
|
+
name: string;
|
|
295
433
|
claim: string;
|
|
296
434
|
confidence_score: number;
|
|
297
435
|
label: string;
|
|
298
|
-
name: string;
|
|
299
436
|
quote: string;
|
|
300
437
|
reason: string;
|
|
301
438
|
score: number;
|
|
302
439
|
}[];
|
|
303
440
|
}[];
|
|
304
441
|
}>;
|
|
442
|
+
export type EvaluationRequest = z.input<typeof EvaluationRequestSchema>;
|
|
305
443
|
export type EvaluationResponse = z.infer<typeof EvaluationResponseSchema>;
|
|
306
|
-
export type EvaluationRequestSchema = z.infer<typeof EvaluationRequestSchema>;
|
|
307
444
|
export {};
|
package/lib/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.outputSchema = exports.inputSchema = exports.usageSchema = exports.choiceSchema = exports.messageSchema = void 0;
|
|
3
|
+
exports.EvaluationRequestSchema = exports.outputSchema = exports.inputSchema = exports.usageSchema = exports.choiceSchema = exports.messageSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
exports.messageSchema = zod_1.z.object({
|
|
6
6
|
role: zod_1.z.string(),
|
|
@@ -29,23 +29,73 @@ exports.outputSchema = zod_1.z.object({
|
|
|
29
29
|
usage: exports.usageSchema.optional(),
|
|
30
30
|
system_fingerprint: zod_1.z.string().optional(),
|
|
31
31
|
});
|
|
32
|
+
const LLMToolDefinitionSchema = zod_1.z.object({
|
|
33
|
+
name: zod_1.z.string(),
|
|
34
|
+
description: zod_1.z.string(),
|
|
35
|
+
parameters: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
36
|
+
});
|
|
37
|
+
const LLMToolCallSchema = zod_1.z.object({
|
|
38
|
+
name: zod_1.z.string(),
|
|
39
|
+
arguments: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
40
|
+
id: zod_1.z.string().optional(),
|
|
41
|
+
});
|
|
32
42
|
const LLMMessageSchema = zod_1.z.object({
|
|
33
|
-
content: zod_1.z.string(),
|
|
34
43
|
role: zod_1.z.string(),
|
|
44
|
+
content: zod_1.z.string().optional(),
|
|
45
|
+
tool_calls: zod_1.z.array(LLMToolCallSchema).optional(),
|
|
46
|
+
});
|
|
47
|
+
const SyntaxCheckArgsSchema = zod_1.z.object({
|
|
48
|
+
args: zod_1.z.string(),
|
|
35
49
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
dangerous_content_check: zod_1.z.boolean(),
|
|
41
|
-
hallucinations_check: zod_1.z.boolean(),
|
|
42
|
-
harassment_check: zod_1.z.boolean(),
|
|
43
|
-
hate_speech_check: zod_1.z.boolean(),
|
|
44
|
-
pii_check: zod_1.z.boolean(),
|
|
45
|
-
prompt_injections: zod_1.z.boolean(),
|
|
46
|
-
sexual_content_check: zod_1.z.boolean(),
|
|
50
|
+
exports.EvaluationRequestSchema = zod_1.z
|
|
51
|
+
.object({
|
|
52
|
+
input: zod_1.z.string().optional(),
|
|
53
|
+
output: zod_1.z.string().optional(),
|
|
47
54
|
messages: zod_1.z.array(LLMMessageSchema).optional(),
|
|
55
|
+
available_tools: zod_1.z.array(LLMToolDefinitionSchema).optional(),
|
|
56
|
+
dangerous_content_check: zod_1.z.boolean().default(false),
|
|
57
|
+
grounding_check: zod_1.z.boolean().default(false),
|
|
58
|
+
hallucinations_check: zod_1.z.boolean().default(false),
|
|
59
|
+
harassment_check: zod_1.z.boolean().default(false),
|
|
60
|
+
hate_speech_check: zod_1.z.boolean().default(false),
|
|
61
|
+
instructions_following_check: zod_1.z.boolean().default(false),
|
|
62
|
+
pii_check: zod_1.z.boolean().default(false),
|
|
63
|
+
prompt_injections: zod_1.z.boolean().default(false),
|
|
64
|
+
sexual_content_check: zod_1.z.boolean().default(false),
|
|
65
|
+
syntax_checks: zod_1.z.record(zod_1.z.string(), SyntaxCheckArgsSchema).optional(),
|
|
66
|
+
tool_selection_quality_check: zod_1.z.boolean().default(false),
|
|
48
67
|
assertions: zod_1.z.array(zod_1.z.string()).optional(),
|
|
68
|
+
})
|
|
69
|
+
.superRefine((data, ctx) => {
|
|
70
|
+
const hasMessages = Array.isArray(data.messages) && data.messages.length > 0;
|
|
71
|
+
const hasInput = typeof data.input === 'string' && data.input.trim() !== '';
|
|
72
|
+
const hasOutput = typeof data.output === 'string' && data.output.trim() !== '';
|
|
73
|
+
// Validation: At least one of messages, input, or output
|
|
74
|
+
if (!hasMessages && !hasInput && !hasOutput) {
|
|
75
|
+
ctx.addIssue({
|
|
76
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
77
|
+
message: 'At least one of messages, input, or output must be set',
|
|
78
|
+
path: [], // Top level
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// Validation: tool_selection_quality_check requires messages and available_tools
|
|
82
|
+
if (data.tool_selection_quality_check) {
|
|
83
|
+
const hasAvailableTools = Array.isArray(data.available_tools) && data.available_tools.length > 0;
|
|
84
|
+
if (!hasMessages) {
|
|
85
|
+
ctx.addIssue({
|
|
86
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
87
|
+
message: 'messages must be provided when tool_selection_quality_check is true',
|
|
88
|
+
path: ['messages'],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (!hasAvailableTools) {
|
|
92
|
+
ctx.addIssue({
|
|
93
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
94
|
+
message: 'available_tools must be provided when tool_selection_quality_check is true',
|
|
95
|
+
path: ['available_tools'],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
49
99
|
});
|
|
50
100
|
const EvaluationResultSchema = zod_1.z.object({
|
|
51
101
|
claim: zod_1.z.string(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qualifire",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Qualifire client SDK",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -114,7 +114,9 @@
|
|
|
114
114
|
]
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
|
+
"@traceloop/node-server-sdk": "^0.13.3",
|
|
117
118
|
"openai": "^4.28.4",
|
|
118
119
|
"zod": "^3.22.4"
|
|
119
|
-
}
|
|
120
|
+
},
|
|
121
|
+
"packageManager": "pnpm@9.6.0+sha512.38dc6fba8dba35b39340b9700112c2fe1e12f10b17134715a4aa98ccf7bb035e76fd981cf0bb384dfa98f8d6af5481c2bef2f4266a24bfa20c34eb7147ce0b5e"
|
|
120
122
|
}
|