MCPcopy Create free account
hub / github.com/modelscope/modelscope / HubApi

Class HubApi

modelscope/hub/api.py:52–324  ·  view source on GitHub ↗

ModelScope Hub API — delegates to ``modelscope_hub``. Maintains backward compatibility with the legacy ``HubApi`` interface; method behaviour is inherited from :class:`modelscope_hub.compat.LegacyHubApi`.

Source from the content-addressed store, hash-verified

50
51
52class HubApi(_LegacyHubApi):
53 """ModelScope Hub API — delegates to ``modelscope_hub``.
54
55 Maintains backward compatibility with the legacy ``HubApi`` interface;
56 method behaviour is inherited from
57 :class:`modelscope_hub.compat.LegacyHubApi`.
58 """
59
60 def __init__(
61 self,
62 endpoint: Optional[str] = None,
63 timeout: int = API_HTTP_CLIENT_TIMEOUT,
64 max_retries: int = API_HTTP_CLIENT_MAX_RETRIES,
65 token: Optional[str] = None,
66 ) -> None:
67 super().__init__(endpoint=endpoint, token=token)
68 # Preserved for callers that historically read these attributes.
69 self.endpoint = self._endpoint or self._api._config.endpoint
70 self.token = token
71 self.timeout = timeout
72 self.max_retries = max_retries
73 self.headers = {'user-agent': ModelScopeConfig.get_user_agent()}
74
75 # If non-default timeout/max_retries were provided, eagerly construct
76 # the internal LegacyClient so they actually take effect on the wire.
77 if (timeout != API_HTTP_CLIENT_TIMEOUT
78 or max_retries != API_HTTP_CLIENT_MAX_RETRIES):
79 from modelscope_hub._legacy_api import LegacyClient
80 from modelscope_hub.utils import build_user_agent
81 cfg = self._api._config
82 self._api._legacy = LegacyClient(
83 token=cfg.token,
84 endpoint=cfg.endpoint,
85 timeout=timeout,
86 max_retries=max_retries,
87 user_agent=build_user_agent(cfg.get_session_id()),
88 )
89
90 # ------------------------------------------------------------------
91 # Legacy method shims missing from LegacyHubApi
92 # ------------------------------------------------------------------
93 def create_model(self, model_id: str, **kwargs) -> str:
94 """Create a model repo — delegates to ``create_repo`` (model type).
95
96 Returns the model repository URL for backward compatibility.
97 Authentication errors are converted to ``ValueError`` by the compat layer.
98 """
99 # LegacyHubApi.create_model handles exception conversion;
100 # override endpoint in the returned URL with local self.endpoint.
101 result = super().create_model(model_id, **kwargs)
102 # Replace endpoint in URL with the one resolved at __init__ time
103 if result and self.endpoint and self.endpoint not in result:
104 return f'{self.endpoint}/models/{model_id}'
105 return result
106
107 def get_model_url(self, model_id: str) -> str:
108 """Return the model page URL ``{endpoint}/{model_id}``."""
109 return f'{self.endpoint}/{model_id}'

Callers 15

__init__Method · 0.90
save_pretrainedMethod · 0.90
list_repo_treeMethod · 0.90
file_existsMethod · 0.90
list_repo_refsMethod · 0.90
_file_existsFunction · 0.90
_file_downloadFunction · 0.90
_whoamiFunction · 0.90
create_repoFunction · 0.90
create_commitFunction · 0.90
loadFunction · 0.90
loadMethod · 0.90

Calls

no outgoing calls

Tested by 15

__init__Method · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
tearDownMethod · 0.72
setUpMethod · 0.72
test_file_existsMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…