UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

70 lines (69 loc) 2.47 kB
/** * @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<ScoreResult>; /** * Main scoring method */ score(input: ScorerInput): Promise<ScoreResult>; /** * Initialize the AI provider */ protected initializeProvider(): Promise<void>; /** * Internal method to actually initialize the provider */ private _doInitializeProvider; /** * Call the LLM with the given prompt */ protected callLLM(prompt: string): Promise<string>; /** * 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, string | string[] | undefined>): string; /** * Handle conditional template blocks */ protected processConditionals(template: string, conditions: Record<string, boolean>): 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; }