Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bellabf authored Jan 21, 2024
2 parents 7da2c67 + c706027 commit 6d95f7a
Show file tree
Hide file tree
Showing 24 changed files with 578 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/agents-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ jobs:
- run: pnpm publish --no-git-checks .
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Update Doc"
uses: peter-evans/repository-dispatch@v2
with:
event-type: doc-build
10 changes: 6 additions & 4 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ name: Build documentation

on:
workflow_dispatch:
repository_dispatch:
types: [doc-build]
push:
branches:
- main
paths:
- "README.md"
- "docs/**"
- "packages/hub/package.json"
- "packages/inference/package.json"
- "packages/agents/package.json"
- "packages/hub/README.md"
- "packages/inference/README.md"
- "packages/agents/README.md"
- ".github/workflows/documentation.yml"

jobs:
build:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/hub-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ jobs:
- run: pnpm publish --no-git-checks .
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Update Doc"
uses: peter-evans/repository-dispatch@v2
with:
event-type: doc-build
48 changes: 48 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Lint
on:
pull_request:
push:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v3
with:
# Could use something like rmacklin/fetch-through-merge-base@v0 instead when the repo gets bigger
fetch-depth: 0
- name: "Extracting the merge base into 'SINCE'"
id: since
run: |
if [ -z "${{ github.event.pull_request.head.ref }}" ]
then
echo "SINCE=${{ github.sha }}^1" >> $GITHUB_OUTPUT
else
echo "SINCE=$(git merge-base origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }})" >> $GITHUB_OUTPUT
fi
- run: corepack enable

- uses: actions/setup-node@v3
with:
node-version: "18"
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"
- run: |
pnpm install --frozen-lockfile --filter .
pnpm install --frozen-lockfile --filter ...[${{ steps.since.outputs.SINCE }}]...
pnpm --filter ...[${{ steps.since.outputs.SINCE }}]... build
- name: "Checking lint errors"
run: |
pnpm --filter ...[${{ steps.since.outputs.SINCE }}] lint:check
- name: "Checking format errors"
run: |
pnpm --filter ...[${{ steps.since.outputs.SINCE }}] format:check
- name: Check types
run: pnpm --filter ...[${{ steps.since.outputs.SINCE }}] check
4 changes: 4 additions & 0 deletions .github/workflows/tasks-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ jobs:
- run: pnpm publish --no-git-checks .
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Update Doc"
uses: peter-evans/repository-dispatch@v2
with:
event-type: doc-build
14 changes: 2 additions & 12 deletions .github/workflows/lint-and-test.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Lint and test
name: Test
on:
pull_request:
push:
branches:
- main

jobs:
lint:
test:
runs-on: ubuntu-latest
timeout-minutes: 10

