fix: allow WebTerminal init without OCR API key (openai>=2.40 requires key)

This commit is contained in:
JOJO 2026-06-19 01:35:39 +08:00
parent fd8decc3c3
commit 9e4b0bdb97

View File

@ -26,6 +26,8 @@ class OCRClient:
# httpx 0.28 起不再支持 proxies 参数,显式传入 http_client 以避免默认封装报错
self.http_client = httpx.Client()
self.client = None
if OCR_API_KEY:
self.client = OpenAI(
api_key=OCR_API_KEY,
base_url=base_url or None,
@ -58,7 +60,7 @@ class OCRClient:
if not prompt or not str(prompt).strip():
return {"success": False, "error": "prompt 不能为空", "warnings": warnings}
if not OCR_API_KEY or not OCR_API_BASE_URL or not self.model:
if not self.client or not OCR_API_KEY or not OCR_API_BASE_URL or not self.model:
return {"success": False, "error": "VLM 配置缺失,请设置 OCR_API_BASE_URL / OCR_API_KEY / OCR_MODEL_ID", "warnings": warnings}
try: