/** * @file Base class for all LLM-based scorers * Provides common functionality for calling LLMs and parsing responses */ import type { JsonObject, AIProvider, LLMScorer, LLMScorerConfig, ScoreResult, ScorerInput, ScorerMetadata } from "../../../types/index.js"; import { BaseScorer } from "../baseScorer.js"; /** * Default LLM scorer configuration */ export declare const DEFAULT_LLM_SCORER_CONFIG: LLMScorerConfig; /** * Abstract base class for LLM-based scorers */ export declare abstract class BaseLLMScorer extends BaseScorer implements LLMScorer { protected _llmConfig: LLMScorerConfig; protected provider?: AIProvider; private initializationPromise; constructor(metadata: ScorerMetadata, config?: LLMScorerConfig); /** * Get LLM-specific configuration */ get llmConfig(): LLMScorerConfig; /** * Generate the prompt for LLM scoring - must be implemented by subclasses */ abstract generatePrompt(input: ScorerInput): string; /** * Parse LLM response into score result - must be implemented by subclasses */ abstract parseResponse(response: string, input: ScorerInput): Partial; /** * Main scoring method */ score(input: ScorerInput): Promise; /** * Initialize the AI provider */ protected initializeProvider(): Promise; /** * Internal method to actually initialize the provider */ private _doInitializeProvider; /** * Call the LLM with the given prompt */ protected callLLM(prompt: string): Promise; /** * Extract JSON from LLM response * Handles various formats including markdown code blocks */ protected extractJSON(response: string): JsonObject | null; /** * Simple template substitution for prompts */ protected substituteTemplate(template: string, variables: Record): string; /** * Handle conditional template blocks */ protected processConditionals(template: string, conditions: Record): string; /** * Extract a numeric score from text response * Safe numeric extraction without ReDoS-prone regex */ protected extractNumericScore(text: string): number | null; /** * Extract a numeric score from text response with fallback */ protected extractScoreFromText(text: string, min?: number, max?: number): number; }