Skip to content

Commit 180fa4e

Browse files
authored
Merge pull request #56 from opendatalab/dev
Dev
2 parents 839f0b7 + 4cbebd8 commit 180fa4e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

mineru_vl_utils/mineru_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import asyncio
22
import math
3+
import os
34
import re
45
from concurrent.futures import Executor
56
from typing import Literal, Sequence
67

78
from PIL import Image
9+
from loguru import logger
810

911
from .post_process import post_process
1012
from .structs import BLOCK_TYPES, ContentBlock
@@ -322,6 +324,15 @@ def __init__(
322324
max_retries: int = 3, # for http-client backend only
323325
retry_backoff_factor: float = 0.5, # for http-client backend only
324326
) -> None:
327+
env_debug_value = os.getenv('MINERU_VL_DEBUG_ENABLE', '')
328+
if env_debug_value:
329+
if env_debug_value.lower() in ['true', '1', 'yes']:
330+
debug = True
331+
elif env_debug_value.lower() in ['false', '0', 'no']:
332+
debug = False
333+
else:
334+
logger.warning(f'unknown MINERU_VL_DEBUG_ENABLE config: {env_debug_value}, pass')
335+
325336
if backend == "transformers":
326337
if model is None or processor is None:
327338
if not model_path:

mineru_vl_utils/vlm_client/http_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44
import re
5+
from enum import Enum
56
from typing import AsyncIterable, Iterable, Sequence
67

78
import httpx
@@ -35,6 +36,16 @@ def _get_env(key: str, default: str | None = None) -> str:
3536
raise ValueError(f"Environment variable {key} is not set.")
3637

3738

39+
class HTTPMethod(str, Enum):
40+
HEAD = "HEAD"
41+
GET = "GET"
42+
PUT = "PUT"
43+
DELETE = "DELETE"
44+
OPTIONS = "OPTIONS"
45+
TRACE = "TRACE"
46+
POST = "POST"
47+
48+
3849
class HttpVlmClient(VlmClient):
3950
def __init__(
4051
self,
@@ -120,6 +131,7 @@ def _new_client(self) -> httpx.Client:
120131
retry=Retry(
121132
total=self.max_retries,
122133
backoff_factor=self.retry_backoff_factor,
134+
allowed_methods=list(HTTPMethod),
123135
),
124136
transport=httpx.HTTPTransport(
125137
limits=httpx.Limits(
@@ -144,6 +156,7 @@ async def _new_aio_client(self) -> httpx.AsyncClient:
144156
retry=Retry(
145157
total=self.max_retries,
146158
backoff_factor=self.retry_backoff_factor,
159+
allowed_methods=list(HTTPMethod),
147160
),
148161
transport=httpx.AsyncHTTPTransport(
149162
limits=httpx.Limits(

0 commit comments

Comments
 (0)