modelhub-xc 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- modelhub_xc-1.0.0/LICENSE +15 -0
- modelhub_xc-1.0.0/PKG-INFO +274 -0
- modelhub_xc-1.0.0/README.md +233 -0
- modelhub_xc-1.0.0/modelhub_xc/__init__.py +10 -0
- modelhub_xc-1.0.0/modelhub_xc/api.py +70 -0
- modelhub_xc-1.0.0/modelhub_xc/api_client.py +55 -0
- modelhub_xc-1.0.0/modelhub_xc/cli.py +98 -0
- modelhub_xc-1.0.0/modelhub_xc/downloader.py +95 -0
- modelhub_xc-1.0.0/modelhub_xc/gitea_client.py +181 -0
- modelhub_xc-1.0.0/modelhub_xc.egg-info/PKG-INFO +274 -0
- modelhub_xc-1.0.0/modelhub_xc.egg-info/SOURCES.txt +16 -0
- modelhub_xc-1.0.0/modelhub_xc.egg-info/dependency_links.txt +1 -0
- modelhub_xc-1.0.0/modelhub_xc.egg-info/entry_points.txt +2 -0
- modelhub_xc-1.0.0/modelhub_xc.egg-info/requires.txt +1 -0
- modelhub_xc-1.0.0/modelhub_xc.egg-info/top_level.txt +1 -0
- modelhub_xc-1.0.0/setup.cfg +4 -0
- modelhub_xc-1.0.0/setup.py +56 -0
- modelhub_xc-1.0.0/tests/test_modelhub.py +132 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ModelHub XC Team
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: modelhub-xc
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: ModelHub XC Community SDK - Python library for downloading models
|
|
5
|
+
Home-page: https://modelhub.org.cn
|
|
6
|
+
Author: ModelHub XC Team
|
|
7
|
+
Author-email: noreply@modelhub-xc.org.cn
|
|
8
|
+
License: Apache License 2.0
|
|
9
|
+
Keywords: modelhub-xc,model,download,xc,ai
|
|
10
|
+
Platform: any
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Requires-Python: >=3.6
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: requests>=2.25.0
|
|
28
|
+
Dynamic: author
|
|
29
|
+
Dynamic: author-email
|
|
30
|
+
Dynamic: classifier
|
|
31
|
+
Dynamic: description
|
|
32
|
+
Dynamic: description-content-type
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: keywords
|
|
35
|
+
Dynamic: license
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
Dynamic: platform
|
|
38
|
+
Dynamic: requires-dist
|
|
39
|
+
Dynamic: requires-python
|
|
40
|
+
Dynamic: summary
|
|
41
|
+
|
|
42
|
+
[# ModelHub - XC社区模型下载SDK
|
|
43
|
+
|
|
44
|
+
ModelHub是一个用于从XC社区下载模型的Python SDK工具。它提供了简单易用的命令行工具和Python API接口,帮助用户快速下载和管理AI模型。
|
|
45
|
+
|
|
46
|
+
## 功能特点
|
|
47
|
+
|
|
48
|
+
- 🚀 简单易用的命令行工具
|
|
49
|
+
- 📦 完整的Python SDK支持
|
|
50
|
+
- 🔄 支持下载完整模型库或单个文件
|
|
51
|
+
- 📁 自动管理本地缓存
|
|
52
|
+
- 🌐 直接对接XC社区API和Gitea仓库
|
|
53
|
+
|
|
54
|
+
## 安装
|
|
55
|
+
|
|
56
|
+
使用pip安装:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install modelhub-xc
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 使用方法
|
|
63
|
+
|
|
64
|
+
### 命令行下载
|
|
65
|
+
|
|
66
|
+
#### 1. 下载完整模型库
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
modelhub-xc download --model mlx-community/Qwen3-8B-bf16
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### 2. 下载单个文件到指定本地文件夹
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# 下载README.md到当前路径下"dir"目录
|
|
76
|
+
modelhub-xc download --model mlx-community/Qwen3-8B-bf16 README.md --local_dir ./dir
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### 3. 指定分支下载
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
modelhub-xc download --model mlx-community/Qwen3-8B-bf16 --branch main
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### SDK下载
|
|
86
|
+
|
|
87
|
+
#### 1. 下载完整模型
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from modelhub_xc import snapshot_download
|
|
91
|
+
|
|
92
|
+
# 下载完整模型库
|
|
93
|
+
model_dir = snapshot_download('mlx-community/Qwen3-8B-bf16')
|
|
94
|
+
print(f"模型已下载到: {model_dir}")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### 2. 指定保存目录
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from modelhub_xc import snapshot_download
|
|
101
|
+
|
|
102
|
+
# 下载到指定目录
|
|
103
|
+
model_dir = snapshot_download(
|
|
104
|
+
'mlx-community/Qwen3-8B-bf16',
|
|
105
|
+
local_dir='./my_models'
|
|
106
|
+
)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### 3. 下载单个文件
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from modelhub_xc import download_file
|
|
113
|
+
|
|
114
|
+
# 下载单个文件
|
|
115
|
+
model_dir = download_file(
|
|
116
|
+
'mlx-community/Qwen3-8B-bf16',
|
|
117
|
+
'README.md',
|
|
118
|
+
local_dir='./dir'
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## API参考
|
|
123
|
+
|
|
124
|
+
### snapshot_download
|
|
125
|
+
|
|
126
|
+
下载完整的模型快照。
|
|
127
|
+
|
|
128
|
+
**参数:**
|
|
129
|
+
- `model_id` (str): 模型ID,例如 'mlx-community/Qwen3-8B-bf16'
|
|
130
|
+
- `local_dir` (str, 可选): 本地保存目录,默认为 `~/.cache/modelhub/models/{model_id}`
|
|
131
|
+
- `branch` (str, 可选): 分支名,默认为 'main'
|
|
132
|
+
- `api_base_url` (str, 可选): API基础URL,默认为 'https://modelhub.org.cn/api'
|
|
133
|
+
|
|
134
|
+
**返回:**
|
|
135
|
+
- `str`: 下载后的本地目录路径
|
|
136
|
+
|
|
137
|
+
### download_file
|
|
138
|
+
|
|
139
|
+
下载模型中的单个文件。
|
|
140
|
+
|
|
141
|
+
**参数:**
|
|
142
|
+
- `model_id` (str): 模型ID
|
|
143
|
+
- `filename` (str): 要下载的文件名或路径
|
|
144
|
+
- `local_dir` (str, 可选): 本地保存目录,默认为当前目录
|
|
145
|
+
- `branch` (str, 可选): 分支名,默认为 'main'
|
|
146
|
+
- `api_base_url` (str, 可选): API基础URL
|
|
147
|
+
|
|
148
|
+
**返回:**
|
|
149
|
+
- `str`: 下载后的本地目录路径
|
|
150
|
+
|
|
151
|
+
## 项目结构
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
modelhub/
|
|
155
|
+
├── modelhub_xc/
|
|
156
|
+
│ ├── __init__.py # 包初始化
|
|
157
|
+
│ ├── api.py # 公共API接口
|
|
158
|
+
│ ├── api_client.py # ModelHub API客户端
|
|
159
|
+
│ ├── gitea_client.py # Gitea仓库客户端
|
|
160
|
+
│ ├── downloader.py # 模型下载器
|
|
161
|
+
│ └── cli.py # 命令行工具
|
|
162
|
+
├── tests/ # 测试文件
|
|
163
|
+
├── setup.py # 安装配置
|
|
164
|
+
├── publish.sh # PyPI发布脚本
|
|
165
|
+
├── .pypirc.example # PyPI配置示例
|
|
166
|
+
└── README.md # 项目文档
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## 工作原理
|
|
170
|
+
|
|
171
|
+
1. **查询模型信息**:通过ModelHub API查询模型的基本信息和Gitea仓库地址
|
|
172
|
+
2. **获取文件列表**:通过Gitea API获取模型仓库中的文件列表
|
|
173
|
+
3. **下载文件**:使用Gitea的下载接口下载模型文件到本地
|
|
174
|
+
|
|
175
|
+
## 开发指南
|
|
176
|
+
|
|
177
|
+
### 安装开发依赖
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
pip install -e .
|
|
181
|
+
pip install wheel twine
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 运行测试
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
python -m pytest tests/
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### 构建和发布
|
|
191
|
+
|
|
192
|
+
1. 构建包:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
python setup.py sdist bdist_wheel
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
2. 上传到PyPI:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# 配置.pypirc文件(参考.pypirc.example)
|
|
202
|
+
twine upload dist/*
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
或者使用发布脚本:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
./publish.sh
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 配置PyPI上传
|
|
212
|
+
|
|
213
|
+
1. 复制配置文件示例:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
cp .pypirc ~/.pypirc
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
2. 编辑 `~/.pypirc` 文件,填入你的PyPI token:
|
|
220
|
+
|
|
221
|
+
```ini
|
|
222
|
+
[distutils]
|
|
223
|
+
index-servers =
|
|
224
|
+
pypi
|
|
225
|
+
|
|
226
|
+
[pypi]
|
|
227
|
+
repository = https://upload.pypi.org/legacy/
|
|
228
|
+
username = __token__
|
|
229
|
+
password = pypi-your-token-here
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## 技术栈
|
|
233
|
+
|
|
234
|
+
- Python 3.6+
|
|
235
|
+
- requests: HTTP客户端
|
|
236
|
+
- setuptools: 包管理
|
|
237
|
+
|
|
238
|
+
## 常见问题
|
|
239
|
+
|
|
240
|
+
### 1. 下载速度慢?
|
|
241
|
+
|
|
242
|
+
模型文件通常较大,下载速度取决于网络连接。建议使用稳定的网络环境。
|
|
243
|
+
|
|
244
|
+
### 2. 下载中断如何处理?
|
|
245
|
+
|
|
246
|
+
目前不支持断点续传,如果下载中断,需要重新开始下载。
|
|
247
|
+
|
|
248
|
+
### 3. 如何查看可用的模型?
|
|
249
|
+
|
|
250
|
+
访问 [https://modelhub.org.cn](https://modelhub.org.cn) 浏览可用的模型列表。
|
|
251
|
+
|
|
252
|
+
## 许可证
|
|
253
|
+
|
|
254
|
+
Apache License 2.0
|
|
255
|
+
|
|
256
|
+
## 贡献
|
|
257
|
+
|
|
258
|
+
欢迎提交Issue和Pull Request!
|
|
259
|
+
|
|
260
|
+
## 联系方式
|
|
261
|
+
|
|
262
|
+
- 官网:https://modelhub.org.cn
|
|
263
|
+
- 邮箱:noreply@modelhub.org.cn
|
|
264
|
+
|
|
265
|
+
## 更新日志
|
|
266
|
+
|
|
267
|
+
### v1.0.0 (2026-04-09)
|
|
268
|
+
|
|
269
|
+
- 初始版本发布
|
|
270
|
+
- 支持命令行下载
|
|
271
|
+
- 支持SDK接口
|
|
272
|
+
- 支持下载完整模型和单个文件
|
|
273
|
+
- 集成XC社区API和Gitea仓库
|
|
274
|
+
]()
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
[# ModelHub - XC社区模型下载SDK
|
|
2
|
+
|
|
3
|
+
ModelHub是一个用于从XC社区下载模型的Python SDK工具。它提供了简单易用的命令行工具和Python API接口,帮助用户快速下载和管理AI模型。
|
|
4
|
+
|
|
5
|
+
## 功能特点
|
|
6
|
+
|
|
7
|
+
- 🚀 简单易用的命令行工具
|
|
8
|
+
- 📦 完整的Python SDK支持
|
|
9
|
+
- 🔄 支持下载完整模型库或单个文件
|
|
10
|
+
- 📁 自动管理本地缓存
|
|
11
|
+
- 🌐 直接对接XC社区API和Gitea仓库
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
使用pip安装:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install modelhub-xc
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 使用方法
|
|
22
|
+
|
|
23
|
+
### 命令行下载
|
|
24
|
+
|
|
25
|
+
#### 1. 下载完整模型库
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
modelhub-xc download --model mlx-community/Qwen3-8B-bf16
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### 2. 下载单个文件到指定本地文件夹
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# 下载README.md到当前路径下"dir"目录
|
|
35
|
+
modelhub-xc download --model mlx-community/Qwen3-8B-bf16 README.md --local_dir ./dir
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### 3. 指定分支下载
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
modelhub-xc download --model mlx-community/Qwen3-8B-bf16 --branch main
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### SDK下载
|
|
45
|
+
|
|
46
|
+
#### 1. 下载完整模型
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from modelhub_xc import snapshot_download
|
|
50
|
+
|
|
51
|
+
# 下载完整模型库
|
|
52
|
+
model_dir = snapshot_download('mlx-community/Qwen3-8B-bf16')
|
|
53
|
+
print(f"模型已下载到: {model_dir}")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### 2. 指定保存目录
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from modelhub_xc import snapshot_download
|
|
60
|
+
|
|
61
|
+
# 下载到指定目录
|
|
62
|
+
model_dir = snapshot_download(
|
|
63
|
+
'mlx-community/Qwen3-8B-bf16',
|
|
64
|
+
local_dir='./my_models'
|
|
65
|
+
)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### 3. 下载单个文件
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from modelhub_xc import download_file
|
|
72
|
+
|
|
73
|
+
# 下载单个文件
|
|
74
|
+
model_dir = download_file(
|
|
75
|
+
'mlx-community/Qwen3-8B-bf16',
|
|
76
|
+
'README.md',
|
|
77
|
+
local_dir='./dir'
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## API参考
|
|
82
|
+
|
|
83
|
+
### snapshot_download
|
|
84
|
+
|
|
85
|
+
下载完整的模型快照。
|
|
86
|
+
|
|
87
|
+
**参数:**
|
|
88
|
+
- `model_id` (str): 模型ID,例如 'mlx-community/Qwen3-8B-bf16'
|
|
89
|
+
- `local_dir` (str, 可选): 本地保存目录,默认为 `~/.cache/modelhub/models/{model_id}`
|
|
90
|
+
- `branch` (str, 可选): 分支名,默认为 'main'
|
|
91
|
+
- `api_base_url` (str, 可选): API基础URL,默认为 'https://modelhub.org.cn/api'
|
|
92
|
+
|
|
93
|
+
**返回:**
|
|
94
|
+
- `str`: 下载后的本地目录路径
|
|
95
|
+
|
|
96
|
+
### download_file
|
|
97
|
+
|
|
98
|
+
下载模型中的单个文件。
|
|
99
|
+
|
|
100
|
+
**参数:**
|
|
101
|
+
- `model_id` (str): 模型ID
|
|
102
|
+
- `filename` (str): 要下载的文件名或路径
|
|
103
|
+
- `local_dir` (str, 可选): 本地保存目录,默认为当前目录
|
|
104
|
+
- `branch` (str, 可选): 分支名,默认为 'main'
|
|
105
|
+
- `api_base_url` (str, 可选): API基础URL
|
|
106
|
+
|
|
107
|
+
**返回:**
|
|
108
|
+
- `str`: 下载后的本地目录路径
|
|
109
|
+
|
|
110
|
+
## 项目结构
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
modelhub/
|
|
114
|
+
├── modelhub_xc/
|
|
115
|
+
│ ├── __init__.py # 包初始化
|
|
116
|
+
│ ├── api.py # 公共API接口
|
|
117
|
+
│ ├── api_client.py # ModelHub API客户端
|
|
118
|
+
│ ├── gitea_client.py # Gitea仓库客户端
|
|
119
|
+
│ ├── downloader.py # 模型下载器
|
|
120
|
+
│ └── cli.py # 命令行工具
|
|
121
|
+
├── tests/ # 测试文件
|
|
122
|
+
├── setup.py # 安装配置
|
|
123
|
+
├── publish.sh # PyPI发布脚本
|
|
124
|
+
├── .pypirc.example # PyPI配置示例
|
|
125
|
+
└── README.md # 项目文档
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## 工作原理
|
|
129
|
+
|
|
130
|
+
1. **查询模型信息**:通过ModelHub API查询模型的基本信息和Gitea仓库地址
|
|
131
|
+
2. **获取文件列表**:通过Gitea API获取模型仓库中的文件列表
|
|
132
|
+
3. **下载文件**:使用Gitea的下载接口下载模型文件到本地
|
|
133
|
+
|
|
134
|
+
## 开发指南
|
|
135
|
+
|
|
136
|
+
### 安装开发依赖
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pip install -e .
|
|
140
|
+
pip install wheel twine
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 运行测试
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
python -m pytest tests/
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 构建和发布
|
|
150
|
+
|
|
151
|
+
1. 构建包:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
python setup.py sdist bdist_wheel
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
2. 上传到PyPI:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# 配置.pypirc文件(参考.pypirc.example)
|
|
161
|
+
twine upload dist/*
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
或者使用发布脚本:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
./publish.sh
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 配置PyPI上传
|
|
171
|
+
|
|
172
|
+
1. 复制配置文件示例:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
cp .pypirc ~/.pypirc
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
2. 编辑 `~/.pypirc` 文件,填入你的PyPI token:
|
|
179
|
+
|
|
180
|
+
```ini
|
|
181
|
+
[distutils]
|
|
182
|
+
index-servers =
|
|
183
|
+
pypi
|
|
184
|
+
|
|
185
|
+
[pypi]
|
|
186
|
+
repository = https://upload.pypi.org/legacy/
|
|
187
|
+
username = __token__
|
|
188
|
+
password = pypi-your-token-here
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## 技术栈
|
|
192
|
+
|
|
193
|
+
- Python 3.6+
|
|
194
|
+
- requests: HTTP客户端
|
|
195
|
+
- setuptools: 包管理
|
|
196
|
+
|
|
197
|
+
## 常见问题
|
|
198
|
+
|
|
199
|
+
### 1. 下载速度慢?
|
|
200
|
+
|
|
201
|
+
模型文件通常较大,下载速度取决于网络连接。建议使用稳定的网络环境。
|
|
202
|
+
|
|
203
|
+
### 2. 下载中断如何处理?
|
|
204
|
+
|
|
205
|
+
目前不支持断点续传,如果下载中断,需要重新开始下载。
|
|
206
|
+
|
|
207
|
+
### 3. 如何查看可用的模型?
|
|
208
|
+
|
|
209
|
+
访问 [https://modelhub.org.cn](https://modelhub.org.cn) 浏览可用的模型列表。
|
|
210
|
+
|
|
211
|
+
## 许可证
|
|
212
|
+
|
|
213
|
+
Apache License 2.0
|
|
214
|
+
|
|
215
|
+
## 贡献
|
|
216
|
+
|
|
217
|
+
欢迎提交Issue和Pull Request!
|
|
218
|
+
|
|
219
|
+
## 联系方式
|
|
220
|
+
|
|
221
|
+
- 官网:https://modelhub.org.cn
|
|
222
|
+
- 邮箱:noreply@modelhub.org.cn
|
|
223
|
+
|
|
224
|
+
## 更新日志
|
|
225
|
+
|
|
226
|
+
### v1.0.0 (2026-04-09)
|
|
227
|
+
|
|
228
|
+
- 初始版本发布
|
|
229
|
+
- 支持命令行下载
|
|
230
|
+
- 支持SDK接口
|
|
231
|
+
- 支持下载完整模型和单个文件
|
|
232
|
+
- 集成XC社区API和Gitea仓库
|
|
233
|
+
]()
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Public API for ModelHub SDK
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Optional, List
|
|
6
|
+
from .downloader import ModelDownloader
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def snapshot_download(
|
|
10
|
+
model_id: str,
|
|
11
|
+
local_dir: Optional[str] = None,
|
|
12
|
+
branch: str = "main",
|
|
13
|
+
api_base_url: str = "https://modelhub.org.cn/api"
|
|
14
|
+
) -> str:
|
|
15
|
+
"""
|
|
16
|
+
下载完整的模型快照
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
model_id: 模型ID,例如 'mlx-community/Qwen3-8B-bf16'
|
|
20
|
+
local_dir: 本地保存目录,如果为None则使用默认目录 ~/.cache/modelhub-xc/models/{model_id}
|
|
21
|
+
branch: 分支名,默认为 'main'
|
|
22
|
+
api_base_url: API基础URL,默认为 'https://modelhub.org.cn/api'
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
下载后的本地目录路径
|
|
26
|
+
|
|
27
|
+
Example:
|
|
28
|
+
>>> from modelhub-xc import snapshot_download
|
|
29
|
+
>>> model_dir = snapshot_download('mlx-community/Qwen3-8B-bf16')
|
|
30
|
+
>>> print(f"模型已下载到: {model_dir}")
|
|
31
|
+
"""
|
|
32
|
+
downloader = ModelDownloader(api_base_url)
|
|
33
|
+
return downloader.download_model(model_id, local_dir=local_dir, branch=branch)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def download_file(
|
|
37
|
+
model_id: str,
|
|
38
|
+
filename: str,
|
|
39
|
+
local_dir: Optional[str] = None,
|
|
40
|
+
branch: str = "main",
|
|
41
|
+
api_base_url: str = "https://modelhub.org.cn/api"
|
|
42
|
+
) -> str:
|
|
43
|
+
"""
|
|
44
|
+
下载模型中的单个文件
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
model_id: 模型ID,例如 'mlx-community/Qwen3-8B-bf16'
|
|
48
|
+
filename: 要下载的文件名或路径,例如 'README.md'
|
|
49
|
+
local_dir: 本地保存目录,如果为None则使用当前目录
|
|
50
|
+
branch: 分支名,默认为 'main'
|
|
51
|
+
api_base_url: API基础URL
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
下载后的本地目录路径
|
|
55
|
+
|
|
56
|
+
Example:
|
|
57
|
+
>>> from modelhub-xc import download_file
|
|
58
|
+
>>> model_dir = download_file('mlx-community/Qwen3-8B-bf16', 'README.md', local_dir='./dir')
|
|
59
|
+
"""
|
|
60
|
+
downloader = ModelDownloader(api_base_url)
|
|
61
|
+
|
|
62
|
+
if local_dir is None:
|
|
63
|
+
local_dir = '.'
|
|
64
|
+
|
|
65
|
+
return downloader.download_model(
|
|
66
|
+
model_id,
|
|
67
|
+
local_dir=local_dir,
|
|
68
|
+
files=[filename],
|
|
69
|
+
branch=branch
|
|
70
|
+
)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ModelHub API Client
|
|
3
|
+
Handles API requests to modelhub-xc.org.cn
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
from typing import Dict, Any, Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ModelHubAPIClient:
|
|
11
|
+
"""ModelHub API客户端"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, api_base_url: str = "https://modelhub.org.cn/api"):
|
|
14
|
+
self.api_base_url = api_base_url.rstrip('/')
|
|
15
|
+
|
|
16
|
+
def get_model_info(self, model_id: str) -> Dict[str, Any]:
|
|
17
|
+
"""
|
|
18
|
+
通过modelId查询模型信息
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
model_id: 模型ID,例如 'mlx-community/Qwen3-8B-bf16'
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
模型信息字典
|
|
25
|
+
|
|
26
|
+
Raises:
|
|
27
|
+
Exception: 当API请求失败时
|
|
28
|
+
"""
|
|
29
|
+
url = f"{self.api_base_url}/computility/models/getByModelId/vo"
|
|
30
|
+
params = {'modelId': model_id}
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
response = requests.get(url, params=params, timeout=30)
|
|
34
|
+
response.raise_for_status()
|
|
35
|
+
|
|
36
|
+
data = response.json()
|
|
37
|
+
if data.get('code') != 0:
|
|
38
|
+
raise Exception(f"API返回错误: {data.get('message', 'Unknown error')}")
|
|
39
|
+
|
|
40
|
+
return data.get('data', {})
|
|
41
|
+
except requests.RequestException as e:
|
|
42
|
+
raise Exception(f"查询模型信息失败: {str(e)}")
|
|
43
|
+
|
|
44
|
+
def get_gitea_url(self, model_id: str) -> Optional[str]:
|
|
45
|
+
"""
|
|
46
|
+
获取模型的Gitea URL
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
model_id: 模型ID
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
Gitea URL或None
|
|
53
|
+
"""
|
|
54
|
+
model_info = self.get_model_info(model_id)
|
|
55
|
+
return model_info.get('giteaUrl')
|