Skip to content

Commit 31fdf54

Browse files
authored
Merge branch 'huggingface:main' into xsn/llama_snippet
2 parents 3d5db7d + 3f9c0a9 commit 31fdf54

File tree

51 files changed

+1037
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1037
-116
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or
8888

8989
```html
9090
<script type="module">
91-
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@2.7.0/+esm';
91+
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@2.8.0/+esm';
9292
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
9393
</script>
9494
```

packages/hub/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,4 @@ Under the hood, `@huggingface/hub` uses a lazy blob implementation to load the f
121121

122122
## Dependencies
123123

124-
- `hash-wasm` : Only used in the browser, when committing files over 10 MB. Browsers do not natively support streaming sha256 computations.
125124
- `@huggingface/tasks` : Typings only

packages/hub/src/lib/commit.spec.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,80 @@ size 4194304
204204
}
205205
// https://huggingfacejs-push-model-from-web.hf.space/
206206
}, 60_000);
207+
208+
it("should be able to create a PR and then commit to it", async function () {
209+
const repoName = `${TEST_USER}/TEST-${insecureRandomString()}`;
210+
const repo: RepoId = {
211+
name: repoName,
212+
type: "model",
213+
};
214+
215+
await createRepo({
216+
credentials: {
217+
accessToken: TEST_ACCESS_TOKEN,
218+
},
219+
repo,
220+
hubUrl: TEST_HUB_URL,
221+
});
222+
223+
try {
224+
const pr = await commit({
225+
repo,
226+
credentials: {
227+
accessToken: TEST_ACCESS_TOKEN,
228+
},
229+
hubUrl: TEST_HUB_URL,
230+
title: "Create PR",
231+
isPullRequest: true,
232+
operations: [
233+
{
234+
operation: "addOrUpdate",
235+
content: new Blob(["This is me"]),
236+
path: "test.txt",
237+
},
238+
],
239+
});
240+
241+
if (!pr) {
242+
throw new Error("PR creation failed");
243+
}
244+
245+
if (!pr.pullRequestUrl) {
246+
throw new Error("No pull request url");
247+
}
248+
249+
const prNumber = pr.pullRequestUrl.split("/").pop();
250+
const prRef = `refs/pr/${prNumber}`;
251+
252+
await commit({
253+
repo,
254+
credentials: {
255+
accessToken: TEST_ACCESS_TOKEN,
256+
},
257+
hubUrl: TEST_HUB_URL,
258+
branch: prRef,
259+
title: "Some commit",
260+
operations: [
261+
{
262+
operation: "addOrUpdate",
263+
content: new URL(
264+
`https://huggingface.co/spaces/huggingfacejs/push-model-from-web/resolve/main/mobilenet/group1-shard1of2`
265+
),
266+
path: "mobilenet/group1-shard1of2",
267+
},
268+
],
269+
});
270+
271+
assert(commit, "PR commit failed");
272+
} finally {
273+
await deleteRepo({
274+
repo: {
275+
name: repoName,
276+
type: "model",
277+
},
278+
hubUrl: TEST_HUB_URL,
279+
credentials: { accessToken: TEST_ACCESS_TOKEN },
280+
});
281+
}
282+
}, 60_000);
207283
});

packages/inference/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@huggingface/inference",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"packageManager": "[email protected]",
55
"license": "MIT",
66
"author": "Tim Mikeladze <[email protected]>",

packages/inference/src/tasks/nlp/textGeneration.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { TextGenerationInput, TextGenerationOutput } from "@huggingface/tasks";
22
import { InferenceOutputError } from "../../lib/InferenceOutputError";
33
import type { BaseArgs, Options } from "../../types";
4+
import { toArray } from "../../utils/toArray";
45
import { request } from "../custom/request";
56

