UNPKG

ds-sfcoe-ailabs

Version:

AI-powered code review tool with static analysis integration for comprehensive code quality assessment.

122 lines (121 loc) 3.68 kB
import { ReviewHint, ReviewResponse } from './index.js'; /** * Abstract base class for AI provider implementations * * Defines the contract for AI services that can generate code reviews * and analysis responses. Implementations should handle specific AI * provider APIs like OpenAI, Anthropic, or Azure OpenAI. * * @example * ```typescript * class CustomAIProvider extends AIProvider { * async generateResponse(prompt: string): Promise<string> { * // Implementation specific logic * return 'AI response'; * } * } * ``` */ export default abstract class AIProvider { private apiKey; private model; private maxTokens; private apiEndpoint?; private apiVersion?; /** * Creates a new AI provider instance * * @param apiKey - The API key for the AI provider * @param model - The model name to use for AI processing */ /** * Creates a new AI provider instance * * @param apiKey - The API key for authentication * @param model - The AI model to use for requests * @param apiEndpoint - Optional custom API endpoint URL * @param apiVersion - Optional API version specification * @example * ```typescript * const provider = new OpenAIProvider( * 'sk-...', * 'gpt-4', * 'https://api.openai.com/v1', * '2023-05-15' * ); * ``` */ constructor(apiKey: string, model: string, apiEndpoint?: string, apiVersion?: string); /** * Generates a prompt for AI code review based on code snippet and hints * * @param codeSnippet - The code to be reviewed * @param hints - Array of review hints from static analysis tools * @returns Formatted prompt string for AI review * @example * ```typescript * const prompt = AIProvider.generatePrompt( * 'function add(a, b) { return a + b; }', * [{type: 'error', message: 'Missing type annotations'}] * ); * ``` */ protected static generatePrompt(codeSnippet: string, hints: ReviewHint[]): string; /** * Gets the review instructions for AI providers * * @returns The review instructions string */ protected static getReviewInstructions(): string; /** * Formats review hints into a readable string format * * @param hint - The review hint to format * @returns Formatted hint string */ private static formatHints; /** * Gets the API endpoint for the AI provider, if set * * @returns The API endpoint for the AI provider, if set */ getAPIEndpoint(): string | undefined; /** * Gets the API version for the AI provider, if set * * @returns The API version for the AI provider, if set */ getAPIVersion(): string | undefined; /** * Gets the AI model name * * @returns The model name */ getModel(): string; /** * Gets the API key * * @returns The API key */ getApiKey(): string; /** * Gets the maximum number of tokens for AI requests * * @returns The maximum token count */ getMaxTokens(): number; /** * Sets the maximum number of tokens for AI requests * * @param maxTokens - The maximum token count to set */ setMaxTokens(maxTokens: number): void; /** * Reviews code using the AI provider * * @param codeSnippet - The code to be reviewed * @param hints - Array of review hints from static analysis tools * @returns Promise that resolves to the AI review response */ abstract reviewCode(codeSnippet: string, hints: ReviewHint[]): Promise<ReviewResponse>; }