Files
office_translator/services/providers/__init__.py
sepehr e6e1678b1d
Some checks failed
Deploy to Homelab / Deploy Wordly to 192.168.1.151 (push) Has been cancelled
Deploy to Homelab / Deploy Monitoring (if configured) (push) Has been cancelled
feat: add DeepSeek and Minimax (m2.7) translation providers
New providers:
- DeepSeek: direct API with deepseek-chat model, very cost-effective
- Minimax: MiniMax-M1 model via OpenAI-compatible API, supports m2.7

Changes:
- Full provider implementations with retry, health check, batch support
- Provider config with env vars (DEEPSEEK_*, MINIMAX_*)
- Auto-registration in provider registry
- Updated fallback chain to include new providers
- Updated setup-env.sh wizard with options 6 (deepseek) and 7 (minimax)
- Updated manage-keys.sh with new menu entries and provider switching
- Updated docker-compose.yml with new env vars

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-10 12:30:36 +02:00

92 lines
2.6 KiB
Python

"""
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()
if ProvidersConfig.DEEPSEEK_ENABLED and ProvidersConfig.DEEPSEEK_API_KEY:
from .deepseek_provider import register_deepseek_provider
register_deepseek_provider()
if ProvidersConfig.MINIMAX_ENABLED and ProvidersConfig.MINIMAX_API_KEY:
from .minimax_provider import register_minimax_provider
register_minimax_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,
)