2026-10-27 02:54:53 +00:00
|
|
|
"""Start the pinned upstream parser; application features live in MaxKB."""
|
|
|
|
|
import os
|
2026-11-06 08:52:28 +00:00
|
|
|
import argparse
|
2026-10-27 02:54:53 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
import sys
|
2026-11-06 08:52:28 +00:00
|
|
|
from types import SimpleNamespace
|
2026-10-27 02:54:53 +00:00
|
|
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
os.environ.setdefault('MINERU_MODEL_SOURCE', 'local')
|
|
|
|
|
os.environ.setdefault('MINERU_API_MAX_CONCURRENT_REQUESTS', '1')
|
|
|
|
|
from mineru.version import __version__
|
|
|
|
|
from mineru import __file__ as module_path
|
2026-11-06 08:52:28 +00:00
|
|
|
if __version__ != '2.7.1' or not Path(module_path).resolve().is_relative_to(ROOT / 'mineru'):
|
2026-10-27 02:54:53 +00:00
|
|
|
raise RuntimeError('解析服务版本或源码路径不匹配')
|
2026-11-06 08:52:28 +00:00
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
|
parser.add_argument('--host', default='127.0.0.1')
|
|
|
|
|
parser.add_argument('--port', type=int, default=8000)
|
|
|
|
|
parser.add_argument('--mineru-api-max-concurrent-requests', type=int,
|
|
|
|
|
default=int(os.environ['MINERU_API_MAX_CONCURRENT_REQUESTS']))
|
|
|
|
|
parser.add_argument('--gpu-memory-utilization', type=float,
|
|
|
|
|
default=float(os.environ['MINERU_GPU_MEMORY_UTILIZATION'])
|
|
|
|
|
if os.getenv('MINERU_GPU_MEMORY_UTILIZATION') else None)
|
|
|
|
|
parser.add_argument('--reload', action='store_true')
|
|
|
|
|
args, engine_args = parser.parse_known_args()
|
|
|
|
|
if args.reload:
|
|
|
|
|
raise ValueError('解析服务使用单进程启动,请移除 --reload')
|
|
|
|
|
if args.mineru_api_max_concurrent_requests < 0:
|
|
|
|
|
raise ValueError('解析请求并发数不能小于 0')
|
|
|
|
|
if args.gpu_memory_utilization is not None and not 0 < args.gpu_memory_utilization < 1:
|
|
|
|
|
raise ValueError('MINERU_GPU_MEMORY_UTILIZATION must be between 0 and 1')
|
|
|
|
|
os.environ['MINERU_API_MAX_CONCURRENT_REQUESTS'] = str(args.mineru_api_max_concurrent_requests)
|
|
|
|
|
# Official 2.7.1's CLI puts every extra flag in app.state.config. The API
|
|
|
|
|
# forwards that dict to vLLM, where API-only flags are invalid EngineArgs.
|
|
|
|
|
# Configure the unmodified upstream ASGI app and pass only engine options.
|
|
|
|
|
from mineru.utils.cli_parser import arg_parse
|
|
|
|
|
from mineru.cli.fast_api import app
|
|
|
|
|
normalized = []
|
|
|
|
|
for value in engine_args:
|
|
|
|
|
normalized.extend(value.split('=', 1) if value.startswith('--') and '=' in value else [value])
|
|
|
|
|
app.state.config = arg_parse(SimpleNamespace(args=normalized))
|
|
|
|
|
if args.gpu_memory_utilization is not None:
|
|
|
|
|
app.state.config['gpu_memory_utilization'] = args.gpu_memory_utilization
|
|
|
|
|
import uvicorn
|
|
|
|
|
uvicorn.run(app, host=args.host, port=args.port)
|
2026-10-27 02:54:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|