ds-sfcoe-ailabs
Version:
AI-powered code review tool with static analysis integration for comprehensive code quality assessment.
54 lines (53 loc) • 2 kB
JavaScript
import { OpenAiClient, AzureOpenAiClient, AIProviderType, AnthropicAiClient, } from './index.js';
/**
* Factory class for creating AI provider instances
*
* Centralizes the creation of AI provider implementations based on
* provider type. Supports OpenAI, Azure OpenAI, and Anthropic providers
* with proper configuration and authentication setup.
*
* @example
* ```typescript
* const provider = AIProviderFactory.createProvider(
* AIProviderType.OpenAI,
* 'sk-...',
* 'gpt-4'
* );
* const response = await provider.generateResponse('Review this code');
* ```
*/
export default class AIProviderFactory {
/**
* Gets an AI provider instance
*
* @param type - The type of AI provider to create
* @param token - The API token for the provider
* @param model - The model name to use
* @param apiEndpoint - Optional API endpoint URL for the provider
* @param apiVersion - Optional API version for the provider
* @returns An instance of the specified AI provider
* @throws Error when the provider type is unsupported
* @example
* ```typescript
* const provider = AIProviderFactory.getInstance(
* AIProviderType.OpenAI,
* 'sk-abc123',
* 'gpt-4',
* 'https://api.openai.com/v1'
* );
* const response = await provider.generateResponse('Review code');
* ```
*/
static getInstance(type, token, model, apiEndpoint, apiVersion) {
switch (type) {
case AIProviderType.OpenAI:
return new OpenAiClient(token, model, apiEndpoint ?? '', apiVersion ?? '');
case AIProviderType.Anthropic:
return new AnthropicAiClient(token, model, apiEndpoint ?? '', apiVersion ?? '');
case AIProviderType.AzureOpenAI:
return new AzureOpenAiClient(token, model, apiEndpoint ?? '', apiVersion ?? '');
default:
throw new Error(`Unsupported AI provider type: ${type}`);
}
}
}