feat: 支持 LLM 请求超时配置

This commit is contained in:
cat-shark
2026-08-13 22:01:42 +08:00
parent c16dfb380b
commit 1c6e01087b
3 changed files with 51 additions and 1 deletions
+2 -1
View File
@@ -18,6 +18,7 @@ def translate_lines(lines: list[str], params: dict) -> list[str]:
"http://192.168.123.70:8080/v1/chat/completions",
)
api_key = os.getenv("LLM_API_KEY", "")
request_timeout = float(os.getenv("LLM_TIMEOUT_SECONDS", "600"))
model = str(params.get("model") or os.getenv("LLM_MODEL", "default"))
target_language = str(params.get("target_language", "zh-CN"))
system_prompt = (
@@ -43,7 +44,7 @@ def translate_lines(lines: list[str], params: dict) -> list[str]:
headers=headers,
method="POST",
)
with urllib.request.urlopen(request, timeout=120) as response:
with urllib.request.urlopen(request, timeout=request_timeout) as response:
payload = json.loads(response.read().decode("utf-8"))
content = payload["choices"][0]["message"]["content"]
translated.extend(