DeepSeek-OCR-2 / code /tt_dsocr /tests /test_host_inputs.py
changh95's picture
tt-model push deepseek-ocr-2 (container)
c60a316 verified
Raw History Blame Contribute Delete
1.23 kB
# SPDX-License-Identifier: Apache-2.0
"""Text inputs that the tokenizer cannot take (a lone UTF-16 surrogate, valid in JSON) are a 400, not a 500."""
from __future__ import annotations
import os
import sys
import pytest
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(os.path.dirname(HERE)))
from tt_dsocr import config as C # noqa: E402
from tt_dsocr.api import DeepSeekOcr, InputError # noqa: E402
def _model(variant):
m = DeepSeekOcr.__new__(DeepSeekOcr)
m.cfg = C.resolve_config({"DSOCR_VARIANT": variant, "DSOCR_BACKEND": "fake"})
m.vinfo = m.cfg.info
m.tasks = C.TASK_PROMPTS[variant]
return m
@pytest.mark.parametrize("variant", ["deepseek-ocr", "deepseek-ocr-2", "unlimited-ocr-2"])
def test_lone_surrogate_prompt_is_an_input_error(variant):
m = _model(variant)
with pytest.raises(InputError, match="surrogate"):
m.resolve_prompt(None, "read this \ud800 please", None)
if "locate" in m.tasks:
with pytest.raises(InputError, match="surrogate"):
m.resolve_prompt("locate", None, "x\udfff")
# ordinary non-ASCII text is fine
assert m.resolve_prompt(None, "읽어 주세요 ✓", None)[1] == "읽어 주세요 ✓"