feat: revue de code, doc CODE_REVIEW, forfaits 2026, traduction LLM, providers avec modèle
Made-with: Cursor
This commit is contained in:
81
services/providers/__init__.py
Normal file
81
services/providers/__init__.py
Normal file
@@ -0,0 +1,81 @@
|
||||
"""
|
||||
Translation Providers Package.
|
||||
|
||||
This package provides a pluggable architecture for translation providers
|
||||
with a registry for easy access and fallback support.
|
||||
|
||||
Usage:
|
||||
from services.providers import TranslationProvider, registry
|
||||
from services.providers.schemas import TranslationRequest, TranslationResponse
|
||||
|
||||
# Get a provider (Google is auto-registered)
|
||||
google_provider = registry.get("google")
|
||||
|
||||
# Translate text
|
||||
request = TranslationRequest(text="Hello", target_language="fr")
|
||||
response = google_provider.translate_text(request)
|
||||
|
||||
# Use fallback chain
|
||||
provider = registry.get_first_available(["google", "deepl", "openai"])
|
||||
"""
|
||||
|
||||
from .base import TranslationProvider
|
||||
from .schemas import (
|
||||
TranslationRequest,
|
||||
TranslationResponse,
|
||||
BatchTranslationRequest,
|
||||
BatchTranslationResponse,
|
||||
ProviderHealthStatus,
|
||||
)
|
||||
from .registry import ProviderRegistry, registry, get_registry
|
||||
|
||||
__all__ = [
|
||||
"TranslationProvider",
|
||||
"TranslationRequest",
|
||||
"TranslationResponse",
|
||||
"BatchTranslationRequest",
|
||||
"BatchTranslationResponse",
|
||||
"ProviderHealthStatus",
|
||||
"ProviderRegistry",
|
||||
"registry",
|
||||
"get_registry",
|
||||
"translate_with_fallback",
|
||||
"translate_with_fallback_by_mode",
|
||||
"AllProvidersFailedError",
|
||||
"ALL_PROVIDERS_FAILED",
|
||||
]
|
||||
|
||||
|
||||
def _auto_register_providers() -> None:
|
||||
"""Auto-register available providers on module import."""
|
||||
from .google_provider import register_google_provider
|
||||
from .config import ProvidersConfig
|
||||
|
||||
if ProvidersConfig.GOOGLE_ENABLED:
|
||||
register_google_provider()
|
||||
|
||||
if ProvidersConfig.DEEPL_ENABLED and ProvidersConfig.DEEPL_API_KEY:
|
||||
from .deepl_provider import register_deepl_provider
|
||||
|
||||
register_deepl_provider()
|
||||
|
||||
if ProvidersConfig.OLLAMA_ENABLED:
|
||||
from .ollama_provider import register_ollama_provider
|
||||
|
||||
register_ollama_provider()
|
||||
|
||||
if ProvidersConfig.OPENAI_ENABLED and ProvidersConfig.OPENAI_API_KEY:
|
||||
from .openai_provider import register_openai_provider
|
||||
|
||||
register_openai_provider()
|
||||
|
||||
|
||||
_auto_register_providers()
|
||||
|
||||
# Import fallback functions for easy access
|
||||
from .fallback import (
|
||||
translate_with_fallback,
|
||||
translate_with_fallback_by_mode,
|
||||
AllProvidersFailedError,
|
||||
ALL_PROVIDERS_FAILED,
|
||||
)
|
||||
Reference in New Issue
Block a user