|
4 | 4 | import os |
5 | 5 | from pycsghub.constants import MODEL_ID_SEPARATOR, DEFAULT_CSG_GROUP, DEFAULT_CSGHUB_DOMAIN |
6 | 6 | from pycsghub.constants import OPERATION_ACTION_API, OPERATION_ACTION_GIT, XNET_API_PATH |
7 | | -from pycsghub.constants import REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER |
| 7 | +from pycsghub.constants import REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER, REPO_TYPE_SKILL |
8 | 8 | from pycsghub.constants import REPO_SOURCE_CSG, REPO_SOURCE_HF, REPO_SOURCE_MS, REPO_SOURCE_XET |
9 | 9 | import requests |
10 | 10 | from huggingface_hub.hf_api import ModelInfo, DatasetInfo, SpaceInfo |
|
17 | 17 | import logging |
18 | 18 | from huggingface_hub.hf_api import ModelInfo as CodeInfo |
19 | 19 | from huggingface_hub.hf_api import ModelInfo as McpserverInfo |
| 20 | +from huggingface_hub.hf_api import ModelInfo as SkillInfo |
20 | 21 |
|
21 | 22 | logger = logging.getLogger(__name__) |
22 | 23 |
|
@@ -159,9 +160,11 @@ def get_repo_info( |
159 | 160 | method = code_info |
160 | 161 | elif repo_type == REPO_TYPE_MCPSERVER: |
161 | 162 | method = mcpserver_info |
| 163 | + elif repo_type == REPO_TYPE_SKILL: |
| 164 | + method = skill_info |
162 | 165 | else: |
163 | 166 | raise ValueError(f"Unsupported repo type {repo_type}.") |
164 | | - |
| 167 | + |
165 | 168 | logger.debug(f"get repo info {repo_id} {revision} {repo_type} {token} {endpoint} {source}") |
166 | 169 |
|
167 | 170 | return method( |
@@ -428,6 +431,35 @@ def mcpserver_info( |
428 | 431 | data = r.json() |
429 | 432 | return McpserverInfo(**data) |
430 | 433 |
|
| 434 | +def skill_info( |
| 435 | + repo_id: str, |
| 436 | + *, |
| 437 | + revision: Optional[str] = None, |
| 438 | + timeout: Optional[float] = None, |
| 439 | + securityStatus: Optional[bool] = None, |
| 440 | + files_metadata: bool = False, |
| 441 | + token: Union[bool, str, None] = None, |
| 442 | + endpoint: Optional[str] = None, |
| 443 | + source: Optional[str] = None, |
| 444 | +) -> SkillInfo: |
| 445 | + headers = build_csg_headers(token=token) |
| 446 | + path = get_repo_meta_path(repo_type=REPO_TYPE_SKILL, |
| 447 | + repo_id=repo_id, |
| 448 | + revision=revision, |
| 449 | + endpoint=endpoint, |
| 450 | + source=source) |
| 451 | + params = {} |
| 452 | + if securityStatus: |
| 453 | + params["securityStatus"] = True |
| 454 | + if files_metadata: |
| 455 | + params["blobs"] = True |
| 456 | + r = requests.get(path, headers=headers, timeout=timeout, params=params) |
| 457 | + if r.status_code != 200: |
| 458 | + logger.error(f"get skill meta info from {path} response: {r.text}") |
| 459 | + r.raise_for_status() |
| 460 | + data = r.json() |
| 461 | + return SkillInfo(**data) |
| 462 | + |
431 | 463 | def get_repo_meta_path( |
432 | 464 | repo_type: str, |
433 | 465 | repo_id: str, |
@@ -583,17 +615,17 @@ def print_download_result(res): |
583 | 615 | print(tabulate(items, headers=columns)) |
584 | 616 |
|
585 | 617 | def check_repo_type(repo_type: str): |
586 | | - if repo_type not in [REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER]: |
587 | | - raise ValueError(f"invalid repo type, must be one of {REPO_TYPE_MODEL} or {REPO_TYPE_DATASET} or {REPO_TYPE_SPACE} or {REPO_TYPE_CODE} or {REPO_TYPE_MCPSERVER}") |
| 618 | + if repo_type not in [REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER, REPO_TYPE_SKILL]: |
| 619 | + raise ValueError(f"invalid repo type, must be one of {REPO_TYPE_MODEL} or {REPO_TYPE_DATASET} or {REPO_TYPE_SPACE} or {REPO_TYPE_CODE} or {REPO_TYPE_MCPSERVER} or {REPO_TYPE_SKILL}") |
588 | 620 |
|
589 | 621 | def get_repo_url_prefix(repo_type: Optional[str] = None): |
590 | | - if repo_type in [REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER]: |
| 622 | + if repo_type in [REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER, REPO_TYPE_SKILL]: |
591 | 623 | return f"{repo_type}s" |
592 | 624 | else: |
593 | 625 | return f"{REPO_TYPE_MODEL}s" |
594 | 626 |
|
595 | 627 | def get_repo_git_prefix(repo_type: Optional[str] = None): |
596 | | - if repo_type in [REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE]: |
| 628 | + if repo_type in [REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_SKILL]: |
597 | 629 | return f"{repo_type}s" |
598 | 630 | elif repo_type in [REPO_TYPE_MCPSERVER]: |
599 | 631 | return f"mcpservers" |
|
0 commit comments