Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion glmocr/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ def from_env(
_KW_MAP = {
"api_key": "pipeline.maas.api_key",
"api_url": "pipeline.maas.api_url",
"model": "pipeline.maas.model",
"mode": "pipeline.maas.enabled",
"timeout": "pipeline.maas.request_timeout",
"enable_layout": "pipeline.enable_layout",
Expand All @@ -442,6 +441,15 @@ def from_env(
"cuda_visible_devices": "pipeline.layout.cuda_visible_devices",
"layout_device": "pipeline.layout.device",
}

# `model` is shared by both MaaS and self-hosted modes.
# Keep MaaS behavior while also forwarding it to OCR API so that
# `GlmOcr(mode="selfhosted", model="...")` works as expected.
if "model" in overrides and overrides["model"] is not None:
model_value = str(overrides["model"])
_set_nested(data, "pipeline.maas.model", model_value)
_set_nested(data, "pipeline.ocr_api.model", model_value)

for kw, dotted in _KW_MAP.items():
if kw in overrides and overrides[kw] is not None:
raw = overrides[kw]
Expand Down
18 changes: 18 additions & 0 deletions glmocr/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,24 @@ def test_explicit_selfhosted_mode(self, monkeypatch):
assert parser._use_maas is False
parser.close()

def test_selfhosted_model_kwarg_is_forwarded_to_ocr_api(self, monkeypatch):
"""model=... should configure self-hosted OCR request model."""
from glmocr.config import _ENV_MAP, ENV_PREFIX

for suffix in _ENV_MAP:
monkeypatch.delenv(f"{ENV_PREFIX}{suffix}", raising=False)
monkeypatch.setattr("glmocr.config._find_dotenv", lambda: None)

with patch("glmocr.pipeline.Pipeline") as mock_pipeline:
mock_pipeline.return_value.start = MagicMock()
mock_pipeline.return_value.enable_layout = False
from glmocr.api import GlmOcr

parser = GlmOcr(mode="selfhosted", model="glm-ocr")
assert parser._use_maas is False
assert parser.config_model.pipeline.ocr_api.model == "glm-ocr"
parser.close()


class TestOCRClientOllamaConfig:
"""Tests for OCRClient initialization with Ollama api_mode."""
Expand Down
Loading