Minimal `HfApi` look-alike that forwards to ModelScope. Only the handful of methods that `kernels` actually calls are implemented.
| 553 | |
| 554 | |
| 555 | class _MsKernelApi: |
| 556 | """Minimal `HfApi` look-alike that forwards to ModelScope. Only the |
| 557 | handful of methods that `kernels` actually calls are implemented. |
| 558 | """ |
| 559 | |
| 560 | def snapshot_download(self, |
| 561 | repo_id, |
| 562 | *, |
| 563 | allow_patterns=None, |
| 564 | ignore_patterns=None, |
| 565 | cache_dir=None, |
| 566 | revision=None, |
| 567 | local_files_only=False, |
| 568 | **kwargs): |
| 569 | from modelscope import snapshot_download as ms_snapshot_download |
| 570 | if kwargs.get('repo_type') == 'kernel': |
| 571 | kwargs['repo_type'] = 'model' |
| 572 | return ms_snapshot_download( |
| 573 | repo_id, |
| 574 | revision=_ms_revision(revision), |
| 575 | cache_dir=cache_dir, |
| 576 | local_files_only=local_files_only, |
| 577 | allow_patterns=allow_patterns, |
| 578 | ignore_patterns=ignore_patterns, |
| 579 | **kwargs) |
| 580 | |
| 581 | def list_repo_tree(self, |
| 582 | repo_id, |
| 583 | *, |
| 584 | path_in_repo=None, |
| 585 | revision=None, |
| 586 | **kwargs): |
| 587 | from huggingface_hub.hf_api import RepoFolder |
| 588 | from modelscope.hub.api import HubApi |
| 589 | entries = HubApi().get_model_files( |
| 590 | repo_id, |
| 591 | revision=_ms_revision(revision), |
| 592 | root=path_in_repo, |
| 593 | recursive=False) |
| 594 | folders = [] |
| 595 | for entry in entries: |
| 596 | if entry.get('Type') != 'tree': |
| 597 | continue |
| 598 | path = entry.get('Path') or entry.get('Name') |
| 599 | folders.append(RepoFolder(path=path, oid='', last_commit=None)) |
| 600 | return folders |
| 601 | |
| 602 | def file_exists(self, repo_id, filename, *, revision=None, **kwargs): |
| 603 | from modelscope.hub.api import HubApi |
| 604 | return HubApi().file_exists( |
| 605 | repo_id, filename, revision=_ms_revision(revision)) |
| 606 | |
| 607 | def list_repo_refs(self, repo_id, **kwargs): |
| 608 | from huggingface_hub.hf_api import GitRefInfo |
| 609 | from modelscope.hub.api import HubApi |
| 610 | branches, tags = HubApi().get_model_branches_and_tags(repo_id) |
| 611 | # `target_commit` doubles as the revision in later calls, so reuse |
| 612 | # the branch/tag name (ModelScope accepts it as a revision). |
no outgoing calls
no test coverage detected
searching dependent graphs…