67
export type { TextGenerationInput, TextGenerationOutput };
@@ -12,10 +13,12 @@ export async function textGeneration(
1213
args: BaseArgs & TextGenerationInput,
1314
options?: Options
1415
): Promise<TextGenerationOutput> {
15-
const res = await request<TextGenerationOutput[]>(args, {
16-
...options,
17-
taskHint: "text-generation",
18-
});
16+
const res = toArray(
17+
await request<TextGenerationOutput | TextGenerationOutput[]>(args, {
18+
...options,
19+
taskHint: "text-generation",
20+
})
21+
);
1922
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.generated_text === "string");
2023
if (!isValidOutput) {
2124
throw new InferenceOutputError("Expected Array<{generated_text: string}>");

packages/languages/src/languages_iso_639_3.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17884,7 +17884,7 @@ export const LANGUAGES_ISO_639_3 = {
1788417884
},
1788517885
nan: {
1788617886
code: "nan",
17887-
name: "Min Nan Chinese",
17887+
name: "Southern Min (Min Nan Chinese)",
1788817888
},
1788917889
nao: {
1789017890
code: "nao",
@@ -30790,7 +30790,7 @@ export const LANGUAGES_ISO_639_3 = {
3079030790
},
3079130791
yue: {
3079230792
code: "yue",
30793-
name: "Yue Chinese",
30793+
name: "Cantonese (Yue Chinese)",
3079430794
},
3079530795
yuf: {
3079630796
code: "yuf",

packages/space-header/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@huggingface/space-header",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"packageManager": "[email protected]",
55
"description": "Use the Space mini_header outside Hugging Face",
66
"repository": "https://github.com/huggingface/huggingface.js.git",

packages/space-header/src/header/components/box.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ export const Box = (): HTMLDivElement => {
1313
box.style.justifyContent = "space-between";
1414
box.style.overflow = "hidden";
1515
box.style.position = "fixed";
16-
box.style.right = "1.5rem";
17-
box.style.top = "1.25rem";
16+
box.style.right = ".75rem";
17+
box.style.top = ".75rem";
1818
box.style.width = "auto";
1919
box.style.zIndex = "20";
20-
box.style.padding = "0.75rem";
2120
box.style.paddingLeft = "1rem";
22-
box.style.paddingRight = "0rem";
23-
2421
box.setAttribute("id", "huggingface-space-header");
2522

2623
window.matchMedia("(max-width: 768px)").addEventListener("change", (e) => {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const ArrowCollapse = (): SVGElement => {
2+
const arrow = document.createElementNS("http://www.w3.org/2000/svg", "svg");
3+
arrow.setAttribute("xmlns", "http://www.w3.org/2000/svg");
4+
arrow.setAttribute("xmlns:link", "http://www.w3.org/1999/xlink");
5+
arrow.setAttribute("aria-hidden", "true");
6+
arrow.setAttribute("focusable", "false");
7+
arrow.setAttribute("role", "img");
8+
arrow.setAttribute("width", "1em");
9+
arrow.setAttribute("height", "1em");
10+
arrow.setAttribute("preserveAspectRatio", "xMidYMid meet");
11+
arrow.setAttribute("viewBox", "0 0 12 12");
12+
arrow.setAttribute("fill", "currentColor");
13+
14+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
15+
16+
path.setAttribute(
17+
"d",
18+
"M0.375001 10.3828L0.375 1.61719C0.375 1.104 0.816001 0.687501 1.35938 0.687501L10.6406 0.6875C10.9017 0.6875 11.1521 0.785449 11.3367 0.959797C11.5213 1.13415 11.625 1.37062 11.625 1.61719V10.3828C11.625 10.6294 11.5213 10.8659 11.3367 11.0402C11.1521 11.2145 10.9017 11.3125 10.6406 11.3125H1.35938C0.816001 11.3125 0.375001 10.896 0.375001 10.3828ZM1.35938 10.5156H10.6406C10.7183 10.5156 10.7813 10.4561 10.7813 10.3828V4.40625H1.21875V10.3828C1.21875 10.418 1.23356 10.4518 1.25994 10.4767C1.28631 10.5017 1.32208 10.5156 1.35938 10.5156ZM4.61052 6.38251L5.9999 7.69472L7.38927 6.38251C7.44083 6.33007 7.50645 6.29173 7.57913 6.27153C7.6518 6.25134 7.72898 6.25003 7.8024 6.26776C7.87583 6.28549 7.9428 6.3216 7.99628 6.37227C8.04983 6.42295 8.08785 6.48631 8.10645 6.5557C8.12528 6.62497 8.12393 6.69773 8.10263 6.76635C8.0814 6.83497 8.0409 6.8969 7.98555 6.94564L6.29802 8.53936C6.21892 8.61399 6.11169 8.65592 5.9999 8.65592C5.8881 8.65592 5.78087 8.61399 5.70177 8.53936L4.01427 6.94564C3.95874 6.89694 3.91814 6.835 3.89676 6.76633C3.87538 6.69766 3.874 6.62483 3.89277 6.55549C3.91154 6.48615 3.94977 6.42287 4.00343 6.37233C4.05708 6.32179 4.12418 6.28585 4.19765 6.2683C4.27098 6.25054 4.34803 6.25178 4.42068 6.27188C4.49334 6.29198 4.55891 6.3302 4.61052 6.38251Z"
19+
);
20+
21+
arrow.appendChild(path);
22+
return arrow;
23+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { Space } from "../../../type";
2+
import { ArrowCollapse } from "./arrow";
3+
4+
export const Collapse = (space: Space, callback: () => void): HTMLDivElement | SVGElement => {
5+
const box = document.createElement("div");
6+
7+
box.setAttribute("id", "space-header__collapse");
8+
9+
box.style.display = "flex";
10+
box.style.flexDirection = "row";
11+
box.style.alignItems = "center";
12+
box.style.justifyContent = "center";
13+
box.style.fontSize = "16px";
14+
box.style.paddingLeft = "10px";
15+
box.style.paddingRight = "10px";
16+
box.style.height = "40px";
17+
box.style.cursor = "pointer";
18+
box.style.color = "#40546e";
19+
box.style.transitionDuration = "0.1s";
20+
box.style.transitionProperty = "all";
21+
box.style.transitionTimingFunction = "ease-in-out";
22+
23+
box.appendChild(ArrowCollapse());
24+
25+
box.addEventListener("click", (e) => {
26+
e.preventDefault();
27+
e.stopPropagation();
28+
callback();
29+
});
30+
31+
box.addEventListener("mouseenter", () => {
32+
box.style.color = "#213551";
33+
});
34+
box.addEventListener("mouseleave", () => {
35+
box.style.color = "#40546e";
36+
});
37+
38+
return box;
39+
};

0 commit comments

Comments
 (0)