032: Phase 4 US2 — Translate plugin fully async

T022-T028: All translate methods async.
- _llm_async_http.py created (httpx.AsyncClient+asyncio.sleep)
- Old _llm_http.py and preview_llm_client.py preserved (tombstone later)
- superset_executor, preview, executor, run_source, llm_call all async

RATIONALE: httpx.AsyncClient + asyncio.sleep instead of time.sleep.
REJECTED: AsyncOpenAI SDK — doesn't support custom base_url.
This commit is contained in:
2026-06-04 20:09:45 +03:00
parent 3b7778b1d1
commit 2a86ab6fe1
9 changed files with 316 additions and 73 deletions

View File

@@ -46,7 +46,7 @@ class BatchProcessingService:
# @PRE job and batch_rows are valid.
# @POST TranslationBatch and TranslationRecord rows are created.
# @SIDE_EFFECT LLM API call; DB writes.
def process_batch(
async def process_batch(
self, job: TranslationJob, run_id: str, batch_index: int,
batch_rows: list[dict[str, Any]],
dict_snapshot_hash: str | None = None, config_hash: str | None = None,
@@ -76,7 +76,7 @@ class BatchProcessingService:
# Count cache hits: pre_rows that have _cached_lang_values (served from cache, not same-lang/approved)
result["cache_hits"] = sum(1 for r in pre_rows if r.get("_cached_lang_values"))
if llm_rows:
llm_res = self._process_llm(job, run_id, llm_rows, dict_matches, bid, tls)
llm_res = await self._process_llm(job, run_id, llm_rows, dict_matches, bid, tls)
for k in ("successful", "failed", "skipped", "retries"):
result[k] += llm_res.get(k, 0)
@@ -205,7 +205,7 @@ class BatchProcessingService:
count += 1
return count
def _process_llm(self, job, run_id, rows_for_llm, dict_matches, bid, tls):
async def _process_llm(self, job, run_id, rows_for_llm, dict_matches, bid, tls):
# Resolve provider token config (DB values take priority over PROVIDER_DEFAULTS)
token_config = {"model": None, "context_window": None, "max_output_tokens": None}
if job.provider_id:
@@ -239,7 +239,7 @@ class BatchProcessingService:
},
)
result = self._llm_service.call_llm_for_batch(
result = await self._llm_service.call_llm_for_batch(
job=job, run_id=run_id, batch_rows=rows_for_llm,
dict_matches=dict_matches, batch_id=bid,
max_tokens=tb["max_output_needed"],