@@ -5,22 +5,25 @@ import { GeminiAICanonicalEvaluationStrategy } from './frameworks/gemini/gemini-
55import { OpenAICanonicalEvaluationStrategy } from './frameworks/openai/openai-converter' ;
66import { VercelAICanonicalEvaluationStrategy } from './frameworks/vercelai/vercelai-converter' ;
77import {
8+ type CompilePromptResponse ,
89 EvaluationProxyAPIRequest ,
910 EvaluationProxyAPIRequestSchema ,
10- EvaluationRequestV2Schema ,
1111 type EvaluationRequestV2 ,
12+ EvaluationRequestV2Schema ,
1213 type EvaluationResponse ,
1314 type Framework ,
1415} from './types' ;
1516
1617export type {
18+ CompilePromptResponse ,
1719 EvaluationProxyAPIRequest ,
1820 EvaluationRequestV2 ,
1921 EvaluationResponse ,
2022 Framework ,
2123 LLMMessage ,
2224 ModelMode ,
2325 PolicyTarget ,
26+ ToolResponse ,
2427} from './types' ;
2528
2629/**
@@ -418,4 +421,66 @@ export class Qualifire {
418421 const jsonResponse = await response . json ( ) ;
419422 return jsonResponse as EvaluationResponse ;
420423 } ;
424+
425+ /**
426+ * Compiles a prompt from Qualifire Studio with the specified parameters.
427+ *
428+ * @param promptId - The ID of the prompt to compile.
429+ * @param revisionId - Optional revision ID to use. If not provided, uses the latest revision.
430+ * @param params - Optional dictionary of parameters to substitute in the prompt template.
431+ * @returns A CompilePromptResponse containing the compiled prompt details.
432+ *
433+ * @example
434+ * ```ts
435+ * const qualifire = new Qualifire({ apiKey: 'your_api_key' });
436+ *
437+ * const response = await qualifire.compilePrompt({
438+ * promptId: 'prompt-123',
439+ * revisionId: 'rev-456',
440+ * params: {
441+ * user_name: 'John',
442+ * language: 'French'
443+ * }
444+ * });
445+ *
446+ * console.log(response.messages);
447+ * console.log(response.tools);
448+ * ```
449+ */
450+ compilePrompt = async ( {
451+ promptId,
452+ revisionId,
453+ params,
454+ } : {
455+ promptId : string ;
456+ revisionId ?: string ;
457+ params ?: Record < string , string > ;
458+ } ) : Promise < CompilePromptResponse > => {
459+ let url = `${ this . baseUrl } /api/v1/studio/prompts/${ promptId } /compile` ;
460+ if ( revisionId ) {
461+ url = `${ url } ?revision=${ revisionId } ` ;
462+ }
463+
464+ const headers = {
465+ 'Content-Type' : 'application/json' ,
466+ 'X-Qualifire-API-Key' : this . sdkKey ,
467+ } ;
468+
469+ const body = JSON . stringify ( {
470+ variables : params || { } ,
471+ } ) ;
472+
473+ const response = await fetch ( url , {
474+ method : 'POST' ,
475+ headers,
476+ body,
477+ } ) ;
478+
479+ if ( ! response . ok ) {
480+ throw new Error ( `Qualifire API error: ${ response . statusText } ` ) ;
481+ }
482+
483+ const jsonResponse = await response . json ( ) ;
484+ return jsonResponse as CompilePromptResponse ;
485+ } ;
421486}
0 commit comments