feat(translate): language detection, async HTTP LLM, history model, agent improvements

- Add async HTTP-based LLM transport (_llm_async_http.py)
- Add orthogonal LLM call tests
- Improve language detection (_lang_detect.py) and batch insert
- Update translate schemas, service utils, preview constants/prompts
- Add TranslateHistoryModel with pagination and filtering
- Update agent confirmation, persistence, langgraph setup, run, tools
- Improve LLM health checking in shared module
- Update translate runs API, history route
This commit is contained in:
2026-07-08 19:35:49 +03:00
parent e6532c8dab
commit 3b13c67c0d
30 changed files with 1148 additions and 550 deletions

View File

@@ -17,6 +17,7 @@ from src.plugins.translate._lang_detect import (
get_detector,
detect_language,
_character_block_fallback,
_mark_suspicious_detections_und,
batch_detect,
)
@@ -184,6 +185,39 @@ class TestCharacterBlockFallback:
assert results[0] == "und"
class TestSuspiciousDetections:
"""Suspicious short Cyrillic detections are routed to LLM as und."""
def test_short_cyrillic_uk_for_ru_target_becomes_und(self):
results = _mark_suspicious_detections_und(
["Оплачено 22.06"],
["uk"],
["ru"],
)
assert results == ["und"]
def test_short_cyrillic_it_for_ru_target_becomes_und(self):
results = _mark_suspicious_detections_und(
["Нет"],
["it"],
["ru"],
)
assert results == ["und"]
def test_long_mixed_text_keeps_detection(self):
text = "Contract with KZ Trading for Financing in China Необходимо подтверждение депозита"
results = _mark_suspicious_detections_und([text], ["en"], ["ru"])
assert results == ["en"]
def test_non_ru_target_keeps_detection(self):
results = _mark_suspicious_detections_und(
["Оплачено 22.06"],
["uk"],
["en"],
)
assert results == ["uk"]
class TestBatchDetect:
"""batch_detect."""