@syncshio/kano-plugin-huggingface 0.0.0-stage → 2.0.0
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.
Potentially problematic release.
This version of @syncshio/kano-plugin-huggingface might be problematic. Click here for more details.
- package/dist/entry.js +159 -0
- package/kano-release.json +5 -0
- package/package.json +25 -4
- package/plugin.json +24 -0
- package/README.md +0 -3
package/dist/entry.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
//#region ../kano-plugin-sdk/src/helpers/define-plugin.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e;
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region packages/plugins/huggingface/provider.ts
|
|
7
|
+
function t(e) {
|
|
8
|
+
if (!e || typeof e != "object" || !("id" in e) || typeof e.id != "string" || !/^[\w.-]+(?:\/[\w.-]+)?$/.test(e.id) || e.id.split("/").some((e) => e === "." || e === "..")) throw Error("Hugging Face 返回了无效的仓库标识");
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
function n(e) {
|
|
12
|
+
if (!e || e.includes("\\") || e.split("/").some((e) => !e || e === "." || e === "..")) throw Error("模型仓库文件路径无效");
|
|
13
|
+
return e.split("/").map(encodeURIComponent).join("/");
|
|
14
|
+
}
|
|
15
|
+
function r(e, t) {
|
|
16
|
+
let r = Array.isArray(e.tags) ? e.tags.filter((e) => typeof e == "string") : [], i = e.cardData?.base_model, a = r.includes("lora") || e.library_name === "peft" ? "lora" : e.library_name === "diffusers" || [
|
|
17
|
+
"text-to-image",
|
|
18
|
+
"image-to-image",
|
|
19
|
+
"text-to-video",
|
|
20
|
+
"image-to-video"
|
|
21
|
+
].includes(e.pipeline_tag || "") ? "checkpoint" : r.includes("gguf") || [
|
|
22
|
+
"text-generation",
|
|
23
|
+
"image-text-to-text",
|
|
24
|
+
"text2text-generation"
|
|
25
|
+
].includes(e.pipeline_tag || "") ? "llm" : "other";
|
|
26
|
+
return {
|
|
27
|
+
id: e.id,
|
|
28
|
+
name: e.id.split("/").at(-1),
|
|
29
|
+
author: e.author || (e.id.includes("/") ? e.id.split("/")[0] : ""),
|
|
30
|
+
type: a,
|
|
31
|
+
baseModel: Array.isArray(i) ? i.join(", ") : i || "",
|
|
32
|
+
tags: r,
|
|
33
|
+
thumbnails: [],
|
|
34
|
+
downloadCount: e.downloads || 0,
|
|
35
|
+
rating: 0,
|
|
36
|
+
updatedAt: e.lastModified || "",
|
|
37
|
+
pageUrl: t + "/" + n(e.id)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function i(e, i, a) {
|
|
41
|
+
async function o(e, i, o) {
|
|
42
|
+
let s = t({ id: e });
|
|
43
|
+
if (o && !/^[\da-f]{40,64}$/i.test(o)) throw Error("模型修订版本无效");
|
|
44
|
+
let c = a + "/api/models/" + n(s.id) + (o ? "/revision/" + o : "") + "?blobs=true", l = t(await i.http.getJson(c));
|
|
45
|
+
if (l.id !== e || !l.sha || !/^[\da-f]{40,64}$/i.test(l.sha) || o && l.sha !== o) throw Error("仓库版本已变更,请刷新详情");
|
|
46
|
+
let u = r(l, a), d = (l.siblings || []).filter((e) => typeof e.rfilename == "string" && /\.(gguf|safetensors)$/i.test(e.rfilename)).map((e) => (n(e.rfilename), {
|
|
47
|
+
id: e.rfilename,
|
|
48
|
+
name: e.rfilename,
|
|
49
|
+
format: /\.gguf$/i.test(e.rfilename) ? "GGUF" : "Safetensors",
|
|
50
|
+
size: e.lfs?.size || e.size || 0,
|
|
51
|
+
sha256: e.lfs?.sha256,
|
|
52
|
+
downloadable: !0
|
|
53
|
+
}));
|
|
54
|
+
return {
|
|
55
|
+
...u,
|
|
56
|
+
description: l.cardData?.model_description || "",
|
|
57
|
+
createdAt: l.createdAt || "",
|
|
58
|
+
versions: [{
|
|
59
|
+
id: l.sha,
|
|
60
|
+
name: l.sha.slice(0, 12),
|
|
61
|
+
baseModel: u.baseModel,
|
|
62
|
+
files: d,
|
|
63
|
+
createdAt: u.updatedAt
|
|
64
|
+
}]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
id: e,
|
|
69
|
+
name: i,
|
|
70
|
+
homepage: a,
|
|
71
|
+
apiOrigins: [a],
|
|
72
|
+
capabilities: {
|
|
73
|
+
types: [
|
|
74
|
+
"llm",
|
|
75
|
+
"checkpoint",
|
|
76
|
+
"lora",
|
|
77
|
+
"other"
|
|
78
|
+
],
|
|
79
|
+
baseModels: [],
|
|
80
|
+
searchBy: [
|
|
81
|
+
"name",
|
|
82
|
+
"author",
|
|
83
|
+
"tag"
|
|
84
|
+
],
|
|
85
|
+
sorts: [
|
|
86
|
+
{
|
|
87
|
+
label: "下载最多",
|
|
88
|
+
value: "downloads"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
label: "最近更新",
|
|
92
|
+
value: "lastModified"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
label: "点赞最多",
|
|
96
|
+
value: "likes"
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
apiKey: {
|
|
100
|
+
label: i + " Token",
|
|
101
|
+
helpUrl: "https://huggingface.co/settings/tokens"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
async search(e, n) {
|
|
105
|
+
let i = new URL(a + "/api/models");
|
|
106
|
+
i.searchParams.set("limit", String(Math.min(100, Math.max(1, e.limit)))), i.searchParams.set("sort", [
|
|
107
|
+
"downloads",
|
|
108
|
+
"lastModified",
|
|
109
|
+
"likes"
|
|
110
|
+
].includes(e.sort) ? e.sort : "downloads"), i.searchParams.set("direction", "-1");
|
|
111
|
+
for (let e of [
|
|
112
|
+
"author",
|
|
113
|
+
"downloads",
|
|
114
|
+
"lastModified",
|
|
115
|
+
"library_name",
|
|
116
|
+
"pipeline_tag",
|
|
117
|
+
"tags"
|
|
118
|
+
]) i.searchParams.append("expand", e);
|
|
119
|
+
e.cursor && i.searchParams.set("cursor", e.cursor), e.search.trim() && i.searchParams.set({
|
|
120
|
+
name: "search",
|
|
121
|
+
author: "author",
|
|
122
|
+
tag: "filter"
|
|
123
|
+
}[e.searchBy], e.search.trim());
|
|
124
|
+
let o = n.http.getJsonPage ? await n.http.getJsonPage(i.href) : {
|
|
125
|
+
data: await n.http.getJson(i.href),
|
|
126
|
+
next: void 0
|
|
127
|
+
};
|
|
128
|
+
if (!Array.isArray(o.data)) throw Error("Hugging Face 返回了无效的模型列表");
|
|
129
|
+
let s = o.data.map((e) => r(t(e), a)).filter((t) => !e.types.length || e.types.includes(t.type)), c;
|
|
130
|
+
if (o.next) {
|
|
131
|
+
let e = new URL(o.next, i);
|
|
132
|
+
e.origin === a && e.pathname === i.pathname && (c = e.searchParams.get("cursor") || void 0);
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
items: s,
|
|
136
|
+
nextCursor: c
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
getDetail: o,
|
|
140
|
+
async resolveDownload({ modelId: e, versionId: t, fileId: r }, i) {
|
|
141
|
+
let s = (await o(e, i, t)).versions[0].files.find((e) => e.id === r);
|
|
142
|
+
if (!s) throw Error("当前版本没有此文件,请刷新模型详情");
|
|
143
|
+
let c = a + "/" + n(e) + "/resolve/" + t + "/" + n(s.id) + "?download=true";
|
|
144
|
+
return {
|
|
145
|
+
url: await i.http.resolveDownload(c),
|
|
146
|
+
filename: s.name.split("/").at(-1),
|
|
147
|
+
size: s.size
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region packages/plugins/huggingface/index.ts
|
|
154
|
+
var a = e({
|
|
155
|
+
id: "huggingface",
|
|
156
|
+
modelMarkets: [i("hub", "Hugging Face", "https://huggingface.co"), i("hf-mirror", "HF Mirror", "https://hf-mirror.com")]
|
|
157
|
+
});
|
|
158
|
+
//#endregion
|
|
159
|
+
export { a as default };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"payload": "eyJzY2hlbWEiOjEsInBhY2thZ2VOYW1lIjoiQHN5bmNzaGlvL2thbm8tcGx1Z2luLWh1Z2dpbmdmYWNlIiwicGx1Z2luSWQiOiJodWdnaW5nZmFjZSIsInZlcnNpb24iOiIyLjAuMCIsImZpbGVzIjpbeyJwYXRoIjoicGFja2FnZS5qc29uIiwic2l6ZSI6NjExLCJzaGEyNTYiOiIzZTk2OWU5NWIyZDRkYzI4MTdhNjVmNmExNzkzNjJkZDAzYjYyM2M4M2EzZmQwYjE2MWUyMGYzYWE4Mzg3Nzk5In0seyJwYXRoIjoicGx1Z2luLmpzb24iLCJzaXplIjo0NzcsInNoYTI1NiI6IjA1NTEzYjdhMGQ0ODMxMzRkM2VmMGJjOGI3MDY2YmUxYWEzOTYzMGFmZjM5YjBmOWEwMjE2YjFmNzRkZGNmNzYifSx7InBhdGgiOiJkaXN0L2VudHJ5LmpzIiwic2l6ZSI6NDkyNCwic2hhMjU2IjoiNDVlZTI2ZWNhOTRmNjhhZGRhNTIxMjhmZDBkZTYwNGQzOTBjYTc5ZGM1NWUxYjI4NjRlMTc1ZGU3MzE0M2I3ZCJ9XX0=",
|
|
3
|
+
"keyId": "release-1",
|
|
4
|
+
"signature": "SorzJV6gbcyPAxJLqbsxP0lsH93JSTDi6gYuJuFmvaNvUpWxPliMM1iCq+GoomMhYX9a95hECYIO9oUmH1q3Dg=="
|
|
5
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncshio/kano-plugin-huggingface",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "浏览 Hugging Face 与镜像的 GGUF 和 Safetensors 模型",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"kano-plugin"
|
|
8
|
+
],
|
|
9
|
+
"files": [
|
|
10
|
+
"plugin.json",
|
|
11
|
+
"dist",
|
|
12
|
+
"kano-release.json"
|
|
13
|
+
],
|
|
14
|
+
"kano": {
|
|
15
|
+
"manifest": "plugin.json"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "node ../../../scripts/build-plugins.mjs huggingface"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@syncshio/kano-plugin-sdk": "file:../../../../kano-plugin-sdk"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/plugin.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifestVersion": 2,
|
|
3
|
+
"id": "huggingface",
|
|
4
|
+
"name": "Hugging Face 模型市场",
|
|
5
|
+
"version": "2.0.0",
|
|
6
|
+
"description": "浏览 Hugging Face 与镜像的 GGUF 和 Safetensors 模型",
|
|
7
|
+
"runtime": {
|
|
8
|
+
"entry": "dist/entry.js"
|
|
9
|
+
},
|
|
10
|
+
"permissions": {
|
|
11
|
+
"network": [
|
|
12
|
+
"https://huggingface.co",
|
|
13
|
+
"https://hf-mirror.com"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"kano": "^1.0.0",
|
|
18
|
+
"pluginSdk": "^4.0.0"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"kano-plugin",
|
|
22
|
+
"model-market"
|
|
23
|
+
]
|
|
24
|
+
}
|
package/README.md
DELETED