from typing import Type from ..config import get_settings from .base import BaseAttributionService from .service_anthropic import AnthropicService # Assuming this exists from .service_openai import OpenAIService from .service_gemini import GeminiService # Import the new GeminiService settings = get_settings() class AIServiceFactory: _services = { "openai": OpenAIService, "anthropic": AnthropicService, "gemini": GeminiService, # Add Gemini service } @classmethod def get_service(cls, ai_vendor: str = None) -> BaseAttributionService: """ Factory method to get an AI service instance. Args: ai_vendor (str, optional): The name of the AI vendor. Defaults to settings.DEFAULT_VENDOR. Returns: BaseAttributionService: An instance of the requested AI service. Raises: ValueError: If the ai_vendor is unsupported. """ # Use the provided ai_vendor or fallback to the default from settings ai_vendor_to_use = ai_vendor or settings.DEFAULT_VENDOR # Retrieve the service class from the dictionary (case-insensitive lookup) service_class = cls._services.get(ai_vendor_to_use.lower()) # If the service class is not found, raise an error if not service_class: raise ValueError(f"Unsupported AI vendor: {ai_vendor_to_use}. Supported vendors are: {', '.join(cls._services.keys())}") # Create and return an instance of the service return service_class()