Spaces:
Sleeping
Sleeping
File size: 1,664 Bytes
8ba64a4 4645b0f 8ba64a4 4645b0f 8ba64a4 4645b0f 8ba64a4 4645b0f 8ba64a4 4645b0f 8ba64a4 4645b0f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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()
|