UNPKG

@bobmatnyc/ai-code-review

Version:

A TypeScript-based tool for automated code reviews using AI models from Google Gemini, Anthropic Claude, and OpenRouter

88 lines (87 loc) 3.03 kB
/** * @fileoverview Prompt optimizer for improving code review prompts. * * This module provides functionality for analyzing and improving code review prompts * based on the results they generate and user feedback. */ import { ReviewResult } from '../../types/review'; import { PromptManager } from '../PromptManager'; import { PromptCache } from '../cache/PromptCache'; import { ApiClientConfig } from '../../core/ApiClientSelector'; /** * Feedback on review quality */ export interface ReviewFeedback { /** * Rating from 1-5 (1 = poor, 5 = excellent) */ rating: number; /** * Comments on the review quality */ comments?: string; /** * Specific aspects that were good */ positiveAspects?: string[]; /** * Specific aspects that could be improved */ negativeAspects?: string[]; } /** * Optimizer for code review prompts */ export declare class PromptOptimizer { private promptManager; private promptCache; /** * Create a new prompt optimizer * @param promptManager Prompt manager instance * @param promptCache Prompt cache instance */ constructor(promptManager: PromptManager, promptCache: PromptCache); /** * Optimize a prompt based on review results and feedback * @param originalPrompt Original prompt template * @param reviewResult Review result generated with the prompt * @param feedback Feedback on the review quality * @param apiClientConfig API client configuration * @returns Promise resolving to the optimized prompt */ optimizePrompt(originalPrompt: string, reviewResult: ReviewResult, feedback: ReviewFeedback, apiClientConfig: ApiClientConfig): Promise<string>; /** * Load the meta-prompt template for prompt optimization * @returns Promise resolving to the meta-prompt template */ private loadMetaPromptTemplate; /** * Format the meta-prompt with the original prompt, review results, and feedback * @param metaPromptTemplate Meta-prompt template * @param originalPrompt Original prompt template * @param reviewResult Review result generated with the prompt * @param feedback Feedback on the review quality * @returns Formatted meta-prompt */ private formatMetaPrompt; /** * Format feedback as a string * @param feedback Feedback on the review quality * @returns Formatted feedback string */ private formatFeedback; /** * Generate an optimized prompt using the appropriate API client * @param metaPrompt Meta-prompt for prompt optimization * @param apiClientConfig API client configuration * @returns Promise resolving to the optimized prompt */ private generateOptimizedPrompt; /** * Cache an optimized prompt for future use * @param reviewType Type of review * @param optimizedPrompt Optimized prompt template * @param rating Rating of the optimized prompt */ private cacheOptimizedPrompt; }