qualifire 1.4.0 → 1.5.0
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 +32 -2
- package/lib/index.js +48 -0
- package/lib/types.d.ts +33 -0
- package/lib/types.js +12 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EvaluationProxyAPIRequest, type EvaluationRequestV2, type EvaluationResponse } from './types';
|
|
2
|
-
export type { EvaluationProxyAPIRequest, EvaluationRequestV2, EvaluationResponse, Framework, LLMMessage, ModelMode, PolicyTarget, } from './types';
|
|
1
|
+
import { type CompilePromptResponse, EvaluationProxyAPIRequest, type EvaluationRequestV2, type EvaluationResponse } from './types';
|
|
2
|
+
export type { CompilePromptResponse, EvaluationProxyAPIRequest, EvaluationRequestV2, EvaluationResponse, Framework, LLMMessage, ModelMode, PolicyTarget, ToolResponse, } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Represents the Qualifire SDK.
|
|
5
5
|
*/
|
|
@@ -174,4 +174,34 @@ export declare class Qualifire {
|
|
|
174
174
|
output: string;
|
|
175
175
|
evaluationId: string;
|
|
176
176
|
}) => Promise<EvaluationResponse | undefined>;
|
|
177
|
+
/**
|
|
178
|
+
* Compiles a prompt from Qualifire Studio with the specified parameters.
|
|
179
|
+
*
|
|
180
|
+
* @param promptId - The ID of the prompt to compile.
|
|
181
|
+
* @param revisionId - Optional revision ID to use. If not provided, uses the latest revision.
|
|
182
|
+
* @param params - Optional dictionary of parameters to substitute in the prompt template.
|
|
183
|
+
* @returns A CompilePromptResponse containing the compiled prompt details.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* const qualifire = new Qualifire({ apiKey: 'your_api_key' });
|
|
188
|
+
*
|
|
189
|
+
* const response = await qualifire.compilePrompt({
|
|
190
|
+
* promptId: 'prompt-123',
|
|
191
|
+
* revisionId: 'rev-456',
|
|
192
|
+
* params: {
|
|
193
|
+
* user_name: 'John',
|
|
194
|
+
* language: 'French'
|
|
195
|
+
* }
|
|
196
|
+
* });
|
|
197
|
+
*
|
|
198
|
+
* console.log(response.messages);
|
|
199
|
+
* console.log(response.tools);
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
compilePrompt: ({ promptId, revisionId, params, }: {
|
|
203
|
+
promptId: string;
|
|
204
|
+
revisionId?: string;
|
|
205
|
+
params?: Record<string, string>;
|
|
206
|
+
}) => Promise<CompilePromptResponse>;
|
|
177
207
|
}
|
package/lib/index.js
CHANGED
|
@@ -337,6 +337,54 @@ class Qualifire {
|
|
|
337
337
|
const jsonResponse = await response.json();
|
|
338
338
|
return jsonResponse;
|
|
339
339
|
};
|
|
340
|
+
/**
|
|
341
|
+
* Compiles a prompt from Qualifire Studio with the specified parameters.
|
|
342
|
+
*
|
|
343
|
+
* @param promptId - The ID of the prompt to compile.
|
|
344
|
+
* @param revisionId - Optional revision ID to use. If not provided, uses the latest revision.
|
|
345
|
+
* @param params - Optional dictionary of parameters to substitute in the prompt template.
|
|
346
|
+
* @returns A CompilePromptResponse containing the compiled prompt details.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* const qualifire = new Qualifire({ apiKey: 'your_api_key' });
|
|
351
|
+
*
|
|
352
|
+
* const response = await qualifire.compilePrompt({
|
|
353
|
+
* promptId: 'prompt-123',
|
|
354
|
+
* revisionId: 'rev-456',
|
|
355
|
+
* params: {
|
|
356
|
+
* user_name: 'John',
|
|
357
|
+
* language: 'French'
|
|
358
|
+
* }
|
|
359
|
+
* });
|
|
360
|
+
*
|
|
361
|
+
* console.log(response.messages);
|
|
362
|
+
* console.log(response.tools);
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
this.compilePrompt = async ({ promptId, revisionId, params, }) => {
|
|
366
|
+
let url = `${this.baseUrl}/api/v1/studio/prompts/${promptId}/compile`;
|
|
367
|
+
if (revisionId) {
|
|
368
|
+
url = `${url}?revision=${revisionId}`;
|
|
369
|
+
}
|
|
370
|
+
const headers = {
|
|
371
|
+
'Content-Type': 'application/json',
|
|
372
|
+
'X-Qualifire-API-Key': this.sdkKey,
|
|
373
|
+
};
|
|
374
|
+
const body = JSON.stringify({
|
|
375
|
+
variables: params || {},
|
|
376
|
+
});
|
|
377
|
+
const response = await fetch(url, {
|
|
378
|
+
method: 'POST',
|
|
379
|
+
headers,
|
|
380
|
+
body,
|
|
381
|
+
});
|
|
382
|
+
if (!response.ok) {
|
|
383
|
+
throw new Error(`Qualifire API error: ${response.statusText}`);
|
|
384
|
+
}
|
|
385
|
+
const jsonResponse = await response.json();
|
|
386
|
+
return jsonResponse;
|
|
387
|
+
};
|
|
340
388
|
const key = apiKey || process.env.QUALIFIRE_API_KEY;
|
|
341
389
|
const qualifireBaseUrl = baseUrl || process.env.QUALIFIRE_BASE_URL || 'https://proxy.qualifire.ai';
|
|
342
390
|
if (!key) {
|
package/lib/types.d.ts
CHANGED
|
@@ -268,4 +268,37 @@ export type EvaluationResponse = z.infer<typeof EvaluationResponseSchema>;
|
|
|
268
268
|
export type LLMToolDefinition = z.infer<typeof LLMToolDefinitionSchema>;
|
|
269
269
|
export type LLMToolCall = z.infer<typeof LLMToolCallSchema>;
|
|
270
270
|
export type EvaluationRequestV2 = z.infer<typeof EvaluationRequestV2Schema>;
|
|
271
|
+
declare const ToolResponseSchema: z.ZodObject<{
|
|
272
|
+
type: z.ZodString;
|
|
273
|
+
function: z.ZodObject<{
|
|
274
|
+
name: z.ZodString;
|
|
275
|
+
description: z.ZodString;
|
|
276
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
277
|
+
}, z.core.$strip>;
|
|
278
|
+
}, z.core.$strip>;
|
|
279
|
+
declare const CompilePromptResponseSchema: z.ZodObject<{
|
|
280
|
+
id: z.ZodString;
|
|
281
|
+
name: z.ZodString;
|
|
282
|
+
revision: z.ZodNumber;
|
|
283
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
284
|
+
role: z.ZodString;
|
|
285
|
+
content: z.ZodOptional<z.ZodString>;
|
|
286
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
287
|
+
name: z.ZodString;
|
|
288
|
+
arguments: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
289
|
+
id: z.ZodOptional<z.ZodString>;
|
|
290
|
+
}, z.core.$strip>>>;
|
|
291
|
+
}, z.core.$strip>>;
|
|
292
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
293
|
+
type: z.ZodString;
|
|
294
|
+
function: z.ZodObject<{
|
|
295
|
+
name: z.ZodString;
|
|
296
|
+
description: z.ZodString;
|
|
297
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
298
|
+
}, z.core.$strip>;
|
|
299
|
+
}, z.core.$strip>>;
|
|
300
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
301
|
+
}, z.core.$strip>;
|
|
302
|
+
export type ToolResponse = z.infer<typeof ToolResponseSchema>;
|
|
303
|
+
export type CompilePromptResponse = z.infer<typeof CompilePromptResponseSchema>;
|
|
271
304
|
export {};
|
package/lib/types.js
CHANGED
|
@@ -230,3 +230,15 @@ const EvaluationResponseSchema = zod_1.z.object({
|
|
|
230
230
|
score: zod_1.z.number(),
|
|
231
231
|
status: zod_1.z.string(),
|
|
232
232
|
});
|
|
233
|
+
const ToolResponseSchema = zod_1.z.object({
|
|
234
|
+
type: zod_1.z.string(),
|
|
235
|
+
function: exports.LLMToolDefinitionSchema,
|
|
236
|
+
});
|
|
237
|
+
const CompilePromptResponseSchema = zod_1.z.object({
|
|
238
|
+
id: zod_1.z.string(),
|
|
239
|
+
name: zod_1.z.string(),
|
|
240
|
+
revision: zod_1.z.number(),
|
|
241
|
+
messages: zod_1.z.array(LLMMessageSchema),
|
|
242
|
+
tools: zod_1.z.array(ToolResponseSchema),
|
|
243
|
+
parameters: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
244
|
+
});
|