Skip to content

Commit 8b96b0e

Browse files
authored
Merge branch 'main' into conversational_snippets_update
2 parents c273834 + 3881d12 commit 8b96b0e

File tree

15 files changed

+585
-225
lines changed

15 files changed

+585
-225
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or
9393
```html
9494
<script type="module">
9595
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm';
96-
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@0.18.2/+esm";
96+
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@0.19.0/+esm";
9797
</script>
9898
```
9999

packages/hub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@huggingface/hub",
33
"packageManager": "[email protected]",
4-
"version": "0.18.2",
4+
"version": "0.19.0",
55
"description": "Utilities to interact with the Hugging Face hub",
66
"repository": "https://github.com/huggingface/huggingface.js.git",
77
"publishConfig": {

packages/hub/src/lib/dataset-info.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { describe, expect, it } from "vitest";
22
import { datasetInfo } from "./dataset-info";
3+
import type { DatasetEntry } from "./list-datasets";
4+
import type { ApiDatasetInfo } from "../types/api/api-dataset";
35

46
describe("datasetInfo", () => {
57
it("should return the dataset info", async () => {
@@ -16,4 +18,39 @@ describe("datasetInfo", () => {
1618
private: false,
1719
});
1820
});
21+
22+
it("should return the dataset info with author", async () => {
23+
const info: DatasetEntry & Pick<ApiDatasetInfo, 'author'> = await datasetInfo({
24+
name: "nyu-mll/glue",
25+
additionalFields: ['author'],
26+
});
27+
expect(info).toEqual({
28+
id: "621ffdd236468d709f181e3f",
29+
downloads: expect.any(Number),
30+
gated: false,
31+
name: "nyu-mll/glue",
32+
updatedAt: expect.any(Date),
33+
likes: expect.any(Number),
34+
private: false,
35+
author: 'nyu-mll'
36+
});
37+
});
38+
39+
it("should return the dataset info for a specific revision", async () => {
40+
const info: DatasetEntry & Pick<ApiDatasetInfo, 'sha'> = await datasetInfo({
41+
name: "nyu-mll/glue",
42+
revision: "cb2099c76426ff97da7aa591cbd317d91fb5fcb7",
43+
additionalFields: ["sha"],
44+
});
45+
expect(info).toEqual({
46+
id: "621ffdd236468d709f181e3f",
47+
downloads: expect.any(Number),
48+
gated: false,
49+
name: "nyu-mll/glue",
50+
updatedAt: expect.any(Date),
51+
likes: expect.any(Number),
52+
private: false,
53+
sha: 'cb2099c76426ff97da7aa591cbd317d91fb5fcb7'
54+
});
55+
});
1956
});

packages/hub/src/lib/dataset-info.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export async function datasetInfo<
1313
name: string;
1414
hubUrl?: string;
1515
additionalFields?: T[];
16+
/**
17+
* An optional Git revision id which can be a branch name, a tag, or a commit hash.
18+
*/
19+
revision?: string;
1620
/**
1721
* Custom fetch function to use instead of the default one, for example to use a proxy or edit headers.
1822
*/
@@ -27,7 +31,7 @@ export async function datasetInfo<
2731
]).toString();
2832

2933
const response = await (params.fetch || fetch)(
30-
`${params?.hubUrl || HUB_URL}/api/datasets/${params.name}?${search.toString()}`,
34+
`${params?.hubUrl || HUB_URL}/api/datasets/${params.name}/revision/${encodeURIComponent(params.revision ?? "HEAD")}?${search.toString()}`,
3135
{
3236
headers: {
3337
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),

packages/hub/src/lib/model-info.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { describe, expect, it } from "vitest";
22
import { modelInfo } from "./model-info";
3+
import type { ModelEntry } from "./list-models";
4+
import type { ApiModelInfo } from "../types/api/api-model";
35

46
describe("modelInfo", () => {
57
it("should return the model info", async () => {
@@ -17,4 +19,41 @@ describe("modelInfo", () => {
1719
private: false,
1820
});
1921
});
22+
23+
it("should return the model info with author", async () => {
24+
const info: ModelEntry & Pick<ApiModelInfo, 'author'> = await modelInfo({
25+
name: "openai-community/gpt2",
26+
additionalFields: ["author"],
27+
});
28+
expect(info).toEqual({
29+
id: "621ffdc036468d709f17434d",
30+
downloads: expect.any(Number),
31+
author: "openai-community",
32+
gated: false,
33+
name: "openai-community/gpt2",
34+
updatedAt: expect.any(Date),
35+
likes: expect.any(Number),
36+
task: "text-generation",
37+
private: false,
38+
});
39+
});
40+
41+
it("should return the model info for a specific revision", async () => {
42+
const info: ModelEntry & Pick<ApiModelInfo, 'sha'> = await modelInfo({
43+
name: "openai-community/gpt2",
44+
additionalFields: ["sha"],
45+
revision: 'f27b190eeac4c2302d24068eabf5e9d6044389ae',
46+
});
47+
expect(info).toEqual({
48+
id: "621ffdc036468d709f17434d",
49+
downloads: expect.any(Number),
50+
gated: false,
51+
name: "openai-community/gpt2",
52+
updatedAt: expect.any(Date),
53+
likes: expect.any(Number),
54+
task: "text-generation",
55+
private: false,
56+
sha: "f27b190eeac4c2302d24068eabf5e9d6044389ae",
57+
});
58+
});
2059
});

packages/hub/src/lib/model-info.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ import { pick } from "../utils/pick";
77
import { MODEL_EXPAND_KEYS, type MODEL_EXPANDABLE_KEYS, type ModelEntry } from "./list-models";
88

99
export async function modelInfo<
10-
const T extends Exclude<(typeof MODEL_EXPANDABLE_KEYS)[number], (typeof MODEL_EXPANDABLE_KEYS)[number]> = never,
10+
const T extends Exclude<(typeof MODEL_EXPANDABLE_KEYS)[number], (typeof MODEL_EXPAND_KEYS)[number]> = never,
1111
>(
1212
params: {
1313
name: string;
1414
hubUrl?: string;
1515
additionalFields?: T[];
16+
/**
17+
* An optional Git revision id which can be a branch name, a tag, or a commit hash.
18+
*/
19+
revision?: string;
1620
/**
1721
* Custom fetch function to use instead of the default one, for example to use a proxy or edit headers.
1822
*/
@@ -27,7 +31,7 @@ export async function modelInfo<
2731
]).toString();
2832

2933
const response = await (params.fetch || fetch)(
30-
`${params?.hubUrl || HUB_URL}/api/models/${params.name}?${search.toString()}`,
34+
`${params?.hubUrl || HUB_URL}/api/models/${params.name}/revision/${encodeURIComponent(params.revision ?? "HEAD")}?${search.toString()}`,
3135
{
3236
headers: {
3337
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),

packages/hub/src/lib/space-info.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { describe, expect, it } from "vitest";
22
import { spaceInfo } from "./space-info";
3+
import type { SpaceEntry } from "./list-spaces";
4+
import type { ApiSpaceInfo } from "../types/api/api-space";
35

46
describe("spaceInfo", () => {
57
it("should return the space info", async () => {
@@ -15,4 +17,37 @@ describe("spaceInfo", () => {
1517
sdk: "static",
1618
});
1719
});
20+
21+
it("should return the space info with author", async () => {
22+
const info: SpaceEntry & Pick<ApiSpaceInfo, 'author'> = await spaceInfo({
23+
name: "huggingfacejs/client-side-oauth",
24+
additionalFields: ['author'],
25+
});
26+
expect(info).toEqual({
27+
id: "659835e689010f9c7aed608d",
28+
name: "huggingfacejs/client-side-oauth",
29+
updatedAt: expect.any(Date),
30+
likes: expect.any(Number),
31+
private: false,
32+
sdk: "static",
33+
author: 'huggingfacejs',
34+
});
35+
});
36+
37+
it("should return the space info for a given revision", async () => {
38+
const info: SpaceEntry & Pick<ApiSpaceInfo, 'sha'> = await spaceInfo({
39+
name: "huggingfacejs/client-side-oauth",
40+
additionalFields: ['sha'],
41+
revision: 'e410a9ff348e6bed393b847711e793282d7c672e'
42+
});
43+
expect(info).toEqual({
44+
id: "659835e689010f9c7aed608d",
45+
name: "huggingfacejs/client-side-oauth",
46+
updatedAt: expect.any(Date),
47+
likes: expect.any(Number),
48+
private: false,
49+
sdk: "static",
50+
sha: 'e410a9ff348e6bed393b847711e793282d7c672e',
51+
});
52+
});
1853
});

packages/hub/src/lib/space-info.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export async function spaceInfo<
1414
name: string;
1515
hubUrl?: string;
1616
additionalFields?: T[];
17+
/**
18+
* An optional Git revision id which can be a branch name, a tag, or a commit hash.
19+
*/
20+
revision?: string;
1721
/**
1822
* Custom fetch function to use instead of the default one, for example to use a proxy or edit headers.
1923
*/
@@ -28,7 +32,7 @@ export async function spaceInfo<
2832
]).toString();
2933

3034
const response = await (params.fetch || fetch)(
31-
`${params?.hubUrl || HUB_URL}/api/spaces/${params.name}?${search.toString()}`,
35+
`${params?.hubUrl || HUB_URL}/api/spaces/${params.name}/revision/${encodeURIComponent(params.revision ?? "HEAD")}?${search.toString()}`,
3236
{
3337
headers: {
3438
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),

packages/jinja/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@huggingface/jinja",
33
"packageManager": "[email protected]",
4-
"version": "0.3.1",
4+
"version": "0.3.2",
55
"description": "A minimalistic JavaScript implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.",
66
"repository": "https://github.com/huggingface/huggingface.js.git",
77
"publishConfig": {

0 commit comments

Comments
 (0)