Expand Down Expand Up @@ -36,16 +36,6 @@ jobs:
pnpm install --frozen-lockfile --filter .
pnpm install --frozen-lockfile --filter ...[${{ steps.since.outputs.SINCE }}]...
pnpm --filter ...[${{ steps.since.outputs.SINCE }}]... build
- name: "Checking lint errors"
run: |
pnpm --filter ...[${{ steps.since.outputs.SINCE }}] lint:check
- name: "Checking format errors"
run: |
pnpm --filter ...[${{ steps.since.outputs.SINCE }}] format:check
- name: Check types
run: pnpm --filter ...[${{ steps.since.outputs.SINCE }}] check
- name: Test
run: VCR_MODE=playback pnpm --filter ...[${{ steps.since.outputs.SINCE }}] test
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
},
"[svelte]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ If you want to run only specific tests, you can do `pnpm test -- -t "test name"`
- Add the package name in [`pnpm-workspace.yaml`](pnpm-workspace.yaml)
- Add a `package.json` inspired from the other packages ([`packages/hub/package.json`](packages/hub/package.json) / [`packages/agents/package.json`](packages/agents/package.json)) in `packages/<package name>/package.json`
- Run `pnpm install` at the root
- Edit [`packages/doc-internal/package.json`](packages/doc-internal/package.json) and add the two commands in the `scripts` section:
- `prepublish-<package name>`
- `doc-<package name>`
- Edit [`packages/doc-internal/package.json`](packages/doc-internal/package.json) and add the command in the `scripts` section:
- `doc-<package name>` (don't forget to edit the `start` command too)
- Add the `<package-name>-publish.yml` file in the `.github/workflows` folder, inspired from the other packages
- Add the package in the main README.md
- Add a `tsup.config.ts` file in the package folder, inspired from the other packages, or just use `tsup src/index.ts --format cjs,esm --clean --dts` as the build command
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or
```html
<script type="module">
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm';
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@0.12.3/+esm";
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@0.13.0/+esm";
</script>
```

Expand Down
10 changes: 0 additions & 10 deletions packages/doc-internal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ We run a few scripts in between, [fix-md-links](./fix-md-links.ts) and [update-t
```console
# Generate all docs
pnpm run start

# Generate docs for @huggingface/hub
pnpm run prepublish-hub

# Generate docs for @huggingface/inference
pnpm run prepublish-inference

# Generate docs for @huggingface/agents
pnpm run prepublish-agents

```

## HTML docs
Expand Down
3 changes: 0 additions & 3 deletions packages/doc-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"lint:check": "eslint --ext .cjs,.ts .",
"format": "prettier --write .",
"format:check": "prettier --check .",
"prepublish-hub": "pnpm run fix-cdn-versions && pnpm run doc-hub && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
"prepublish-inference": "pnpm run fix-cdn-versions && pnpm run doc-inference && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
"prepublish-agents": "pnpm run fix-cdn-versions && pnpm run doc-agents && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
"doc-hub": "typedoc --tsconfig ../hub/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/hub --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../hub/index.ts",
"doc-inference": "typedoc --tsconfig ../inference/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/inference --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../inference/src/index.ts",
"doc-agents": "typedoc --tsconfig ../agents/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/agents --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../agents/src/index.ts",
Expand Down
22 changes: 22 additions & 0 deletions packages/hub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ for await (const fileInfo of listFiles({repo})) {
await deleteRepo({ repo, credentials });
```

## OAuth Login

It's possible to login using OAuth (["Sign in with HF"](https://huggingface.co/docs/hub/oauth)).

This will allow you get an access token to use some of the API, depending on the scopes set inside the Space or the OAuth App.

```ts
import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "@huggingface/hub";

const oauthResult = await oauthHandleRedirectIfPresent();

if (!oauthResult) {
// If the user is not logged in, redirect to the login page
window.location.href = await oauthLoginUrl();
}

// You can use oauthResult.accessToken, oauthResult.accessTokenExpiresAt and oauthResult.userInfo
console.log(oauthResult);
```

Checkout the demo: https://huggingface.co/spaces/huggingfacejs/client-side-oauth

## Performance considerations

When uploading large files, you may want to run the `commit` calls inside a worker, to offload the sha256 computations.
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@huggingface/hub",
"packageManager": "[email protected]",
"version": "0.12.3",
"version": "0.13.0",
"description": "Utilities to interact with the Hugging Face hub",
"repository": "https://github.com/huggingface/huggingface.js.git",
"publishConfig": {
Expand Down
2 changes: 2 additions & 0 deletions packages/hub/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export * from "./list-datasets";
export * from "./list-files";
export * from "./list-models";
export * from "./list-spaces";
export * from "./oauth-handle-redirect";
export * from "./oauth-login-url";
export * from "./parse-safetensors-metadata";
export * from "./upload-file";
export * from "./upload-files";
Expand Down
3 changes: 3 additions & 0 deletions packages/hub/src/lib/list-datasets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ describe("listDatasets", () => {
const results: DatasetEntry[] = [];

for await (const entry of listDatasets({ search: { owner: "hf-doc-build" } })) {
if (entry.name === "hf-doc-build/doc-build-dev-test") {
continue;
}
if (typeof entry.downloads === "number") {
entry.downloads = 0;
}
Expand Down
Loading

0 comments on commit 6d95f7a

Please sign in to comment.