fix: allow WebTerminal init without OCR API key (openai>=2.40 requires key)
This commit is contained in:
parent
fd8decc3c3
commit
9e4b0bdb97
@ -26,11 +26,13 @@ class OCRClient:
|
|||||||
|
|
||||||
# httpx 0.28 起不再支持 proxies 参数,显式传入 http_client 以避免默认封装报错
|
# httpx 0.28 起不再支持 proxies 参数,显式传入 http_client 以避免默认封装报错
|
||||||
self.http_client = httpx.Client()
|
self.http_client = httpx.Client()
|
||||||
self.client = OpenAI(
|
self.client = None
|
||||||
api_key=OCR_API_KEY,
|
if OCR_API_KEY:
|
||||||
base_url=base_url or None,
|
self.client = OpenAI(
|
||||||
http_client=self.http_client,
|
api_key=OCR_API_KEY,
|
||||||
)
|
base_url=base_url or None,
|
||||||
|
http_client=self.http_client,
|
||||||
|
)
|
||||||
self.model = OCR_MODEL_ID
|
self.model = OCR_MODEL_ID
|
||||||
self.max_tokens = OCR_MAX_TOKENS or 4096
|
self.max_tokens = OCR_MAX_TOKENS or 4096
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ class OCRClient:
|
|||||||
|
|
||||||
if not prompt or not str(prompt).strip():
|
if not prompt or not str(prompt).strip():
|
||||||
return {"success": False, "error": "prompt 不能为空", "warnings": warnings}
|
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}
|
return {"success": False, "error": "VLM 配置缺失,请设置 OCR_API_BASE_URL / OCR_API_KEY / OCR_MODEL_ID", "warnings": warnings}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user