fix: patch ocr http client for httpx 0.28
This commit is contained in:
parent
adb1f1249a
commit
7b804bf65f
@ -5,6 +5,7 @@ import mimetypes
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
|
import httpx
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
|
|
||||||
from config import OCR_API_BASE_URL, OCR_API_KEY, OCR_MODEL_ID, OCR_MAX_TOKENS
|
from config import OCR_API_BASE_URL, OCR_API_KEY, OCR_MODEL_ID, OCR_MAX_TOKENS
|
||||||
@ -23,9 +24,12 @@ class OCRClient:
|
|||||||
if not base_url.endswith("/v1"):
|
if not base_url.endswith("/v1"):
|
||||||
base_url = f"{base_url}/v1"
|
base_url = f"{base_url}/v1"
|
||||||
|
|
||||||
|
# httpx 0.28 起不再支持 proxies 参数,显式传入 http_client 以避免默认封装报错
|
||||||
|
self.http_client = httpx.Client()
|
||||||
self.client = OpenAI(
|
self.client = OpenAI(
|
||||||
api_key=OCR_API_KEY,
|
api_key=OCR_API_KEY,
|
||||||
base_url=base_url,
|
base_url=base_url,
|
||||||
|
http_client=self.http_client,
|
||||||
)
|
)
|
||||||
self.model = OCR_MODEL_ID or "deepseek-ai/DeepSeek-OCR"
|
self.model = OCR_MODEL_ID or "deepseek-ai/DeepSeek-OCR"
|
||||||
self.max_tokens = OCR_MAX_TOKENS or 4096
|
self.max_tokens = OCR_MAX_TOKENS or 4096
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import mimetypes
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
|
import httpx
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
|
|
||||||
from config import OCR_API_BASE_URL, OCR_API_KEY, OCR_MODEL_ID, OCR_MAX_TOKENS
|
from config import OCR_API_BASE_URL, OCR_API_KEY, OCR_MODEL_ID, OCR_MAX_TOKENS
|
||||||
@ -22,9 +23,11 @@ class OCRClient:
|
|||||||
if not base_url.endswith("/v1"):
|
if not base_url.endswith("/v1"):
|
||||||
base_url = f"{base_url}/v1"
|
base_url = f"{base_url}/v1"
|
||||||
|
|
||||||
|
self.http_client = httpx.Client()
|
||||||
self.client = OpenAI(
|
self.client = OpenAI(
|
||||||
api_key=OCR_API_KEY,
|
api_key=OCR_API_KEY,
|
||||||
base_url=base_url,
|
base_url=base_url,
|
||||||
|
http_client=self.http_client,
|
||||||
)
|
)
|
||||||
self.model = OCR_MODEL_ID or "deepseek-ai/DeepSeek-OCR"
|
self.model = OCR_MODEL_ID or "deepseek-ai/DeepSeek-OCR"
|
||||||
self.max_tokens = OCR_MAX_TOKENS or 4096
|
self.max_tokens = OCR_MAX_TOKENS or 4096
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user