fix: respect ModelScope model page limit

This commit is contained in:
CoolBoy
2026-08-02 16:03:44 +08:00
parent 0e42ef73dc
commit 80a1b8518d
4 changed files with 45 additions and 3 deletions

View File

@@ -56,7 +56,7 @@ authority for account capacity and model/GPU uniqueness.
If the platform reports that a model/GPU is already being validated, the claim
is retained and the runner immediately draws replacement candidates from the
same scan instead of retrying the duplicate every cycle. Startup logs and the
health response expose `agent_version`; version `2026.08.02.1` or newer includes
health response expose `agent_version`; version `2026.08.02.2` or newer includes
this behavior.
## Deploy

View File

@@ -105,7 +105,8 @@ class HuggingFaceDiscovery:
min_downloads: int,
updated_after=None,
) -> list[HFModelSummary]:
page_size = min(max(1, limit), 100)
# ModelScope OpenAPI rejects values above 50 with InputParameterError.
page_size = min(max(1, limit), 50)
max_items = min(max(1, limit), 3000)
task_tag = MODELSCOPE_TASK_TAGS.get(pipeline_tag, pipeline_tag)
models: list[HFModelSummary] = []

View File

@@ -1 +1 @@
AGENT_VERSION = "2026.08.02.1"
AGENT_VERSION = "2026.08.02.2"

View File

@@ -0,0 +1,41 @@
from __future__ import annotations
import sys
import unittest
from pathlib import Path
PACKAGE_DIR = Path(__file__).resolve().parents[1] / "modelhub_submmit_api"
if str(PACKAGE_DIR) in sys.path:
sys.path.remove(str(PACKAGE_DIR))
sys.path.insert(0, str(PACKAGE_DIR))
from hf_discovery import HuggingFaceDiscovery # noqa: E402
class RecordingHttpClient:
def __init__(self) -> None:
self.queries: list[dict] = []
def request_json(self, _method: str, _path: str, *, query: dict) -> dict:
self.queries.append(query)
return {"success": True, "data": {"models": []}}
class ModelScopeDiscoveryTests(unittest.TestCase):
def test_openapi_page_size_never_exceeds_platform_limit(self) -> None:
http_client = RecordingHttpClient()
discovery = HuggingFaceDiscovery(http_client=http_client) # type: ignore[arg-type]
models = discovery.list_recent_models(
pipeline_tags=["text-generation"],
limit=1000,
min_downloads=0,
)
self.assertEqual([], models)
self.assertEqual(50, http_client.queries[0]["page_size"])
if __name__ == "__main__":
unittest.main()