Skip to content

Commit 69cab8f

Browse files
luojun96Jun Luo
andauthored
Add support for skill repository type (#121)
* Add skill repo type support. * update version --------- Co-authored-by: Jun Luo <jun.luo@opencsg.com>
1 parent 1207016 commit 69cab8f

File tree

9 files changed

+51
-14
lines changed

9 files changed

+51
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Open Source: Dive into the source code, contribute, and customize the SDK to fit
2525

2626
The main functions are:
2727

28-
1. Repo downloading(model/dataset)
28+
1. Repo downloading(model/dataset/space/code/mcp/skill
2929
2. Repo information query(Compatible with huggingface)
3030

3131
**XNet Accelerated Transfer (New!)**: Next-generation storage and version control technology for large-scale AI/ML data.

README_cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CSGHub SDK 是一个强大的 Python 客户端,专门设计用于与 CSGHub
2525

2626
主要功能包括:
2727

28-
1. 仓库下载(模型/数据集)
28+
1. 仓库下载(模型/数据集/应用/代码/MCP/技能
2929
2. 仓库信息查询(与huggingface兼容)
3030

3131
**XNet 加速传输(新!)**:面向大规模 AI/ML 数据的下一代存储与版本控制技术。

pycsghub/api_client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22
import logging
3-
from pycsghub.constants import REPO_TYPE_CODE, REPO_TYPE_MCPSERVER
3+
from pycsghub.constants import REPO_TYPE_CODE, REPO_TYPE_MCPSERVER, REPO_TYPE_SKILL
44
from pycsghub.utils import disable_xnet, get_endpoint, get_token_to_send
55
from .api_client import CsghubApi
66
from .api_client_interface import HubApi
@@ -16,7 +16,7 @@ def get_csghub_api(repo_type: Optional[RepoType] = None,
1616
token = get_token_to_send(token)
1717
endpoint = get_endpoint(endpoint=endpoint)
1818

19-
if repo_type in [REPO_TYPE_CODE, REPO_TYPE_MCPSERVER]:
19+
if repo_type in [REPO_TYPE_CODE, REPO_TYPE_MCPSERVER, REPO_TYPE_SKILL]:
2020
logger.debug(f"Use CsghubApi for repo_type {repo_type}")
2121
return CsghubApi(token=token, endpoint=endpoint, user_name=user_name)
2222

pycsghub/cmd/repo_types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from enum import Enum
2-
from pycsghub.constants import REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER
2+
from pycsghub.constants import REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER, REPO_TYPE_SKILL
33

44
class RepoType(str, Enum):
55
MODEL = REPO_TYPE_MODEL
66
DATASET = REPO_TYPE_DATASET
77
SPACE = REPO_TYPE_SPACE
88
CODE = REPO_TYPE_CODE
99
MCP = REPO_TYPE_MCPSERVER
10+
SKILL = REPO_TYPE_SKILL

pycsghub/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
REPO_TYPE_SPACE = "space"
99
REPO_TYPE_CODE = "code"
1010
REPO_TYPE_MCPSERVER = "mcp"
11-
REPO_TYPES = [None, REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER]
11+
REPO_TYPE_SKILL = "skill"
12+
REPO_TYPES = [None, REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER, REPO_TYPE_SKILL]
1213

1314
REPO_SOURCE_CSG = "csg"
1415
REPO_SOURCE_HF = "hf"

pycsghub/test/repo_integration_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def test_from_env_config(self):
9898
elif type_str == "code":
9999
repo_type = RepoType.CODE
100100
filename = f"test_code_{unique_suffix}.txt"
101+
elif type_str == "skill":
102+
repo_type = RepoType.SKILL
103+
filename = f"test_skill_{unique_suffix}.txt"
101104
else:
102105
print(f"Unknown repo type: {type_str}")
103106
continue

pycsghub/upload_large_folder/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Optional, Union, List
88
from pycsghub.cmd.repo_types import RepoType
99
from pycsghub.utils import check_repo_type
10-
from pycsghub.constants import REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER
10+
from pycsghub.constants import REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE, REPO_TYPE_CODE, REPO_TYPE_MCPSERVER, REPO_TYPE_SKILL
1111
from pycsghub.utils import get_endpoint
1212
from .path import filter_repo_objects
1313
from .local_folder import get_local_upload_paths, read_upload_metadata

pycsghub/utils.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
from pycsghub.constants import MODEL_ID_SEPARATOR, DEFAULT_CSG_GROUP, DEFAULT_CSGHUB_DOMAIN
66
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
88
from pycsghub.constants import REPO_SOURCE_CSG, REPO_SOURCE_HF, REPO_SOURCE_MS, REPO_SOURCE_XET
99
import requests
1010
from huggingface_hub.hf_api import ModelInfo, DatasetInfo, SpaceInfo
@@ -17,6 +17,7 @@
1717
import logging
1818
from huggingface_hub.hf_api import ModelInfo as CodeInfo
1919
from huggingface_hub.hf_api import ModelInfo as McpserverInfo
20+
from huggingface_hub.hf_api import ModelInfo as SkillInfo
2021

2122
logger = logging.getLogger(__name__)
2223

@@ -159,9 +160,11 @@ def get_repo_info(
159160
method = code_info
160161
elif repo_type == REPO_TYPE_MCPSERVER:
161162
method = mcpserver_info
163+
elif repo_type == REPO_TYPE_SKILL:
164+
method = skill_info
162165
else:
163166
raise ValueError(f"Unsupported repo type {repo_type}.")
164-
167+
165168
logger.debug(f"get repo info {repo_id} {revision} {repo_type} {token} {endpoint} {source}")
166169

167170
return method(
@@ -428,6 +431,35 @@ def mcpserver_info(
428431
data = r.json()
429432
return McpserverInfo(**data)
430433

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+
431463
def get_repo_meta_path(
432464
repo_type: str,
433465
repo_id: str,
@@ -583,17 +615,17 @@ def print_download_result(res):
583615
print(tabulate(items, headers=columns))
584616

585617
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}")
588620

589621
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]:
591623
return f"{repo_type}s"
592624
else:
593625
return f"{REPO_TYPE_MODEL}s"
594626

595627
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]:
597629
return f"{repo_type}s"
598630
elif repo_type in [REPO_TYPE_MCPSERVER]:
599631
return f"mcpservers"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "csghub-sdk"
7-
version = "0.8.3"
7+
version = "0.8.4"
88
description = "CSGHub SDK for downloading and uploading models, datasets, and spaces"
99
readme = "README.md"
1010
license = { text = "Apache-2.0" }

0 commit comments

Comments
 (0)