diff --git a/modules/ocr_client.py b/modules/ocr_client.py index a5e103a..da4ba77 100644 --- a/modules/ocr_client.py +++ b/modules/ocr_client.py @@ -26,11 +26,13 @@ class OCRClient: # httpx 0.28 起不再支持 proxies 参数,显式传入 http_client 以避免默认封装报错 self.http_client = httpx.Client() - self.client = OpenAI( - api_key=OCR_API_KEY, - base_url=base_url or None, - http_client=self.http_client, - ) + self.client = None + if OCR_API_KEY: + self.client = OpenAI( + api_key=OCR_API_KEY, + base_url=base_url or None, + http_client=self.http_client, + ) self.model = OCR_MODEL_ID self.max_tokens = OCR_MAX_TOKENS or 4096 @@ -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: