fix: integrate deepseek, resolve silent google api errors, fix google cloud keys
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2s
This commit is contained in:
@@ -998,10 +998,12 @@ async def _run_translation_job(
|
||||
# quota / network errors don't kill the job — deep_translator is tried
|
||||
# as a best-effort second chance.
|
||||
if _p == "google":
|
||||
# the user might have set GOOGLE_API_KEY instead of GOOGLE_CLOUD_API_KEY
|
||||
gc_key = _cfg(
|
||||
getattr(_admin_cfg.google_cloud, "api_key", None),
|
||||
"GOOGLE_CLOUD_API_KEY",
|
||||
)
|
||||
) or os.getenv("GOOGLE_API_KEY", "").strip()
|
||||
|
||||
if gc_key:
|
||||
from services.providers.google_cloud_provider import LegacyGoogleCloudAdapter
|
||||
from services.translation_service import GoogleTranslationProvider
|
||||
@@ -1037,6 +1039,30 @@ async def _run_translation_job(
|
||||
model=openai_model,
|
||||
system_prompt=full_prompt,
|
||||
)
|
||||
elif _p == "deepseek":
|
||||
from services.translation_service import OpenAITranslationProvider as _OAI
|
||||
ds_key = _cfg(getattr(_admin_cfg, "deepseek", None) and _admin_cfg.deepseek.api_key, "DEEPSEEK_API_KEY")
|
||||
ds_model = _cfg(getattr(_admin_cfg, "deepseek", None) and _admin_cfg.deepseek.model, "DEEPSEEK_MODEL", "deepseek-chat")
|
||||
ds_url = "https://api.deepseek.com/v1"
|
||||
if ds_key:
|
||||
translation_provider = _OAI(
|
||||
api_key=ds_key,
|
||||
model=ds_model,
|
||||
base_url=ds_url,
|
||||
system_prompt=full_prompt,
|
||||
)
|
||||
elif _p == "minimax":
|
||||
from services.translation_service import OpenAITranslationProvider as _OAI
|
||||
mm_key = _cfg(getattr(_admin_cfg, "minimax", None) and _admin_cfg.minimax.api_key, "MINIMAX_API_KEY")
|
||||
mm_model = _cfg(getattr(_admin_cfg, "minimax", None) and _admin_cfg.minimax.model, "MINIMAX_MODEL", "abab6.5s-chat")
|
||||
mm_url = "https://api.minimax.chat/v1"
|
||||
if mm_key:
|
||||
translation_provider = _OAI(
|
||||
api_key=mm_key,
|
||||
model=mm_model,
|
||||
base_url=mm_url,
|
||||
system_prompt=full_prompt,
|
||||
)
|
||||
elif _p == "deepl":
|
||||
deepl_key = _cfg(_admin_cfg.deepl.api_key, "DEEPL_API_KEY")
|
||||
if deepl_key:
|
||||
@@ -1243,10 +1269,16 @@ async def _run_translation_job(
|
||||
logger.info(f"Job {job_id}: Completed successfully")
|
||||
|
||||
except Exception as e:
|
||||
tracker.set_error(str(e))
|
||||
# Check if this is our structured TranslationProviderError
|
||||
if type(e).__name__ == "TranslationProviderError":
|
||||
tracker.set_error(e.message)
|
||||
logger.error(f"Job {job_id}: Provider Failed - {e.code}: {e.message}")
|
||||
else:
|
||||
tracker.set_error(str(e))
|
||||
logger.error(f"Job {job_id}: Failed - {e}")
|
||||
|
||||
# Record translation failure metric
|
||||
record_translation(provider=provider, file_type=file_extension or "unknown", duration=0, status="error")
|
||||
logger.error(f"Job {job_id}: Failed - {e}")
|
||||
|
||||
finally:
|
||||
if webhook_url:
|
||||
|
||||
Reference in New Issue
Block a user