From 15bc408fa72e0826d3a53b385f34f429b649f014 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 20 Jan 2026 11:07:14 +0000 Subject: [PATCH 01/10] switch to oxfmt --- .devcontainer/devcontainer.json | 36 ++++---- .editorconfig | 2 +- .oxfmtrc.json | 6 ++ .prettierrc | 9 -- .vscode/settings.json | 18 ++-- package.json | 7 +- packages/agents/package.json | 4 +- packages/blob/package.json | 4 +- packages/dduf/package.json | 4 +- packages/doc-internal/package.json | 4 +- packages/gguf/package.json | 4 +- packages/hub/package.json | 4 +- packages/inference/package.json | 4 +- packages/jinja/package.json | 4 +- packages/languages/package.json | 4 +- packages/mcp-client/package.json | 4 +- packages/ollama-utils/package.json | 6 +- packages/space-header/package.json | 4 +- packages/tasks-gen/package.json | 10 +-- packages/tasks/package.json | 4 +- packages/tiny-agents/package.json | 4 +- pnpm-lock.yaml | 129 ++++++++++++++++++++++++----- 22 files changed, 182 insertions(+), 93 deletions(-) create mode 100644 .oxfmtrc.json delete mode 100644 .prettierrc diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 10e1514b18..519b13e8e0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,24 +1,30 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node { - "name": "Node.js & TypeScript", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm", + "name": "Node.js & TypeScript", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm", - // Features to add to the dev container. More info: https://containers.dev/features. - "features": { - "ghcr.io/joshuanianji/devcontainer-features/mount-pnpm-store:1": {} - } + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/joshuanianji/devcontainer-features/mount-pnpm-store:1": {} + }, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], + "customizations": { + "vscode": { + "extensions": ["oxc.oxc-vscode"] + } + } - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "yarn install", + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], - // Configure tool-specific properties. - // "customizations": {}, + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "yarn install", - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" } diff --git a/.editorconfig b/.editorconfig index b614fe0926..0cf077588e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -[*.{ts}] +max_line_length = 120 indent_style = tab indent_size = 2 trim_trailing_whitespace = true diff --git a/.oxfmtrc.json b/.oxfmtrc.json new file mode 100644 index 0000000000..c886b57061 --- /dev/null +++ b/.oxfmtrc.json @@ -0,0 +1,6 @@ +{ + "$schema": "./node_modules/oxfmt/configuration_schema.json", + "ignorePatterns": [], + "useTabs": true, + "printWidth": 120 +} diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 4593d117ae..0000000000 --- a/.prettierrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "semi": true, - "useTabs": true, - "tabWidth": 2, - "printWidth": 120, - "trailingComma": "es5", - "plugins": ["prettier-plugin-svelte"], - "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] -} diff --git a/.vscode/settings.json b/.vscode/settings.json index 9d7878528a..2aa98ee0f2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,21 +1,21 @@ { - "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.defaultFormatter": "oxc.oxc-vscode", "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file", // tell oxfmt to format the whole file, not only the modified lines "editor.codeActionsOnSave": { "source.fixAll": "explicit" }, - "[svelte]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "prettier.configPath": ".prettierrc", "json.format.enable": false, - "[json]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, "cSpell.words": ["huggingface"], "deno.enablePaths": ["./e2e/deno"], "search.exclude": { "**/dist": true }, - "typescript.tsdk": "node_modules/typescript/lib" + "typescript.tsdk": "node_modules/typescript/lib", + "[typescript]": { + "editor.defaultFormatter": "oxc.oxc-vscode" + }, + "[jsonc]": { + "editor.defaultFormatter": "oxc.oxc-vscode" + } } diff --git a/package.json b/package.json index 80bcdac821..17805b321f 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .eslintrc.cjs", "lint:check": "eslint --ext .cjs,.ts .eslintrc.cjs", - "format": "prettier --write package.json .prettierrc .vscode .eslintrc.cjs e2e .github *.md", - "format:check": "prettier --check package.json .prettierrc .vscode .eslintrc.cjs .github *.md", + "format": "oxfmt package.json .prettierrc .vscode .eslintrc.cjs e2e .github *.md", + "format:check": "oxfmt --check package.json .prettierrc .vscode .eslintrc.cjs .github *.md", "check-deps": "tsx scripts/check-deps.ts" }, "devDependencies": { @@ -20,8 +20,7 @@ "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-svelte": "^2.30.0", "npm-run-all": "^4.1.5", - "prettier": "^3.1.0", - "prettier-plugin-svelte": "^3.1.2", + "oxfmt": "^0.26.0", "semver": "^7.5.0", "tshy": "^3.0.2", "tsup": "^6.7.0", diff --git a/packages/agents/package.json b/packages/agents/package.json index 7c32cb6d2e..cd842dfe53 100644 --- a/packages/agents/package.json +++ b/packages/agents/package.json @@ -28,8 +28,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build", "build": "tsup && tsc --emitDeclarationOnly --declaration", "test": "vitest run", diff --git a/packages/blob/package.json b/packages/blob/package.json index c630e7a23b..fc3d8b26d0 100644 --- a/packages/blob/package.json +++ b/packages/blob/package.json @@ -34,8 +34,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build", "build": "tsup && tsc --emitDeclarationOnly --declaration && cp dist/index.d.ts dist/index.m.d.ts && cp dist/src/utils/FileBlob.d.ts dist/src/utils/FileBlob.m.d.ts && cp dist/src/utils/WebBlob.d.ts dist/src/utils/WebBlob.m.d.ts", "prepare": "pnpm run build", diff --git a/packages/dduf/package.json b/packages/dduf/package.json index 5103fecd7c..91c3dc7b13 100644 --- a/packages/dduf/package.json +++ b/packages/dduf/package.json @@ -26,8 +26,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build", "build": "tsup && tsc --emitDeclarationOnly --declaration", "prepare": "pnpm run build", diff --git a/packages/doc-internal/package.json b/packages/doc-internal/package.json index 429afcc6e7..1346fbcd25 100644 --- a/packages/doc-internal/package.json +++ b/packages/doc-internal/package.json @@ -8,8 +8,8 @@ "start": "pnpm run fix-cdn-versions && pnpm run doc-hub && pnpm run doc-inference && pnpm run doc-space-header && pnpm run doc-gguf && pnpm run doc-mcp-client && pnpm run doc-tiny-agents && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks", "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "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-gguf": "mkdir -p ../../docs/gguf && cp ../../packages/gguf/README.md ../../docs/gguf/README.md", diff --git a/packages/gguf/package.json b/packages/gguf/package.json index 6a78ca6c6c..3b0724601d 100644 --- a/packages/gguf/package.json +++ b/packages/gguf/package.json @@ -33,8 +33,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build", "build": "tsup src/index.ts src/cli.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration", "build:llm": "tsx scripts/generate-llm.ts && pnpm run format", diff --git a/packages/hub/package.json b/packages/hub/package.json index 33bfbd5a55..69acc41e56 100644 --- a/packages/hub/package.json +++ b/packages/hub/package.json @@ -34,8 +34,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build", "build": "tsup && tsc --emitDeclarationOnly --declaration", "prepare": "pnpm run build", diff --git a/packages/inference/package.json b/packages/inference/package.json index 9edddf6b6c..3d16d73cdc 100644 --- a/packages/inference/package.json +++ b/packages/inference/package.json @@ -44,8 +44,8 @@ "build": "pnpm run export-templates && pnpm run package-to-ts && tshy", "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepare": "pnpm run build", "prepublishOnly": "pnpm run build", "test": "vitest run --config vitest.config.mts", diff --git a/packages/jinja/package.json b/packages/jinja/package.json index 881016cde3..b291e3453d 100644 --- a/packages/jinja/package.json +++ b/packages/jinja/package.json @@ -25,8 +25,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build", "prepare": "pnpm run build", "build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration", diff --git a/packages/languages/package.json b/packages/languages/package.json index bd4069901f..a3283e07f6 100644 --- a/packages/languages/package.json +++ b/packages/languages/package.json @@ -21,8 +21,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build", "build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration", "test": "vitest run", diff --git a/packages/mcp-client/package.json b/packages/mcp-client/package.json index 75c5d3b4d1..ec54e33889 100644 --- a/packages/mcp-client/package.json +++ b/packages/mcp-client/package.json @@ -27,8 +27,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build", "build": "tsup src/index.ts cli.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration", "prepare": "pnpm run build", diff --git a/packages/ollama-utils/package.json b/packages/ollama-utils/package.json index 112478daa9..6b5893def3 100644 --- a/packages/ollama-utils/package.json +++ b/packages/ollama-utils/package.json @@ -29,11 +29,11 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build", "build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration", - "build:automap": "tsx scripts/generate-automap.ts && prettier --write ./src/chat-template-automap.ts", + "build:automap": "tsx scripts/generate-automap.ts && oxfmt ./src/chat-template-automap.ts", "test": "vitest run", "check": "tsc" }, diff --git a/packages/space-header/package.json b/packages/space-header/package.json index 409e332e33..5e67ecd195 100644 --- a/packages/space-header/package.json +++ b/packages/space-header/package.json @@ -25,8 +25,8 @@ "build": "tsup && tsc --emitDeclarationOnly --declaration", "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build" }, "keywords": [ diff --git a/packages/tasks-gen/package.json b/packages/tasks-gen/package.json index 2959d998de..4b1c767fcf 100644 --- a/packages/tasks-gen/package.json +++ b/packages/tasks-gen/package.json @@ -8,13 +8,13 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "check": "tsc", "generate-snippets-fixtures": "tsx scripts/generate-snippets-fixtures.ts", - "inference-codegen": "tsx scripts/inference-codegen.ts && prettier --write ../tasks/src/tasks/*/inference.ts", - "inference-tgi-import": "tsx scripts/inference-tgi-import.ts && prettier --write ../tasks/src/tasks/text-generation/spec/*.json && prettier --write ../tasks/src/tasks/chat-completion/spec/*.json", - "inference-tei-import": "tsx scripts/inference-tei-import.ts && prettier --write ../tasks/src/tasks/feature-extraction/spec/*.json", + "inference-codegen": "tsx scripts/inference-codegen.ts && oxfmt ../tasks/src/tasks/*/inference.ts", + "inference-tgi-import": "tsx scripts/inference-tgi-import.ts && oxfmt ../tasks/src/tasks/text-generation/spec/*.json && oxfmt ../tasks/src/tasks/chat-completion/spec/*.json", + "inference-tei-import": "tsx scripts/inference-tei-import.ts && oxfmt ../tasks/src/tasks/feature-extraction/spec/*.json", "test": "vitest run" }, "type": "module", diff --git a/packages/tasks/package.json b/packages/tasks/package.json index a3626aa9ed..34db238d5a 100644 --- a/packages/tasks/package.json +++ b/packages/tasks/package.json @@ -24,8 +24,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm --filter tasks-gen inference-codegen && git diff --name-only --exit-code src && pnpm run build", "build": "tshy", "watch:cjs": "tsc --declaration --outdir dist/commonjs --module commonjs --watch", diff --git a/packages/tiny-agents/package.json b/packages/tiny-agents/package.json index 8c3339e4f0..f8d2c37cab 100644 --- a/packages/tiny-agents/package.json +++ b/packages/tiny-agents/package.json @@ -27,8 +27,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build", "build": "tsup src/*.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration", "prepare": "pnpm run build", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ac4e071d92..f62a100a3f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,12 +35,9 @@ importers: npm-run-all: specifier: ^4.1.5 version: 4.1.5 - prettier: - specifier: ^3.1.0 - version: 3.1.0 - prettier-plugin-svelte: - specifier: ^3.1.2 - version: 3.1.2(prettier@3.1.0)(svelte@4.2.7) + oxfmt: + specifier: ^0.26.0 + version: 0.26.0 semver: specifier: ^7.5.0 version: 7.5.0 @@ -570,6 +567,46 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@oxfmt/darwin-arm64@0.26.0': + resolution: {integrity: sha512-AAGc+8CffkiWeVgtWf4dPfQwHEE5c/j/8NWH7VGVxxJRCZFdmWcqCXprvL2H6qZFewvDLrFbuSPRCqYCpYGaTQ==} + cpu: [arm64] + os: [darwin] + + '@oxfmt/darwin-x64@0.26.0': + resolution: {integrity: sha512-xFx5ijCTjw577wJvFlZEMmKDnp3HSCcbYdCsLRmC5i3TZZiDe9DEYh3P46uqhzj8BkEw1Vm1ZCWdl48aEYAzvQ==} + cpu: [x64] + os: [darwin] + + '@oxfmt/linux-arm64-gnu@0.26.0': + resolution: {integrity: sha512-GubkQeQT5d3B/Jx/IiR7NMkSmXrCZcVI0BPh1i7mpFi8HgD1hQ/LbhiBKAMsMqs5bbugdQOgBEl8bOhe8JhW1g==} + cpu: [arm64] + os: [linux] + + '@oxfmt/linux-arm64-musl@0.26.0': + resolution: {integrity: sha512-OEypUwK69bFPj+aa3/LYCnlIUPgoOLu//WNcriwpnWNmt47808Ht7RJSg+MNK8a7pSZHpXJ5/E6CRK/OTwFdaQ==} + cpu: [arm64] + os: [linux] + + '@oxfmt/linux-x64-gnu@0.26.0': + resolution: {integrity: sha512-xO6iEW2bC6ZHyOTPmPWrg/nM6xgzyRPaS84rATy6F8d79wz69LdRdJ3l/PXlkqhi7XoxhvX4ExysA0Nf10ZZEQ==} + cpu: [x64] + os: [linux] + + '@oxfmt/linux-x64-musl@0.26.0': + resolution: {integrity: sha512-Z3KuZFC+MIuAyFCXBHY71kCsdRq1ulbsbzTe71v+hrEv7zVBn6yzql+/AZcgfIaKzWO9OXNuz5WWLWDmVALwow==} + cpu: [x64] + os: [linux] + + '@oxfmt/win32-arm64@0.26.0': + resolution: {integrity: sha512-3zRbqwVWK1mDhRhTknlQFpRFL9GhEB5GfU6U7wawnuEwpvi39q91kJ+SRJvJnhyPCARkjZBd1V8XnweN5IFd1g==} + cpu: [arm64] + os: [win32] + + '@oxfmt/win32-x64@0.26.0': + resolution: {integrity: sha512-m8TfIljU22i9UEIkD+slGPifTFeaCwIUfxszN3E6ABWP1KQbtwSw9Ak0TdoikibvukF/dtbeyG3WW63jv9DnEg==} + cpu: [x64] + os: [win32] + '@polka/url@1.0.0-next.23': resolution: {integrity: sha512-C16M+IYz0rgRhWZdCmK+h58JMv8vijAA61gmz2rspCSwKwzBebpdcsiUmwrtJRdphuY30i6BSLEOP8ppbNLyLg==} @@ -2020,6 +2057,11 @@ packages: resolution: {integrity: sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==} engines: {node: '>= 0.8.0'} + oxfmt@0.26.0: + resolution: {integrity: sha512-UDD1wFNwfeorMm2ZY0xy1KRAAvJ5NjKBfbDmiMwGP7baEHTq65cYpC0aPP+BGHc8weXUbSZaK8MdGyvuRUvS4Q==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + p-cancelable@3.0.0: resolution: {integrity: sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw==} engines: {node: '>=12.20'} @@ -2171,12 +2213,6 @@ packages: resolution: {integrity: sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==} engines: {node: '>=6.0.0'} - prettier-plugin-svelte@3.1.2: - resolution: {integrity: sha512-7xfMZtwgAWHMT0iZc8jN4o65zgbAQ3+O32V6W7pXrqNvKnHnkoyQCGCbKeUyXKZLbYE0YhFRnamfxfkEGxm8qA==} - peerDependencies: - prettier: ^3.0.0 - svelte: ^3.2.0 || ^4.0.0-next.0 || ^5.0.0-next.0 - prettier@3.1.0: resolution: {integrity: sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==} engines: {node: '>=14'} @@ -2542,6 +2578,10 @@ packages: resolution: {integrity: sha512-zSYNUlYSMhJ6Zdou4cJwo/p7w5nmAH17GRfU/ui3ctvjXFErXXkruT4MWW6poDeXgCaIBlGLrfU6TbTXxyGMww==} engines: {node: '>=14.0.0'} + tinypool@2.0.0: + resolution: {integrity: sha512-/RX9RzeH2xU5ADE7n2Ykvmi9ED3FBGPAjw9u3zucrNNaEBIO0HPSYgL0NT7+3p147ojeSdaVu08F6hjpv31HJg==} + engines: {node: ^20.0.0 || >=22.0.0} + tinyspy@2.2.0: resolution: {integrity: sha512-d2eda04AN/cPOR89F7Xv5bK/jrQEhmcLFe6HFldoeO9AJtps+fqEnh486vnT/8y4bw38pSyxDcTCAq+Ks2aJTg==} engines: {node: '>=14.0.0'} @@ -2853,6 +2893,7 @@ snapshots: dependencies: '@jridgewell/gen-mapping': 0.3.3 '@jridgewell/trace-mapping': 0.3.20 + optional: true '@babel/code-frame@7.18.6': dependencies: @@ -3123,7 +3164,8 @@ snapshots: '@jridgewell/resolve-uri@3.1.0': {} - '@jridgewell/resolve-uri@3.1.1': {} + '@jridgewell/resolve-uri@3.1.1': + optional: true '@jridgewell/set-array@1.1.2': {} @@ -3140,6 +3182,7 @@ snapshots: dependencies: '@jridgewell/resolve-uri': 3.1.1 '@jridgewell/sourcemap-codec': 1.4.15 + optional: true '@jspm/core@2.0.1': {} @@ -3155,6 +3198,30 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.15.0 + '@oxfmt/darwin-arm64@0.26.0': + optional: true + + '@oxfmt/darwin-x64@0.26.0': + optional: true + + '@oxfmt/linux-arm64-gnu@0.26.0': + optional: true + + '@oxfmt/linux-arm64-musl@0.26.0': + optional: true + + '@oxfmt/linux-x64-gnu@0.26.0': + optional: true + + '@oxfmt/linux-x64-musl@0.26.0': + optional: true + + '@oxfmt/win32-arm64@0.26.0': + optional: true + + '@oxfmt/win32-x64@0.26.0': + optional: true + '@polka/url@1.0.0-next.23': {} '@rollup/pluginutils@5.0.5(rollup@4.6.0)': @@ -3488,6 +3555,7 @@ snapshots: aria-query@5.3.0: dependencies: dequal: 2.0.3 + optional: true array-buffer-byte-length@1.0.1: dependencies: @@ -3520,6 +3588,7 @@ snapshots: axobject-query@3.2.1: dependencies: dequal: 2.0.3 + optional: true balanced-match@1.0.2: {} @@ -3663,6 +3732,7 @@ snapshots: acorn: 8.11.2 estree-walker: 3.0.3 periscopic: 3.1.0 + optional: true color-convert@1.9.3: dependencies: @@ -3722,6 +3792,7 @@ snapshots: dependencies: mdn-data: 2.0.30 source-map-js: 1.0.2 + optional: true css-value@0.0.1: {} @@ -3804,7 +3875,8 @@ snapshots: has-property-descriptors: 1.0.0 object-keys: 1.1.1 - dequal@2.0.3: {} + dequal@2.0.3: + optional: true devtools-protocol@0.0.1094867: {} @@ -4526,6 +4598,7 @@ snapshots: is-reference@3.0.2: dependencies: '@types/estree': 1.0.5 + optional: true is-regex@1.1.4: dependencies: @@ -4648,7 +4721,8 @@ snapshots: local-pkg@0.4.3: {} - locate-character@3.0.0: {} + locate-character@3.0.0: + optional: true locate-path@6.0.0: dependencies: @@ -4700,7 +4774,8 @@ snapshots: marky@1.2.5: {} - mdn-data@2.0.30: {} + mdn-data@2.0.30: + optional: true memorystream@0.3.1: {} @@ -4865,6 +4940,19 @@ snapshots: prelude-ls: 1.2.1 type-check: 0.4.0 + oxfmt@0.26.0: + dependencies: + tinypool: 2.0.0 + optionalDependencies: + '@oxfmt/darwin-arm64': 0.26.0 + '@oxfmt/darwin-x64': 0.26.0 + '@oxfmt/linux-arm64-gnu': 0.26.0 + '@oxfmt/linux-arm64-musl': 0.26.0 + '@oxfmt/linux-x64-gnu': 0.26.0 + '@oxfmt/linux-x64-musl': 0.26.0 + '@oxfmt/win32-arm64': 0.26.0 + '@oxfmt/win32-x64': 0.26.0 + p-cancelable@3.0.0: {} p-iteration@1.1.8: {} @@ -4942,6 +5030,7 @@ snapshots: '@types/estree': 1.0.5 estree-walker: 3.0.3 is-reference: 3.0.2 + optional: true picocolors@1.0.0: {} @@ -4986,11 +5075,6 @@ snapshots: dependencies: fast-diff: 1.2.0 - prettier-plugin-svelte@3.1.2(prettier@3.1.0)(svelte@4.2.7): - dependencies: - prettier: 3.1.0 - svelte: 4.2.7 - prettier@3.1.0: {} pretty-format@29.7.0: @@ -5379,6 +5463,7 @@ snapshots: locate-character: 3.0.0 magic-string: 0.30.5 periscopic: 3.1.0 + optional: true sync-content@2.0.1: dependencies: @@ -5419,6 +5504,8 @@ snapshots: tinypool@0.7.0: {} + tinypool@2.0.0: {} + tinyspy@2.2.0: {} to-regex-range@5.0.1: From 9ba626bc830d84297c307357dc58462872c8d552 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 20 Jan 2026 11:08:28 +0000 Subject: [PATCH 02/10] format everything --- e2e/svelte/package.json | 12 +- e2e/ts/package.json | 14 +- e2e/yarn/package.json | 6 +- package.json | 6 +- packages/agents/package.json | 60 ++++---- packages/agents/src/lib/evalBuilder.ts | 2 +- packages/agents/src/lib/generateCode.ts | 2 +- packages/agents/src/lib/promptGeneration.ts | 2 +- packages/blob/package.json | 50 +++---- packages/blob/src/utils/WebBlob.ts | 2 +- packages/dduf/package.json | 50 +++---- packages/dduf/src/check-dduf.spec.ts | 2 +- packages/dduf/src/check-dduf.ts | 6 +- packages/doc-internal/fix-cdn-versions.ts | 2 +- packages/doc-internal/fix-md-links.ts | 2 +- packages/doc-internal/package.json | 16 +- packages/doc-internal/update-toc.ts | 2 +- packages/gguf/package.json | 56 +++---- packages/gguf/scripts/generate-llm.ts | 2 +- packages/gguf/src/cli.ts | 8 +- packages/gguf/src/gguf.spec.ts | 8 +- packages/gguf/src/gguf.ts | 32 ++-- packages/hub/cli.ts | 40 ++--- packages/hub/package.json | 72 ++++----- packages/hub/scripts/debug-xet.ts | 4 +- packages/hub/src/error.ts | 2 +- packages/hub/src/lib/add-collection-item.ts | 2 +- packages/hub/src/lib/cache-management.ts | 6 +- packages/hub/src/lib/check-repo-access.ts | 2 +- packages/hub/src/lib/collection-info.ts | 2 +- packages/hub/src/lib/commit.spec.ts | 14 +- packages/hub/src/lib/commit.ts | 34 ++--- packages/hub/src/lib/count-commits.ts | 2 +- packages/hub/src/lib/create-branch.ts | 2 +- packages/hub/src/lib/create-collection.ts | 2 +- packages/hub/src/lib/create-repo.ts | 14 +- packages/hub/src/lib/dataset-info.ts | 6 +- packages/hub/src/lib/delete-branch.ts | 2 +- .../hub/src/lib/delete-collection-item.ts | 4 +- packages/hub/src/lib/delete-collection.ts | 2 +- packages/hub/src/lib/delete-file.ts | 2 +- packages/hub/src/lib/delete-files.ts | 2 +- packages/hub/src/lib/delete-repo.ts | 2 +- .../lib/download-file-to-cache-dir.spec.ts | 6 +- .../hub/src/lib/download-file-to-cache-dir.ts | 2 +- packages/hub/src/lib/download-file.spec.ts | 2 +- packages/hub/src/lib/download-file.ts | 2 +- packages/hub/src/lib/file-download-info.ts | 2 +- packages/hub/src/lib/file-exists.ts | 4 +- packages/hub/src/lib/list-collections.ts | 2 +- packages/hub/src/lib/list-commits.ts | 2 +- packages/hub/src/lib/list-datasets.ts | 2 +- packages/hub/src/lib/list-files.ts | 2 +- packages/hub/src/lib/list-models.spec.ts | 2 +- packages/hub/src/lib/list-models.ts | 4 +- packages/hub/src/lib/list-spaces.ts | 4 +- packages/hub/src/lib/model-info.ts | 6 +- packages/hub/src/lib/oauth-handle-redirect.ts | 6 +- packages/hub/src/lib/oauth-login-url.ts | 10 +- .../lib/parse-safetensors-metadata.spec.ts | 2 +- .../hub/src/lib/parse-safetensors-metadata.ts | 38 ++--- packages/hub/src/lib/paths-info.ts | 10 +- packages/hub/src/lib/repo-exists.ts | 2 +- .../hub/src/lib/snapshot-download.spec.ts | 12 +- packages/hub/src/lib/snapshot-download.ts | 2 +- packages/hub/src/lib/space-info.ts | 6 +- packages/hub/src/lib/upload-file.spec.ts | 2 +- packages/hub/src/lib/upload-file.ts | 8 +- .../lib/upload-files-with-progress.spec.ts | 4 +- .../hub/src/lib/upload-files-with-progress.ts | 11 +- packages/hub/src/lib/upload-files.spec.ts | 2 +- packages/hub/src/lib/upload-files.ts | 4 +- packages/hub/src/lib/who-am-i.ts | 2 +- packages/hub/src/utils/ChunkCache.ts | 2 +- packages/hub/src/utils/SplicedBlob.spec.ts | 10 +- packages/hub/src/utils/WebBlob.ts | 4 +- packages/hub/src/utils/XetBlob.spec.ts | 60 ++++---- packages/hub/src/utils/XetBlob.ts | 32 ++-- packages/hub/src/utils/combineUint8Arrays.ts | 2 +- packages/hub/src/utils/createBlobs.ts | 4 +- packages/hub/src/utils/createXorbs.ts | 14 +- packages/hub/src/utils/eventToGenerator.ts | 8 +- .../normalizeInferenceProviderMapping.ts | 2 +- packages/hub/src/utils/omit.ts | 2 +- packages/hub/src/utils/pick.ts | 2 +- .../hub/src/utils/promisesQueueStreaming.ts | 2 +- packages/hub/src/utils/sha256-node.ts | 2 +- packages/hub/src/utils/sha256.ts | 6 +- packages/hub/src/utils/sub-paths.ts | 4 +- packages/hub/src/utils/toRepoId.ts | 2 +- packages/hub/src/utils/uploadShards.ts | 8 +- packages/hub/src/utils/xetWriteToken.ts | 2 +- .../src/vendor/hash-wasm/sha256-wrapper.ts | 2 +- packages/hub/src/vendor/lz4js/index.ts | 2 +- packages/hub/src/vendor/type-fest/entries.ts | 19 +-- packages/hub/src/vendor/type-fest/entry.ts | 19 +-- packages/hub/src/vendor/type-fest/except.ts | 7 +- .../hub/src/vendor/xet-chunk/chunker_wasm.ts | 6 +- .../xet-chunk/chunker_wasm_bg.wasm.base64.ts | 2 +- packages/inference/package.json | 70 ++++----- packages/inference/src/InferenceClient.ts | 4 +- packages/inference/src/errors.ts | 2 +- packages/inference/src/lib/getDefaultTask.ts | 2 +- .../src/lib/getInferenceProviderMapping.ts | 22 +-- .../inference/src/lib/getProviderHelper.ts | 74 +++++----- .../inference/src/lib/makeRequestOptions.ts | 22 +-- .../src/providers/black-forest-labs.ts | 6 +- packages/inference/src/providers/fal-ai.ts | 66 ++++----- .../inference/src/providers/featherless-ai.ts | 2 +- .../inference/src/providers/hf-inference.ts | 96 ++++++------ .../inference/src/providers/hyperbolic.ts | 6 +- packages/inference/src/providers/nebius.ts | 2 +- packages/inference/src/providers/novita.ts | 14 +- packages/inference/src/providers/nscale.ts | 4 +- packages/inference/src/providers/ovhcloud.ts | 2 +- .../inference/src/providers/providerHelper.ts | 14 +- packages/inference/src/providers/replicate.ts | 4 +- packages/inference/src/providers/sambanova.ts | 2 +- packages/inference/src/providers/together.ts | 2 +- packages/inference/src/providers/wavespeed.ts | 20 +-- packages/inference/src/providers/zai-org.ts | 14 +- .../src/snippets/getInferenceSnippets.ts | 52 +++---- .../src/tasks/audio/audioClassification.ts | 2 +- .../tasks/audio/automaticSpeechRecognition.ts | 2 +- packages/inference/src/tasks/audio/utils.ts | 2 +- .../inference/src/tasks/custom/request.ts | 4 +- .../src/tasks/custom/streamingRequest.ts | 4 +- .../src/tasks/cv/imageClassification.ts | 2 +- .../src/tasks/cv/imageSegmentation.ts | 2 +- .../inference/src/tasks/cv/textToImage.ts | 10 +- .../inference/src/tasks/cv/textToVideo.ts | 2 +- .../tasks/cv/zeroShotImageClassification.ts | 6 +- .../multimodal/documentQuestionAnswering.ts | 4 +- .../multimodal/visualQuestionAnswering.ts | 2 +- .../inference/src/tasks/nlp/chatCompletion.ts | 2 +- .../src/tasks/nlp/chatCompletionStream.ts | 2 +- .../src/tasks/nlp/featureExtraction.ts | 2 +- .../src/tasks/nlp/questionAnswering.ts | 4 +- .../src/tasks/nlp/sentenceSimilarity.ts | 2 +- .../src/tasks/nlp/tableQuestionAnswering.ts | 4 +- .../src/tasks/nlp/textClassification.ts | 2 +- .../inference/src/tasks/nlp/textGeneration.ts | 2 +- .../src/tasks/nlp/textGenerationStream.ts | 2 +- .../src/tasks/nlp/tokenClassification.ts | 4 +- .../src/tasks/nlp/zeroShotClassification.ts | 4 +- .../tasks/tabular/tabularClassification.ts | 2 +- .../src/tasks/tabular/tabularRegression.ts | 2 +- packages/inference/src/utils/pick.ts | 2 +- packages/inference/src/utils/request.ts | 40 ++--- packages/inference/src/utils/typedEntries.ts | 2 +- .../inference/test/InferenceClient.spec.ts | 138 +++++++++--------- packages/jinja/package.json | 50 +++---- packages/jinja/src/ast.ts | 32 ++-- packages/jinja/src/format.ts | 4 +- packages/jinja/src/lexer.ts | 4 +- packages/jinja/src/runtime.ts | 26 ++-- packages/languages/package.json | 36 ++--- packages/mcp-client/cli.ts | 4 +- packages/mcp-client/package.json | 52 +++---- packages/mcp-client/src/Agent.ts | 2 +- packages/mcp-client/src/McpClient.ts | 8 +- packages/mcp-client/src/ResultFormatter.ts | 6 +- packages/mcp-client/src/utils.ts | 4 +- packages/ollama-utils/package.json | 50 +++---- .../ollama-utils/scripts/generate-automap.ts | 6 +- .../ollama-utils/src/chat-template.spec.ts | 8 +- packages/ollama-utils/src/chat-template.ts | 36 ++--- packages/space-header/package.json | 42 +++--- .../src/header/components/collapse/arrow.ts | 2 +- .../src/header/components/like/heart.ts | 2 +- packages/space-header/src/index.ts | 2 +- packages/tasks-gen/package.json | 18 +-- .../scripts/generate-snippets-fixtures.ts | 10 +- .../tasks-gen/scripts/inference-codegen.ts | 26 ++-- packages/tasks/package.json | 46 +++--- packages/tasks/src/default-widget-inputs.ts | 21 +-- packages/tasks/src/gguf.ts | 2 +- packages/tasks/src/local-apps.ts | 4 +- .../tasks/src/model-libraries-snippets.ts | 30 ++-- packages/tasks/src/snippets/common.ts | 4 +- packages/tasks/src/snippets/inputs.ts | 4 +- .../src/tasks/tabular-regression/about.md | 1 - packages/tasks/src/widget-example.ts | 15 +- packages/tiny-agents/package.json | 50 +++---- packages/tiny-agents/src/cli.ts | 4 +- .../tiny-agents/src/lib/loadConfigFrom.ts | 8 +- packages/tiny-agents/src/lib/webServer.ts | 10 +- 187 files changed, 1163 insertions(+), 1174 deletions(-) diff --git a/e2e/svelte/package.json b/e2e/svelte/package.json index 85d37e1be4..777fd0159b 100644 --- a/e2e/svelte/package.json +++ b/e2e/svelte/package.json @@ -2,7 +2,7 @@ "name": "myapp", "version": "0.0.1", "private": true, - "packageManager": "pnpm@10.10.0", + "type": "module", "scripts": { "dev": "vite dev", "build": "vite build", @@ -11,6 +11,10 @@ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "test:browser": "vitest run --browser.name=chrome --browser.headless" }, + "dependencies": { + "@huggingface/hub": "*", + "@huggingface/inference": "*" + }, "devDependencies": { "@sveltejs/adapter-auto": "^3.2.0", "@sveltejs/kit": "^2.5.9", @@ -23,9 +27,5 @@ "vite": "^5.2.11", "vitest": "^1.6.0" }, - "type": "module", - "dependencies": { - "@huggingface/hub": "*", - "@huggingface/inference": "*" - } + "packageManager": "pnpm@10.10.0" } diff --git a/e2e/ts/package.json b/e2e/ts/package.json index 8fa6ac0822..3124d557cd 100644 --- a/e2e/ts/package.json +++ b/e2e/ts/package.json @@ -2,19 +2,19 @@ "name": "ts", "version": "1.0.0", "description": "", + "keywords": [], + "license": "ISC", + "author": "", "main": "index.js", "scripts": { "start": "tsc && node ./dist/index.js" }, - "keywords": [], - "author": "", - "license": "ISC", + "dependencies": { + "@huggingface/hub": "*", + "@huggingface/inference": "*" + }, "devDependencies": { "@types/node": "^18.16.1", "typescript": "^5.0.4" - }, - "dependencies": { - "@huggingface/inference": "*", - "@huggingface/hub": "*" } } diff --git a/e2e/yarn/package.json b/e2e/yarn/package.json index 9ad62db9d2..577a1615bc 100644 --- a/e2e/yarn/package.json +++ b/e2e/yarn/package.json @@ -1,10 +1,10 @@ { "name": "yarn", "version": "1.0.0", - "main": "index.js", "license": "MIT", + "main": "index.js", "dependencies": { - "@huggingface/inference": "*", - "@huggingface/hub": "*" + "@huggingface/hub": "*", + "@huggingface/inference": "*" } } diff --git a/package.json b/package.json index 17805b321f..6590bbba31 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,7 @@ { - "private": true, "name": "@huggingface/root", + "private": true, "license": "MIT", - "packageManager": "pnpm@10.10.0", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .eslintrc.cjs", "lint:check": "eslint --ext .cjs,.ts .eslintrc.cjs", @@ -29,5 +28,6 @@ "vite": "^5.0.2", "vitest": "^0.34.6", "webdriverio": "^8.6.7" - } + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/agents/package.json b/packages/agents/package.json index cd842dfe53..ea97863f41 100644 --- a/packages/agents/package.json +++ b/packages/agents/package.json @@ -1,14 +1,31 @@ { "name": "@huggingface/agents", - "packageManager": "pnpm@10.10.0", "version": "0.0.5", "description": "Multi-modal agents using Hugging Face's models", + "keywords": [ + "agents", + "api", + "client", + "face", + "hugging", + "huggingface" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" - }, + "source": "index.ts", + "files": [ + "dist", + "index.ts", + "src", + "tsconfig.json" + ], "main": "./dist/index.js", "module": "./dist/index.mjs", + "browser": { + "./dist/index.js": "./dist/browser/index.js", + "./dist/index.mjs": "./dist/browser/index.mjs" + }, "types": "./dist/index.d.ts", "exports": { ".": { @@ -17,14 +34,9 @@ "import": "./dist/index.mjs" } }, - "browser": { - "./dist/index.js": "./dist/browser/index.js", - "./dist/index.mjs": "./dist/browser/index.mjs" - }, - "engines": { - "node": ">=18" + "publishConfig": { + "access": "public" }, - "source": "index.ts", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -36,26 +48,14 @@ "test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest-browser.config.mts", "check": "tsc" }, - "files": [ - "src", - "dist", - "index.ts", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "agents", - "api", - "client", - "hugging", - "face" - ], - "author": "Hugging Face", - "license": "MIT", + "dependencies": { + "@huggingface/inference": "workspace:^" + }, "devDependencies": { "@types/node": "^18.13.0" }, - "dependencies": { - "@huggingface/inference": "workspace:^" - } + "engines": { + "node": ">=18" + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/agents/src/lib/evalBuilder.ts b/packages/agents/src/lib/evalBuilder.ts index ed5de329e0..6f8948ef50 100644 --- a/packages/agents/src/lib/evalBuilder.ts +++ b/packages/agents/src/lib/evalBuilder.ts @@ -7,7 +7,7 @@ export async function evalBuilder( tools: Tool[], files: FileList | undefined, updateCallback: (message: string, data: undefined | string | Blob) => void, - accessToken?: string + accessToken?: string, ): Promise<() => Promise> { async function wrapperEval() { if (files && files.length > 0) { diff --git a/packages/agents/src/lib/generateCode.ts b/packages/agents/src/lib/generateCode.ts index 6b14dd8c07..3d88622d42 100644 --- a/packages/agents/src/lib/generateCode.ts +++ b/packages/agents/src/lib/generateCode.ts @@ -7,7 +7,7 @@ export async function generateCode( prompt: string, tools: Tool[], files: FileList | undefined, - llm: (input: string) => Promise + llm: (input: string) => Promise, ): Promise { const fullprompt = generatePrompt(prompt, [...tools, messageTool], { image: !!files && files[0].type.startsWith("image"), diff --git a/packages/agents/src/lib/promptGeneration.ts b/packages/agents/src/lib/promptGeneration.ts index 0310d5a0e4..edd7d9ad04 100644 --- a/packages/agents/src/lib/promptGeneration.ts +++ b/packages/agents/src/lib/promptGeneration.ts @@ -35,7 +35,7 @@ user: ${example.prompt} function: \`\`\`js ${example.code} -\`\`\`` +\`\`\``, ) .join("\n-------\n"); diff --git a/packages/blob/package.json b/packages/blob/package.json index fc3d8b26d0..04e4c8bf6c 100644 --- a/packages/blob/package.json +++ b/packages/blob/package.json @@ -1,14 +1,31 @@ { "name": "@huggingface/blob", - "packageManager": "pnpm@10.10.0", "version": "0.0.2", "description": "Utilities to convert URLs and files to Blobs, internally used by Hugging Face libs", + "keywords": [ + "blob", + "face", + "hugging", + "huggingface", + "lazy" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" - }, + "source": "index.ts", + "files": [ + "dist", + "index.ts", + "src", + "tsconfig.json" + ], "main": "./dist/index.js", "module": "./dist/index.mjs", + "browser": { + "./src/utils/FileBlob.ts": false, + "./dist/index.js": "./dist/browser/index.js", + "./dist/index.mjs": "./dist/browser/index.mjs" + }, "types": "./dist/index.d.ts", "exports": { ".": { @@ -25,12 +42,9 @@ "import": "./dist/src/utils/FileBlob.mjs" } }, - "browser": { - "./src/utils/FileBlob.ts": false, - "./dist/index.js": "./dist/browser/index.js", - "./dist/index.mjs": "./dist/browser/index.mjs" + "publishConfig": { + "access": "public" }, - "source": "index.ts", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -43,22 +57,8 @@ "test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest-browser.config.mts", "check": "tsc" }, - "files": [ - "src", - "dist", - "index.ts", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "hugging", - "face", - "blob", - "lazy" - ], - "author": "Hugging Face", - "license": "MIT", "devDependencies": { "@types/node": "^20.11.28" - } + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/blob/src/utils/WebBlob.ts b/packages/blob/src/utils/WebBlob.ts index fe35813fe0..3ffba62d5e 100644 --- a/packages/blob/src/utils/WebBlob.ts +++ b/packages/blob/src/utils/WebBlob.ts @@ -69,7 +69,7 @@ export class WebBlob extends Blob { Math.min(this.start + end, this.end), this.contentType, start === 0 && end === this.size ? this.full : false, - this.fetch + this.fetch, ); return slice; diff --git a/packages/dduf/package.json b/packages/dduf/package.json index 91c3dc7b13..20915feef4 100644 --- a/packages/dduf/package.json +++ b/packages/dduf/package.json @@ -1,14 +1,29 @@ { "name": "@huggingface/dduf", - "packageManager": "pnpm@10.10.0", "version": "0.0.2", "description": "Very alpha lib to check DDUF compliance", + "keywords": [ + "dduf", + "face", + "hugging", + "huggingface" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" - }, + "source": "index.ts", + "files": [ + "dist", + "index.ts", + "src", + "tsconfig.json" + ], "main": "./dist/index.js", "module": "./dist/index.mjs", + "browser": { + "./dist/index.js": "./dist/browser/index.js", + "./dist/index.mjs": "./dist/browser/index.mjs" + }, "types": "./dist/index.d.ts", "exports": { ".": { @@ -18,11 +33,9 @@ }, "./package.json": "./package.json" }, - "browser": { - "./dist/index.js": "./dist/browser/index.js", - "./dist/index.mjs": "./dist/browser/index.mjs" + "publishConfig": { + "access": "public" }, - "source": "index.ts", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -35,24 +48,11 @@ "test:browser": "vitest run --browser.name=chrome --browser.headless", "check": "tsc" }, - "files": [ - "src", - "dist", - "index.ts", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "hugging", - "face", - "dduf" - ], - "author": "Hugging Face", - "license": "MIT", + "dependencies": { + "@huggingface/blob": "workspace:^" + }, "devDependencies": { "@types/node": "^20.11.28" }, - "dependencies": { - "@huggingface/blob": "workspace:^" - } + "packageManager": "pnpm@10.10.0" } diff --git a/packages/dduf/src/check-dduf.spec.ts b/packages/dduf/src/check-dduf.spec.ts index a7f44fe7df..3b596c0605 100644 --- a/packages/dduf/src/check-dduf.spec.ts +++ b/packages/dduf/src/check-dduf.spec.ts @@ -5,7 +5,7 @@ describe("check-dduf", () => { it("should work", async () => { const files: DDUFFileEntry[] = []; for await (const file of checkDDUF( - new URL("https://huggingface.co/spaces/DDUF/dduf-check/resolve/main/file-64.dduf") + new URL("https://huggingface.co/spaces/DDUF/dduf-check/resolve/main/file-64.dduf"), )) { files.push(file); } diff --git a/packages/dduf/src/check-dduf.ts b/packages/dduf/src/check-dduf.ts index a4f17a9593..836b4b5b64 100644 --- a/packages/dduf/src/check-dduf.ts +++ b/packages/dduf/src/check-dduf.ts @@ -115,8 +115,8 @@ export async function* checkDDUF(url: Blob | URL, opts?: { log?: (x: string) => centralDirOffset > blob.size - last100kB.byteLength ? last100kB.slice( centralDirOffset - (blob.size - last100kB.byteLength), - centralDirOffset - (blob.size - last100kB.byteLength) + centralDirSize - ) + centralDirOffset - (blob.size - last100kB.byteLength) + centralDirSize, + ) : await blob.slice(centralDirOffset, centralDirOffset + centralDirSize).arrayBuffer(); const centralDirView = new DataView(centralDir); @@ -175,7 +175,7 @@ export async function* checkDDUF(url: Blob | URL, opts?: { log?: (x: string) => const zip64ExtraField = new DataView( centralDir, offset + 46 + filenameLength + extraFieldOffset + 4, - extraFieldSize + extraFieldSize, ); let zip64ExtraFieldOffset = 0; diff --git a/packages/doc-internal/fix-cdn-versions.ts b/packages/doc-internal/fix-cdn-versions.ts index 2a1de7bc82..3893dc47f1 100644 --- a/packages/doc-internal/fix-cdn-versions.ts +++ b/packages/doc-internal/fix-cdn-versions.ts @@ -8,7 +8,7 @@ for (const readme of ["../../README.md", "../../packages/hub/README.md", "../../ content = content.replace( /@huggingface[/]inference@\d+([.]\d+)?([.]\d+)?/g, - `@huggingface/inference@${inferencePackage.version}` + `@huggingface/inference@${inferencePackage.version}`, ); content = content.replace(/@huggingface[/]hub@\d+([.]\d+)?([.]\d+)?/g, `@huggingface/hub@${hubPackage.version}`); diff --git a/packages/doc-internal/fix-md-links.ts b/packages/doc-internal/fix-md-links.ts index 804d76a24a..ab022280df 100644 --- a/packages/doc-internal/fix-md-links.ts +++ b/packages/doc-internal/fix-md-links.ts @@ -13,7 +13,7 @@ for (const mdFile of await glob("**/*.md", { cwd: "../../docs" })) { // Fix links of main page .replaceAll(/\(packages\/[^)]+\)/g, (val) => val.replace("packages/", "")) // When on HF, remove links to HF - .replaceAll(/.*\[full documentation\].*\n\n/g, "") + .replaceAll(/.*\[full documentation\].*\n\n/g, ""), ); } diff --git a/packages/doc-internal/package.json b/packages/doc-internal/package.json index 1346fbcd25..7286dbb614 100644 --- a/packages/doc-internal/package.json +++ b/packages/doc-internal/package.json @@ -1,9 +1,10 @@ { "name": "@huggingface/doc-internal", - "packageManager": "pnpm@10.10.0", "version": "1.0.0", - "description": "Package to generate doc for other @huggingface packages", "private": true, + "description": "Package to generate doc for other @huggingface packages", + "license": "MIT", + "type": "module", "scripts": { "start": "pnpm run fix-cdn-versions && pnpm run doc-hub && pnpm run doc-inference && pnpm run doc-space-header && pnpm run doc-gguf && pnpm run doc-mcp-client && pnpm run doc-tiny-agents && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks", "lint": "eslint --quiet --fix --ext .cjs,.ts .", @@ -21,15 +22,14 @@ "fix-md-links": "tsx fix-md-links.ts", "fix-md-headinghashlinks": "tsx fix-md-headinghashlinks.ts" }, - "type": "module", - "license": "MIT", + "dependencies": { + "glob": "^9.2.1", + "yaml": "^2.2.2" + }, "devDependencies": { "@types/node": "^18.14.5", "typedoc": "^0.25.12", "typedoc-plugin-markdown": "^3.17.1" }, - "dependencies": { - "glob": "^9.2.1", - "yaml": "^2.2.2" - } + "packageManager": "pnpm@10.10.0" } diff --git a/packages/doc-internal/update-toc.ts b/packages/doc-internal/update-toc.ts index af49f55f8d..df6d2efd6e 100644 --- a/packages/doc-internal/update-toc.ts +++ b/packages/doc-internal/update-toc.ts @@ -32,7 +32,7 @@ for (const dir of dirs) { for (const subdir of subdirs) { const files = readdirSync(join("../../docs", dir.name, subdir.name), { withFileTypes: true }).filter((dir) => - dir.isFile() + dir.isFile(), ); const newSection: Section = { diff --git a/packages/gguf/package.json b/packages/gguf/package.json index 3b0724601d..32fced365f 100644 --- a/packages/gguf/package.json +++ b/packages/gguf/package.json @@ -1,18 +1,33 @@ { "name": "@huggingface/gguf", - "packageManager": "pnpm@10.10.0", "version": "0.3.2", "description": "a GGUF parser that works on remotely hosted files", + "keywords": [ + "gguf", + "hub", + "huggingface" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" + "bin": { + "gguf-view": "./dist/cli.js" }, + "source": "index.ts", + "files": [ + "dist", + "src", + "tsconfig.json" + ], "main": "./dist/index.js", "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "bin": { - "gguf-view": "./dist/cli.js" + "browser": { + "./src/cli.ts": false, + "./src/utils/FileBlob.ts": false, + "./dist/index.js": "./dist/browser/index.js", + "./dist/index.mjs": "./dist/browser/index.mjs" }, + "types": "./dist/index.d.ts", "exports": { ".": { "types": "./dist/index.d.ts", @@ -20,16 +35,9 @@ "import": "./dist/index.mjs" } }, - "browser": { - "./src/cli.ts": false, - "./src/utils/FileBlob.ts": false, - "./dist/index.js": "./dist/browser/index.js", - "./dist/index.mjs": "./dist/browser/index.mjs" - }, - "engines": { - "node": ">=20" + "publishConfig": { + "access": "public" }, - "source": "index.ts", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -41,22 +49,14 @@ "test": "vitest run", "check": "tsc" }, - "files": [ - "dist", - "src", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "hub", - "gguf" - ], - "author": "Hugging Face", - "license": "MIT", "dependencies": { "@huggingface/tasks": "workspace:^" }, "devDependencies": { "@types/node": "^20.12.8" - } + }, + "engines": { + "node": ">=20" + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/gguf/scripts/generate-llm.ts b/packages/gguf/scripts/generate-llm.ts index 985d0c5a66..1a3cf1f46b 100644 --- a/packages/gguf/scripts/generate-llm.ts +++ b/packages/gguf/scripts/generate-llm.ts @@ -128,7 +128,7 @@ async function main() { SOURCE_CPP_URLS.map(async (url) => { const res = await fetch(url); return await res.text(); - }) + }), ); const cppSource = cppSources.join("\n"); diff --git a/packages/gguf/src/cli.ts b/packages/gguf/src/cli.ts index eac386d849..36437e68d0 100644 --- a/packages/gguf/src/cli.ts +++ b/packages/gguf/src/cli.ts @@ -74,7 +74,7 @@ async function main() { } strVal = strVal.length > MAX_LEN ? strVal.slice(0, MAX_LEN) + "..." : strVal; return [(i + 1).toString(), count.toString(), `${key} = ${strVal}`]; - }) + }), ); console.log(); @@ -100,7 +100,7 @@ async function main() { ["Overhead", (overhead / 1e9).toFixed(2) + " GB"], ["", "---"], ["TOTAL", (totalMemoryUsage / 1e9).toFixed(2) + " GB"], - ] + ], ); } catch (e) { console.error(`Error: ${(e as Error).message}`); @@ -129,7 +129,7 @@ async function main() { mapDtypeToName[tensorInfo.dtype], tensorInfo.name, ]; - }) + }), ); } else { console.log(); @@ -141,7 +141,7 @@ function calcMemoryUsage( metadata: GGUFParseOutput<{ strict: false }>["metadata"], kvSize: number, kvTypeK: GGMLQuantizationType = GGMLQuantizationType.F16, - kvTypeV: GGMLQuantizationType = GGMLQuantizationType.F16 + kvTypeV: GGMLQuantizationType = GGMLQuantizationType.F16, ) { const arch = metadata["general.architecture"] ?? "unknown"; const n_embd = (metadata[`${arch}.embedding_length`] as number) ?? 0; diff --git a/packages/gguf/src/gguf.spec.ts b/packages/gguf/src/gguf.spec.ts index 2802680a5a..b063bf06b9 100644 --- a/packages/gguf/src/gguf.spec.ts +++ b/packages/gguf/src/gguf.spec.ts @@ -625,7 +625,7 @@ describe("gguf", () => { // Verify the kv_count matches the actual number of KV pairs (excluding built-in fields) const kvPairs = Object.keys(deserializedMetadata).filter( - (key) => !["version", "tensor_count", "kv_count"].includes(key) + (key) => !["version", "tensor_count", "kv_count"].includes(key), ); expect(BigInt(kvPairs.length)).toBe(originalTypedMetadata.kv_count.value); } finally { @@ -677,7 +677,7 @@ describe("gguf", () => { expect(deserializedMetadata["test.float32"].type).toBe(originalTypedMetadata["test.float32"].type); expect(deserializedMetadata["test.float32"].value as number).toBeCloseTo( originalTypedMetadata["test.float32"].value as number, - 5 + 5, ); expect(deserializedMetadata["test.uint64"]).toEqual(originalTypedMetadata["test.uint64"]); expect(deserializedMetadata["test.int64"]).toEqual(originalTypedMetadata["test.int64"]); @@ -873,7 +873,7 @@ describe("gguf", () => { console.log(`✅ Complete header parses successfully!`); console.log( - `📋 Tensor count matches: ${deserializedTensorInfos.length} === ${originalMetadata.tensor_count.value}` + `📋 Tensor count matches: ${deserializedTensorInfos.length} === ${originalMetadata.tensor_count.value}`, ); console.log(`📊 Tensor data offset: ${deserializedOffset}`); @@ -1242,7 +1242,7 @@ describe("gguf", () => { expect(parsedTensorInfos.length).toBe(originalTensorInfos.length); expect(parsedTensorInfos[0]).toEqual(originalTensorInfos[0]); expect(parsedTensorInfos[parsedTensorInfos.length - 1]).toEqual( - originalTensorInfos[originalTensorInfos.length - 1] + originalTensorInfos[originalTensorInfos.length - 1], ); // Verify our custom metadata was added diff --git a/packages/gguf/src/gguf.ts b/packages/gguf/src/gguf.ts index 45362b1575..8c5c9eebe0 100644 --- a/packages/gguf/src/gguf.ts +++ b/packages/gguf/src/gguf.ts @@ -84,7 +84,7 @@ class RangeView { */ fetch?: typeof fetch; additionalFetchHeaders?: Record; - } + }, ) { this.chunk = 0; /// TODO(fix typing) @@ -106,7 +106,7 @@ class RangeView { Range: `bytes=${range[0]}-${range[1]}`, }, }) - ).arrayBuffer() + ).arrayBuffer(), ); this.appendBuffer(buf); this.chunk += 1; @@ -199,7 +199,7 @@ function readMetadataValue( type: GGUFValueType, offset: number, version: Version, - littleEndian: boolean + littleEndian: boolean, ): Slice { switch (type) { case GGUFValueType.UINT8: @@ -248,7 +248,7 @@ export async function gguf( additionalFetchHeaders?: Record; typedMetadata: true; allowLocalFile?: boolean; - } + }, ): Promise; export async function gguf( uri: string, @@ -258,7 +258,7 @@ export async function gguf( typedMetadata: true; computeParametersCount: true; allowLocalFile?: boolean; - } + }, ): Promise; export async function gguf( uri: string, @@ -267,7 +267,7 @@ export async function gguf( additionalFetchHeaders?: Record; computeParametersCount: true; allowLocalFile?: boolean; - } + }, ): Promise; export async function gguf( uri: string, @@ -275,7 +275,7 @@ export async function gguf( fetch?: typeof fetch; additionalFetchHeaders?: Record; allowLocalFile?: boolean; - } + }, ): Promise; export async function gguf( uri: string, @@ -288,7 +288,7 @@ export async function gguf( typedMetadata?: boolean; computeParametersCount?: boolean; allowLocalFile?: boolean; - } + }, ): Promise { let r: RangeView; if (isBackend) { @@ -542,7 +542,7 @@ function writeMetadataValue( type: GGUFValueType, version: Version, littleEndian: boolean, - subType?: GGUFValueType + subType?: GGUFValueType, ): Uint8Array { switch (type) { case GGUFValueType.UINT8: { @@ -678,7 +678,7 @@ export function serializeGgufMetadata( * @default GGUF_DEFAULT_ALIGNMENT (32) */ alignment?: number; - } = {} + } = {}, ): Uint8Array { const littleEndian = options.littleEndian ?? true; const alignment = options.alignment ?? GGUF_DEFAULT_ALIGNMENT; @@ -697,7 +697,7 @@ export function serializeGgufMetadata( // Count key-value pairs (excluding the built-in fields: version, tensor_count, kv_count) const kvEntries = Object.entries(typedMetadata).filter( - ([key]) => !["version", "tensor_count", "kv_count"].includes(key) + ([key]) => !["version", "tensor_count", "kv_count"].includes(key), ); const kvCount = BigInt(kvEntries.length); @@ -728,7 +728,7 @@ export function serializeGgufMetadata( entry.type, version, littleEndian, - "subType" in entry ? entry.subType : undefined + "subType" in entry ? entry.subType : undefined, ); kvBytes.push(valueBytes); } @@ -795,7 +795,7 @@ export async function buildGgufHeader( tensorInfoByteRange: [number, number]; /** Alignment for tensor data (default: GGUF_DEFAULT_ALIGNMENT (32)) */ alignment?: number; - } + }, ): Promise { const alignment = options.alignment ?? GGUF_DEFAULT_ALIGNMENT; const version = updatedMetadata.version.value; @@ -854,7 +854,7 @@ export async function ggufAllShards( additionalFetchHeaders?: Record; parallelDownloads?: number; allowLocalFile?: boolean; - } + }, ): Promise<{ shards: GGUFParseOutput[]; parameterCount: number }> { const parallelDownloads = params?.parallelDownloads ?? PARALLEL_DOWNLOADS; if (parallelDownloads < 1) { @@ -872,7 +872,7 @@ export async function ggufAllShards( const shards = await promisesQueue( urls.map((shardUrl) => () => gguf(shardUrl, { ...params, computeParametersCount: true })), - parallelDownloads + parallelDownloads, ); return { shards, @@ -884,7 +884,7 @@ export async function ggufAllShards( { ...params, computeParametersCount: true, - } + }, ); return { shards: [{ metadata, tensorInfos, tensorDataOffset, littleEndian, tensorInfoByteRange }], parameterCount }; } diff --git a/packages/hub/cli.ts b/packages/hub/cli.ts index 3015d9ffb9..9559ed707b 100644 --- a/packages/hub/cli.ts +++ b/packages/hub/cli.ts @@ -36,7 +36,7 @@ class UploadProgressManager { barCompleteChar: "\u2588", barIncompleteChar: "\u2591", }, - cliProgress.Presets.shades_grey + cliProgress.Presets.shades_grey, ); } catch (error) { // cli-progress is not available, fall back to simple logging @@ -388,11 +388,11 @@ async function run() { `Hugging Face CLI Tools (hfjs)\n\nAvailable commands:\n\n` + typedEntries(commands) .map(([name, def]) => ` ${usage(name)}: ${def.description}`) - .join("\n") + .join("\n"), ); console.log("\nTo get help on a specific command, run `hfjs help ` or `hfjs --help`"); console.log( - "For commands with subcommands (like 'branch'), run `hfjs help ` or `hfjs --help`" + "For commands with subcommands (like 'branch'), run `hfjs help ` or `hfjs --help`", ); if (mainCommandName === undefined) { process.exitCode = 1; @@ -443,7 +443,7 @@ async function run() { content: pathToFileURL(localFolder), path: join(pathInRepo, `${basename(localFolder)}`).replace(/^[.]?\//, ""), }, - ] + ] : [{ content: pathToFileURL(localFolder), path: pathInRepo.replace(/^[.]?\//, "") }]; const progressManager = new UploadProgressManager(!!quiet); @@ -598,7 +598,7 @@ async function run() { `\nAvailable commands:\n\n` + typedEntries(commands) .map(([name, def]) => ` ${usage(name)}: ${def.description}`) - .join("\n") + .join("\n"), ); console.log("\nTo get help on a specific command, run `hfjs help ` or `hfjs --help`"); process.exitCode = 1; @@ -667,8 +667,8 @@ function _detailedUsage(args: readonly ArgDef[], usageLine: string, commandDescr const valueHint = arg.enum ? `{${arg.enum.join("|")}}` : arg.boolean - ? "" - : `<${arg.name.toUpperCase().replace(/-/g, "_")}>`; + ? "" + : `<${arg.name.toUpperCase().replace(/-/g, "_")}>`; ret += ` ${nameAndAlias}${valueHint ? " " + valueHint : ""}\t${arg.description}${ arg.default !== undefined ? ` (default: ${typeof arg.default === "function" ? arg.default() : arg.default})` @@ -690,7 +690,7 @@ function detailedUsageForCommand(commandName: TopLevelCommandName): string { function detailedUsageForSubcommand( commandName: TopLevelCommandName, - subCommandName: keyof CommandGroup["subcommands"] + subCommandName: keyof CommandGroup["subcommands"], ): string { const commandGroup = commands[commandName]; if (!("subcommands" in commandGroup) || !(subCommandName in commandGroup.subcommands)) { @@ -715,16 +715,16 @@ type ParsedArgsResult = { [K in TArgsDef[number] as Camelize]: K["boolean"] extends true ? boolean : K["required"] extends true - ? string - : K["default"] extends undefined - ? string | undefined // Optional strings without default can be undefined - : string; // Strings with default or required are strings + ? string + : K["default"] extends undefined + ? string | undefined // Optional strings without default can be undefined + : string; // Strings with default or required are strings }; function advParseArgs( args: string[], argDefs: TArgsDef, - commandNameForError: string + commandNameForError: string, ): ParsedArgsResult { const { tokens } = parseArgs({ options: Object.fromEntries( @@ -739,7 +739,7 @@ function advParseArgs( }), }; return [arg.name, optionConfig]; - }) + }), ), args, allowPositionals: true, @@ -754,8 +754,8 @@ function advParseArgs( throw new Error( `Command '${commandNameForError}': Missing required positional arguments. Usage: hfjs ${usage( commandNameForError.split(" ")[0] as TopLevelCommandName, - commandNameForError.split(" ")[1] - )}` + commandNameForError.split(" ")[1], + )}`, ); } @@ -763,8 +763,8 @@ function advParseArgs( throw new Error( `Command '${commandNameForError}': Too many positional arguments. Usage: hfjs ${usage( commandNameForError.split(" ")[0] as TopLevelCommandName, - commandNameForError.split(" ")[1] - )}` + commandNameForError.split(" ")[1], + )}`, ); } @@ -805,7 +805,7 @@ function advParseArgs( throw new Error( `Command '${commandNameForError}': Invalid value '${token.value}' for option ${ token.rawName - }. Expected one of: ${argDef.enum.join(", ")}` + }. Expected one of: ${argDef.enum.join(", ")}`, ); } result[argDef.name] = token.value; @@ -820,7 +820,7 @@ function advParseArgs( } return Object.fromEntries( - Object.entries(result).map(([name, val]) => [kebabToCamelCase(name), val]) + Object.entries(result).map(([name, val]) => [kebabToCamelCase(name), val]), ) as ParsedArgsResult; } diff --git a/packages/hub/package.json b/packages/hub/package.json index 69acc41e56..e95d972a02 100644 --- a/packages/hub/package.json +++ b/packages/hub/package.json @@ -1,22 +1,30 @@ { "name": "@huggingface/hub", - "packageManager": "pnpm@10.10.0", "version": "2.7.2", "description": "Utilities to interact with the Hugging Face hub", + "keywords": [ + "api", + "client", + "face", + "hub", + "hugging", + "huggingface" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" + "bin": { + "hfjs": "./dist/cli.js" }, + "source": "index.ts", + "files": [ + "dist", + "index.ts", + "src", + "tsconfig.json" + ], "main": "./dist/index.js", "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "exports": { - ".": { - "types": "./dist/index.d.ts", - "require": "./dist/index.js", - "import": "./dist/index.mjs" - } - }, "browser": { "./src/utils/sha256-node.ts": false, "./src/utils/sub-paths.ts": false, @@ -27,10 +35,17 @@ "./dist/index.js": "./dist/browser/index.js", "./dist/index.mjs": "./dist/browser/index.mjs" }, - "engines": { - "node": ">=18" + "types": "./dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js", + "import": "./dist/index.mjs" + } + }, + "publishConfig": { + "access": "public" }, - "source": "index.ts", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -46,32 +61,17 @@ "bench": "tsx scripts/bench.ts", "debug-xet": "tsx scripts/debug-xet.ts" }, - "files": [ - "src", - "dist", - "index.ts", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "hub", - "api", - "client", - "hugging", - "face" - ], - "bin": { - "hfjs": "./dist/cli.js" - }, - "author": "Hugging Face", - "license": "MIT", "dependencies": { "@huggingface/tasks": "workspace:^" }, + "devDependencies": { + "@types/cli-progress": "^3.11.6" + }, "optionalDependencies": { "cli-progress": "^3.12.0" }, - "devDependencies": { - "@types/cli-progress": "^3.11.6" - } + "engines": { + "node": ">=18" + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/hub/scripts/debug-xet.ts b/packages/hub/scripts/debug-xet.ts index 037baae14f..edd92054e4 100644 --- a/packages/hub/scripts/debug-xet.ts +++ b/packages/hub/scripts/debug-xet.ts @@ -98,7 +98,7 @@ function createDebugFetch(args: { debugDir: string; replay?: boolean }): { // Compare all bytes except footer bytes 104-112 (9 bytes from positions 104-112 inclusive) const footerStart = Number( - new DataView(localData.buffer).getBigUint64(localData.buffer.byteLength - 8, true) + new DataView(localData.buffer).getBigUint64(localData.buffer.byteLength - 8, true), ); // This is the shard timestamp const toIgnoreStart = footerStart + 104; @@ -303,7 +303,7 @@ async function main() { }; console.log( - `\n=== Starting debug upload for ${filePaths.length > 1 ? `${filePaths.length} files` : basename(filePaths[0])} ===` + `\n=== Starting debug upload for ${filePaths.length > 1 ? `${filePaths.length} files` : basename(filePaths[0])} ===`, ); if (args.replay) { console.log("🔄 Replay mode: Using local dedup info when available"); diff --git a/packages/hub/src/error.ts b/packages/hub/src/error.ts index 0da5b2dd96..9c3c675d87 100644 --- a/packages/hub/src/error.ts +++ b/packages/hub/src/error.ts @@ -2,7 +2,7 @@ import type { JsonObject } from "./vendor/type-fest/basic"; export async function createApiError( response: Response, - opts?: { requestId?: string; message?: string } + opts?: { requestId?: string; message?: string }, ): Promise { const error = new HubApiError(response.url, response.status, response.headers.get("X-Request-Id") ?? opts?.requestId); diff --git a/packages/hub/src/lib/add-collection-item.ts b/packages/hub/src/lib/add-collection-item.ts index edcc8776c3..27e926bca9 100644 --- a/packages/hub/src/lib/add-collection-item.ts +++ b/packages/hub/src/lib/add-collection-item.ts @@ -25,7 +25,7 @@ export async function addCollectionItem( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { if (!params.slug) { throw new TypeError("slug is required"); diff --git a/packages/hub/src/lib/cache-management.ts b/packages/hub/src/lib/cache-management.ts index 84b6640779..e658bc7138 100644 --- a/packages/hub/src/lib/cache-management.ts +++ b/packages/hub/src/lib/cache-management.ts @@ -75,7 +75,7 @@ export async function scanCacheDir(cacheDir: string | undefined = undefined): Pr const s = await stat(cacheDir); if (!s.isDirectory()) { throw new Error( - `Scan cache expects a directory but found a file: ${cacheDir}. Please use \`cacheDir\` argument or set \`HF_HUB_CACHE\` environment variable.` + `Scan cache expects a directory but found a file: ${cacheDir}. Please use \`cacheDir\` argument or set \`HF_HUB_CACHE\` environment variable.`, ); } @@ -175,7 +175,7 @@ export async function scanCachedRepo(repoPath: string): Promise // Verify that all refs refer to a valid revision if (refsByHash.size > 0) { throw new Error( - `Reference(s) refer to missing commit hashes: ${JSON.stringify(Object.fromEntries(refsByHash))} (${repoPath})` + `Reference(s) refer to missing commit hashes: ${JSON.stringify(Object.fromEntries(refsByHash))} (${repoPath})`, ); } @@ -219,7 +219,7 @@ export async function scanRefsDir(refsPath: string, refsByHash: Map + blobStats: Map, ): Promise { const files = await readdir(revisionPath, { withFileTypes: true }); for (const file of files) { diff --git a/packages/hub/src/lib/check-repo-access.ts b/packages/hub/src/lib/check-repo-access.ts index 3107c9bd7e..4c997291b4 100644 --- a/packages/hub/src/lib/check-repo-access.ts +++ b/packages/hub/src/lib/check-repo-access.ts @@ -15,7 +15,7 @@ export async function checkRepoAccess( repo: RepoDesignation; hubUrl?: string; fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { const accessToken = params && checkCredentials(params); const repoId = toRepoId(params.repo); diff --git a/packages/hub/src/lib/collection-info.ts b/packages/hub/src/lib/collection-info.ts index 376c18ad8b..ce46e0ceba 100644 --- a/packages/hub/src/lib/collection-info.ts +++ b/packages/hub/src/lib/collection-info.ts @@ -15,7 +15,7 @@ export async function collectionInfo( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { const accessToken = checkCredentials(params); diff --git a/packages/hub/src/lib/commit.spec.ts b/packages/hub/src/lib/commit.spec.ts index 024155bbc7..1e59201c3e 100644 --- a/packages/hub/src/lib/commit.spec.ts +++ b/packages/hub/src/lib/commit.spec.ts @@ -16,7 +16,7 @@ const lfsContent = "O123456789".repeat(100_000); describe("commit", () => { it("should commit to a repo with blobs", async function () { const tokenizerJsonUrl = new URL( - "https://huggingface.co/spaces/aschen/push-model-from-web/raw/main/mobilenet/model.json" + "https://huggingface.co/spaces/aschen/push-model-from-web/raw/main/mobilenet/model.json", ); const repoName = `${TEST_USER}/TEST-${insecureRandomString()}`; const repo: RepoId = { @@ -43,7 +43,7 @@ describe("commit", () => { path: "tsconfig.json", content: (await import("node:url")).pathToFileURL("./tsconfig.json") as URL, }, - ]; + ]; await commit({ repo, @@ -91,14 +91,14 @@ describe("commit", () => { version https://git-lfs.github.com/spec/v1 oid sha256:a3bbce7ee1df7233d85b5f4d60faa3755f93f537804f8b540c72b0739239ddf8 size ${lfsContent.length} - `.trim() + `.trim(), ); if (!isFrontend) { const fileUrlContent = await downloadFile({ repo, path: "tsconfig.json", hubUrl: TEST_HUB_URL }); assert.strictEqual( await fileUrlContent?.text(), - (await import("node:fs")).readFileSync("./tsconfig.json", "utf-8") + (await import("node:fs")).readFileSync("./tsconfig.json", "utf-8"), ); } @@ -149,7 +149,7 @@ size ${lfsContent.length} // upload remote file content: new URL(file), }; - }) + }), ); await commit({ repo, @@ -178,7 +178,7 @@ size ${lfsContent.length} version https://git-lfs.github.com/spec/v1 oid sha256:3fb621eb9b37478239504ee083042d5b18699e8b8618e569478b03b119a85a69 size 4194304 - `.trim() + `.trim(), ); } finally { await deleteRepo({ @@ -249,7 +249,7 @@ size 4194304 { operation: "addOrUpdate", content: new URL( - `https://huggingface.co/spaces/huggingfacejs/push-model-from-web/resolve/main/mobilenet/group1-shard1of2` + `https://huggingface.co/spaces/huggingfacejs/push-model-from-web/resolve/main/mobilenet/group1-shard1of2`, ), path: "mobilenet/group1-shard1of2", }, diff --git a/packages/hub/src/lib/commit.ts b/packages/hub/src/lib/commit.ts index ae0c974143..ae842373b7 100644 --- a/packages/hub/src/lib/commit.ts +++ b/packages/hub/src/lib/commit.ts @@ -199,7 +199,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator ({ insert: splice.content, start: splice.start, end: splice.end })) + operation.edits.map((splice) => ({ insert: splice.content, start: splice.start, end: splice.end })), ); return { operation: "addOrUpdate" as const, @@ -229,7 +229,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator lfsShas.has(op.path)), - 100 + 100, )) { const shas = yield* eventToGenerator< { event: "fileProgress"; state: "hashing"; path: string; progress: number }, @@ -301,7 +301,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator returnCallback(undefined), rejectCallback) + }), + ).then(() => returnCallback(undefined), rejectCallback), ); } else { // No LFS file to upload @@ -542,7 +542,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator (params.fetch ?? fetch)( `${params.hubUrl ?? HUB_URL}/api/${repoId.type}s/${repoId.name}/commit/${encodeURIComponent( - params.branch ?? "main" + params.branch ?? "main", )}` + (params.isPullRequest ? "?create_pr=1" : ""), { method: "POST", @@ -660,7 +660,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator JSON.stringify(x)) @@ -685,7 +685,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator { if (!res.ok) { @@ -703,7 +703,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator + } & Partial, ): Promise { const accessToken = checkCredentials(params); const repoId = toRepoId(params.repo); diff --git a/packages/hub/src/lib/create-branch.ts b/packages/hub/src/lib/create-branch.ts index 100e4d1b94..41dd204ee3 100644 --- a/packages/hub/src/lib/create-branch.ts +++ b/packages/hub/src/lib/create-branch.ts @@ -45,7 +45,7 @@ export async function createBranch(params: { ...(params.empty && { emptyBranch: true }), overwrite: params.overwrite, }), - } + }, ); if (!res.ok) { diff --git a/packages/hub/src/lib/create-collection.ts b/packages/hub/src/lib/create-collection.ts index 7cbe41fb65..97f1a626d9 100644 --- a/packages/hub/src/lib/create-collection.ts +++ b/packages/hub/src/lib/create-collection.ts @@ -12,7 +12,7 @@ export async function createCollection( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise<{ slug: string }> { const accessToken = checkCredentials(params); diff --git a/packages/hub/src/lib/create-repo.ts b/packages/hub/src/lib/create-repo.ts index b3a9e7be11..094d454777 100644 --- a/packages/hub/src/lib/create-repo.ts +++ b/packages/hub/src/lib/create-repo.ts @@ -25,7 +25,7 @@ export async function createRepo( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & CredentialsParams + } & CredentialsParams, ): Promise<{ repoUrl: string }> { const accessToken = checkCredentials(params); const repoId = toRepoId(params.repo); @@ -33,7 +33,7 @@ export async function createRepo( if (!namespace || !repoName) { throw new TypeError( - `"${repoId.name}" is not a fully qualified repo name. It should be of the form "{namespace}/{repoName}".` + `"${repoId.name}" is not a fully qualified repo name. It should be of the form "{namespace}/{repoName}".`, ); } @@ -48,20 +48,20 @@ export async function createRepo( ? { type: "space", sdk: params.sdk ?? "static", - } + } : { type: repoId.type, - }), + }), files: params.files ? await Promise.all( params.files.map(async (file) => ({ encoding: "base64", path: file.path, content: base64FromBytes( - new Uint8Array(file.content instanceof Blob ? await file.content.arrayBuffer() : file.content) + new Uint8Array(file.content instanceof Blob ? await file.content.arrayBuffer() : file.content), ), - })) - ) + })), + ) : undefined, } satisfies ApiCreateRepoPayload), headers: { diff --git a/packages/hub/src/lib/dataset-info.ts b/packages/hub/src/lib/dataset-info.ts index 9253546845..fe34334d69 100644 --- a/packages/hub/src/lib/dataset-info.ts +++ b/packages/hub/src/lib/dataset-info.ts @@ -21,7 +21,7 @@ export async function datasetInfo< * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise> { const accessToken = params && checkCredentials(params); @@ -32,13 +32,13 @@ export async function datasetInfo< const response = await (params.fetch || fetch)( `${params?.hubUrl || HUB_URL}/api/datasets/${params.name}/revision/${encodeURIComponent( - params.revision ?? "HEAD" + params.revision ?? "HEAD", )}?${search.toString()}`, { headers: { ...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}), }, - } + }, ); if (!response.ok) { diff --git a/packages/hub/src/lib/delete-branch.ts b/packages/hub/src/lib/delete-branch.ts index 70227b185e..76072f2fe2 100644 --- a/packages/hub/src/lib/delete-branch.ts +++ b/packages/hub/src/lib/delete-branch.ts @@ -23,7 +23,7 @@ export async function deleteBranch(params: { Authorization: `Bearer ${params.accessToken}`, }), }, - } + }, ); if (!res.ok) { diff --git a/packages/hub/src/lib/delete-collection-item.ts b/packages/hub/src/lib/delete-collection-item.ts index ca7a51f9ad..4678514f1a 100644 --- a/packages/hub/src/lib/delete-collection-item.ts +++ b/packages/hub/src/lib/delete-collection-item.ts @@ -19,7 +19,7 @@ export async function deleteCollectionItem( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { const accessToken = checkCredentials(params); @@ -31,7 +31,7 @@ export async function deleteCollectionItem( Authorization: `Bearer ${accessToken}`, "Content-Type": "application/json", }, - } + }, ); if (!res.ok) { diff --git a/packages/hub/src/lib/delete-collection.ts b/packages/hub/src/lib/delete-collection.ts index d04d7bf415..1bffe064ac 100644 --- a/packages/hub/src/lib/delete-collection.ts +++ b/packages/hub/src/lib/delete-collection.ts @@ -14,7 +14,7 @@ export async function deleteCollection( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { if (!params.slug) { throw new TypeError("slug is required"); diff --git a/packages/hub/src/lib/delete-file.ts b/packages/hub/src/lib/delete-file.ts index 58b19f1983..60f7ee38ba 100644 --- a/packages/hub/src/lib/delete-file.ts +++ b/packages/hub/src/lib/delete-file.ts @@ -13,7 +13,7 @@ export function deleteFile( branch?: CommitParams["branch"]; isPullRequest?: CommitParams["isPullRequest"]; parentCommit?: CommitParams["parentCommit"]; - } & CredentialsParams + } & CredentialsParams, ): Promise { return commit({ ...(params.accessToken ? { accessToken: params.accessToken } : { credentials: params.credentials }), diff --git a/packages/hub/src/lib/delete-files.ts b/packages/hub/src/lib/delete-files.ts index 956bd473e4..fa4b3b5777 100644 --- a/packages/hub/src/lib/delete-files.ts +++ b/packages/hub/src/lib/delete-files.ts @@ -13,7 +13,7 @@ export function deleteFiles( isPullRequest?: CommitParams["isPullRequest"]; parentCommit?: CommitParams["parentCommit"]; fetch?: CommitParams["fetch"]; - } & CredentialsParams + } & CredentialsParams, ): Promise { return commit({ ...(params.accessToken ? { accessToken: params.accessToken } : { credentials: params.credentials }), diff --git a/packages/hub/src/lib/delete-repo.ts b/packages/hub/src/lib/delete-repo.ts index 7b34d1b8e9..4a7e672154 100644 --- a/packages/hub/src/lib/delete-repo.ts +++ b/packages/hub/src/lib/delete-repo.ts @@ -12,7 +12,7 @@ export async function deleteRepo( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & CredentialsParams + } & CredentialsParams, ): Promise { const accessToken = checkCredentials(params); const repoId = toRepoId(params.repo); diff --git a/packages/hub/src/lib/download-file-to-cache-dir.spec.ts b/packages/hub/src/lib/download-file-to-cache-dir.spec.ts index fb407c4c2e..22213418dc 100644 --- a/packages/hub/src/lib/download-file-to-cache-dir.spec.ts +++ b/packages/hub/src/lib/download-file-to-cache-dir.spec.ts @@ -57,7 +57,7 @@ function _getSnapshotFile(params: { getRepoFolderName(toRepoId(params.repo)), "snapshots", params.revision, - params.path + params.path, ); } @@ -73,7 +73,7 @@ describe("downloadFileToCacheDir", () => { etag: DUMMY_ETAG, "Content-Range": "bytes 0-54/55", }, - }) + }), ); // prevent to use caching @@ -95,7 +95,7 @@ describe("downloadFileToCacheDir", () => { repo: DUMMY_REPO, paths: ["/README.md"], fetch: fetchMock, - }) + }), ); }); diff --git a/packages/hub/src/lib/download-file-to-cache-dir.ts b/packages/hub/src/lib/download-file-to-cache-dir.ts index a7b67d9d21..89ca83b56a 100644 --- a/packages/hub/src/lib/download-file-to-cache-dir.ts +++ b/packages/hub/src/lib/download-file-to-cache-dir.ts @@ -64,7 +64,7 @@ export async function downloadFileToCacheDir( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { // get revision provided or default to main const revision = params.revision ?? "main"; diff --git a/packages/hub/src/lib/download-file.spec.ts b/packages/hub/src/lib/download-file.spec.ts index c25a8b69b8..6e71558710 100644 --- a/packages/hub/src/lib/download-file.spec.ts +++ b/packages/hub/src/lib/download-file.spec.ts @@ -28,7 +28,7 @@ license: mit # GPT-2 -Test the whole generation capabilities here: https://transformer.huggingface.co/doc/gpt2-large`) +Test the whole generation capabilities here: https://transformer.huggingface.co/doc/gpt2-large`), ); }); test("should downoad xet file", async () => { diff --git a/packages/hub/src/lib/download-file.ts b/packages/hub/src/lib/download-file.ts index 5174bc09da..ff223f64a8 100644 --- a/packages/hub/src/lib/download-file.ts +++ b/packages/hub/src/lib/download-file.ts @@ -43,7 +43,7 @@ export async function downloadFile( * Can save an http request if provided */ downloadInfo?: FileDownloadInfoOutput; - } & Partial + } & Partial, ): Promise { const accessToken = checkCredentials(params); diff --git a/packages/hub/src/lib/file-download-info.ts b/packages/hub/src/lib/file-download-info.ts index 6ff4f6cebb..1ed6f938ae 100644 --- a/packages/hub/src/lib/file-download-info.ts +++ b/packages/hub/src/lib/file-download-info.ts @@ -44,7 +44,7 @@ export async function fileDownloadInfo( * So that on browsers you can use the URL in an iframe for example */ noContentDisposition?: boolean; - } & Partial + } & Partial, ): Promise { const accessToken = checkCredentials(params); const repoId = toRepoId(params.repo); diff --git a/packages/hub/src/lib/file-exists.ts b/packages/hub/src/lib/file-exists.ts index 64acf1dd39..12f67d60fe 100644 --- a/packages/hub/src/lib/file-exists.ts +++ b/packages/hub/src/lib/file-exists.ts @@ -14,14 +14,14 @@ export async function fileExists( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { const accessToken = checkCredentials(params); const repoId = toRepoId(params.repo); const hubUrl = params.hubUrl ?? HUB_URL; const url = `${hubUrl}/${repoId.type === "model" ? "" : `${repoId.type}s/`}${repoId.name}/raw/${encodeURIComponent( - params.revision ?? "main" + params.revision ?? "main", )}/${params.path}`; const resp = await (params.fetch ?? fetch)(url, { diff --git a/packages/hub/src/lib/list-collections.ts b/packages/hub/src/lib/list-collections.ts index d35c02badd..613499cad3 100644 --- a/packages/hub/src/lib/list-collections.ts +++ b/packages/hub/src/lib/list-collections.ts @@ -40,7 +40,7 @@ export async function* listCollections( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): AsyncGenerator { const accessToken = params && checkCredentials(params); diff --git a/packages/hub/src/lib/list-commits.ts b/packages/hub/src/lib/list-commits.ts index 2bbcc99f71..4d641eb630 100644 --- a/packages/hub/src/lib/list-commits.ts +++ b/packages/hub/src/lib/list-commits.ts @@ -30,7 +30,7 @@ export async function* listCommits( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): AsyncGenerator { const accessToken = checkCredentials(params); const repoId = toRepoId(params.repo); diff --git a/packages/hub/src/lib/list-datasets.ts b/packages/hub/src/lib/list-datasets.ts index fecfa8c321..8198b6786f 100644 --- a/packages/hub/src/lib/list-datasets.ts +++ b/packages/hub/src/lib/list-datasets.ts @@ -66,7 +66,7 @@ export async function* listDatasets< * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): AsyncGenerator> { const accessToken = params && checkCredentials(params); let totalToFetch = params?.limit ?? Infinity; diff --git a/packages/hub/src/lib/list-files.ts b/packages/hub/src/lib/list-files.ts index 2bf76f7817..648a6463a9 100644 --- a/packages/hub/src/lib/list-files.ts +++ b/packages/hub/src/lib/list-files.ts @@ -61,7 +61,7 @@ export async function* listFiles( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): AsyncGenerator { const accessToken = checkCredentials(params); const repoId = toRepoId(params.repo); diff --git a/packages/hub/src/lib/list-models.spec.ts b/packages/hub/src/lib/list-models.spec.ts index be5a43c733..8734c48d1e 100644 --- a/packages/hub/src/lib/list-models.spec.ts +++ b/packages/hub/src/lib/list-models.spec.ts @@ -108,7 +108,7 @@ describe("listModels", () => { count++; if (Array.isArray(entry.inferenceProviderMapping)) { expect( - entry.inferenceProviderMapping.filter(({ provider }) => inferenceProviders.includes(provider)).length + entry.inferenceProviderMapping.filter(({ provider }) => inferenceProviders.includes(provider)).length, ).toBeGreaterThan(0); } } diff --git a/packages/hub/src/lib/list-models.ts b/packages/hub/src/lib/list-models.ts index 39e5468900..3a55a1cd6c 100644 --- a/packages/hub/src/lib/list-models.ts +++ b/packages/hub/src/lib/list-models.ts @@ -83,7 +83,7 @@ export async function* listModels< * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): AsyncGenerator> { const accessToken = params && checkCredentials(params); let totalToFetch = params?.limit ?? Infinity; @@ -127,7 +127,7 @@ export async function* listModels< ) { normalizedItem.inferenceProviderMapping = normalizeInferenceProviderMapping( item.id, - item.inferenceProviderMapping + item.inferenceProviderMapping, ); } diff --git a/packages/hub/src/lib/list-spaces.ts b/packages/hub/src/lib/list-spaces.ts index a14e7e301a..6ab56ff674 100644 --- a/packages/hub/src/lib/list-spaces.ts +++ b/packages/hub/src/lib/list-spaces.ts @@ -62,7 +62,7 @@ export async function* listSpaces< * Additional fields to fetch from huggingface.co. */ additionalFields?: T[]; - } & Partial + } & Partial, ): AsyncGenerator> { const accessToken = params && checkCredentials(params); const search = new URLSearchParams([ @@ -73,7 +73,7 @@ export async function* listSpaces< }), ...(params?.search?.tags?.map((tag) => ["filter", tag]) ?? []), ...[...SPACE_EXPAND_KEYS, ...(params?.additionalFields ?? [])].map( - (val) => ["expand", val] satisfies [string, string] + (val) => ["expand", val] satisfies [string, string], ), ]).toString(); let url: string | undefined = `${params?.hubUrl || HUB_URL}/api/spaces?${search}`; diff --git a/packages/hub/src/lib/model-info.ts b/packages/hub/src/lib/model-info.ts index 247f7e7c32..413d81a334 100644 --- a/packages/hub/src/lib/model-info.ts +++ b/packages/hub/src/lib/model-info.ts @@ -22,7 +22,7 @@ export async function modelInfo< * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise> { const accessToken = params && checkCredentials(params); @@ -33,13 +33,13 @@ export async function modelInfo< const response = await (params.fetch || fetch)( `${params?.hubUrl || HUB_URL}/api/models/${params.name}/revision/${encodeURIComponent( - params.revision ?? "HEAD" + params.revision ?? "HEAD", )}?${search.toString()}`, { headers: { ...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}), }, - } + }, ); if (!response.ok) { diff --git a/packages/hub/src/lib/oauth-handle-redirect.ts b/packages/hub/src/lib/oauth-handle-redirect.ts index d0cf74da9c..d7ad7e5bae 100644 --- a/packages/hub/src/lib/oauth-handle-redirect.ts +++ b/packages/hub/src/lib/oauth-handle-redirect.ts @@ -149,7 +149,7 @@ export async function oauthHandleRedirect(opts?: { } if (typeof localStorage === "undefined" && (!opts?.nonce || !opts?.codeVerifier)) { throw new Error( - "oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier" + "oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier", ); } @@ -319,7 +319,7 @@ export async function oauthHandleRedirectIfPresent(opts?: { } if (typeof localStorage === "undefined" && (!opts?.nonce || !opts?.codeVerifier)) { throw new Error( - "oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier" + "oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier", ); } const searchParams = new URLSearchParams(opts?.redirectedUrl ?? window.location.search); @@ -331,7 +331,7 @@ export async function oauthHandleRedirectIfPresent(opts?: { if (searchParams.has("code")) { if (!localStorage.getItem("huggingface.co:oauth:nonce")) { console.warn( - "Missing oauth nonce from localStorage. This can happen when the user refreshes the page after logging in, without changing the URL." + "Missing oauth nonce from localStorage. This can happen when the user refreshes the page after logging in, without changing the URL.", ); return false; } diff --git a/packages/hub/src/lib/oauth-login-url.ts b/packages/hub/src/lib/oauth-login-url.ts index 0594d09a13..a7ba0b1cda 100644 --- a/packages/hub/src/lib/oauth-login-url.ts +++ b/packages/hub/src/lib/oauth-login-url.ts @@ -80,7 +80,7 @@ export async function oauthLoginUrl(opts?: { } if (typeof localStorage === "undefined" && !opts?.localStorage) { throw new Error( - "oauthLogin requires localStorage to be available in the context, unless you provide a localStorage empty object as argument" + "oauthLogin requires localStorage to be available in the context, unless you provide a localStorage empty object as argument", ); } @@ -109,12 +109,12 @@ export async function oauthLoginUrl(opts?: { if (opts?.localStorage) { if (opts.localStorage.codeVerifier !== undefined && opts.localStorage.codeVerifier !== null) { throw new Error( - "localStorage.codeVerifier must be initially set to null or undefined, and will be filled by oauthLoginUrl" + "localStorage.codeVerifier must be initially set to null or undefined, and will be filled by oauthLoginUrl", ); } if (opts.localStorage.nonce !== undefined && opts.localStorage.nonce !== null) { throw new Error( - "localStorage.nonce must be initially set to null or undefined, and will be filled by oauthLoginUrl" + "localStorage.nonce must be initially set to null or undefined, and will be filled by oauthLoginUrl", ); } opts.localStorage.codeVerifier = newCodeVerifier; @@ -136,7 +136,7 @@ export async function oauthLoginUrl(opts?: { const variables: Record | null = // @ts-expect-error window.huggingface is defined inside static Spaces. - typeof window !== "undefined" ? window.huggingface?.variables ?? null : null; + typeof window !== "undefined" ? (window.huggingface?.variables ?? null) : null; const clientId = opts?.clientId || variables?.OAUTH_CLIENT_ID; @@ -148,7 +148,7 @@ export async function oauthLoginUrl(opts?: { } const challenge = base64FromBytes( - new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(newCodeVerifier))) + new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(newCodeVerifier))), ) .replace(/[+]/g, "-") .replace(/[/]/g, "_") diff --git a/packages/hub/src/lib/parse-safetensors-metadata.spec.ts b/packages/hub/src/lib/parse-safetensors-metadata.spec.ts index 4afbccba70..efcac63afc 100644 --- a/packages/hub/src/lib/parse-safetensors-metadata.spec.ts +++ b/packages/hub/src/lib/parse-safetensors-metadata.spec.ts @@ -236,7 +236,7 @@ describe("parseSafetensorsMetadata", () => { sum( Object.entries(parameterCount) .filter(([, value]) => typeof value === "number") - .map(([, value]) => value as number) + .map(([, value]) => value as number), ); assert.strictEqual(parameterCountTotal, 8_031_637_504); diff --git a/packages/hub/src/lib/parse-safetensors-metadata.ts b/packages/hub/src/lib/parse-safetensors-metadata.ts index 9d004d15ee..1c2396a067 100644 --- a/packages/hub/src/lib/parse-safetensors-metadata.ts +++ b/packages/hub/src/lib/parse-safetensors-metadata.ts @@ -108,7 +108,7 @@ async function fetchModelConfig( revision?: string; hubUrl?: string; fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { try { const configBlob = await downloadFile({ @@ -138,7 +138,7 @@ async function parseSingleFile( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { const blob = await downloadFile({ ...params, path }); @@ -154,7 +154,7 @@ async function parseSingleFile( } if (lengthOfHeader > MAX_HEADER_LENGTH) { throw new SafetensorParseError( - `Failed to parse file ${path}: safetensor header is too big. Maximum supported size is ${MAX_HEADER_LENGTH} bytes.` + `Failed to parse file ${path}: safetensor header is too big. Maximum supported size is ${MAX_HEADER_LENGTH} bytes.`, ); } @@ -177,7 +177,7 @@ async function parseShardedIndex( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { const indexBlob = await downloadFile({ ...params, @@ -208,7 +208,7 @@ async function fetchAllHeaders( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { const pathPrefix = path.slice(0, path.lastIndexOf("/") + 1); const filenames = [...new Set(Object.values(index.weight_map))]; @@ -216,10 +216,10 @@ async function fetchAllHeaders( await promisesQueue( filenames.map( (filename) => async () => - [filename, await parseSingleFile(pathPrefix + filename, params)] satisfies [string, SafetensorsFileHeader] + [filename, await parseSingleFile(pathPrefix + filename, params)] satisfies [string, SafetensorsFileHeader], ), - PARALLEL_DOWNLOADS - ) + PARALLEL_DOWNLOADS, + ), ); return shardedMap; } @@ -248,7 +248,7 @@ export async function parseSafetensorsMetadata( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise>; export async function parseSafetensorsMetadata( params: { @@ -267,7 +267,7 @@ export async function parseSafetensorsMetadata( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise; export async function parseSafetensorsMetadata( params: { @@ -280,7 +280,7 @@ export async function parseSafetensorsMetadata( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { const repoId = toRepoId(params.repo); @@ -309,10 +309,10 @@ export async function parseSafetensorsMetadata( ? typeof header.__metadata__.total_parameters === "number" ? header.__metadata__.total_parameters : typeof header.__metadata__.total_parameters === "string" - ? parseInt(header.__metadata__.total_parameters) - : undefined + ? parseInt(header.__metadata__.total_parameters) + : undefined : undefined, - } + } : undefined), }; } else if ( @@ -336,10 +336,10 @@ export async function parseSafetensorsMetadata( ? typeof index.metadata.total_parameters === "number" ? index.metadata.total_parameters : typeof index.metadata.total_parameters === "string" - ? parseInt(index.metadata.total_parameters) - : undefined + ? parseInt(index.metadata.total_parameters) + : undefined : undefined, - } + } : undefined), }; } else { @@ -435,7 +435,7 @@ function getQuantizationMultiplier(tensorName: string, dtype: Dtype, quantConfig function computeNumOfParamsByDtypeSingleFile( header: SafetensorsFileHeader, - quantConfig?: QuantizationConfig + quantConfig?: QuantizationConfig, ): Partial> { const counter: Partial> = {}; const tensors = omit(header, "__metadata__"); @@ -460,7 +460,7 @@ function computeNumOfParamsByDtypeSingleFile( function computeNumOfParamsByDtypeSharded( shardedMap: SafetensorsShardedHeaders, - quantConfig?: QuantizationConfig + quantConfig?: QuantizationConfig, ): Partial> { const counter: Partial> = {}; for (const header of Object.values(shardedMap)) { diff --git a/packages/hub/src/lib/paths-info.ts b/packages/hub/src/lib/paths-info.ts index ec455f882d..1f8a60c048 100644 --- a/packages/hub/src/lib/paths-info.ts +++ b/packages/hub/src/lib/paths-info.ts @@ -45,7 +45,7 @@ export function pathsInfo( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise<(PathInfo & { lastCommit: CommitInfo; securityFileStatus: SecurityFileStatus })[]>; export function pathsInfo( params: { @@ -58,7 +58,7 @@ export function pathsInfo( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise; export async function pathsInfo( @@ -72,7 +72,7 @@ export async function pathsInfo( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { const accessToken = checkCredentials(params); const repoId = toRepoId(params.repo); @@ -80,7 +80,7 @@ export async function pathsInfo( const hubUrl = params.hubUrl ?? HUB_URL; const url = `${hubUrl}/api/${repoId.type}s/${repoId.name}/paths-info/${encodeURIComponent( - params.revision ?? "main" + params.revision ?? "main", )}`; const resp = await (params.fetch ?? fetch)(url, { @@ -118,7 +118,7 @@ export async function pathsInfo( date: new Date(item.lastCommit.date), title: item.lastCommit.title, id: item.lastCommit.id, - } + } : undefined, })); } diff --git a/packages/hub/src/lib/repo-exists.ts b/packages/hub/src/lib/repo-exists.ts index b53cae0e25..8be149df43 100644 --- a/packages/hub/src/lib/repo-exists.ts +++ b/packages/hub/src/lib/repo-exists.ts @@ -28,7 +28,7 @@ export async function repoExists(params: { Authorization: `Bearer ${params.accessToken}`, }), }, - } + }, ); if (res.status === 404 || res.status === 401) { diff --git a/packages/hub/src/lib/snapshot-download.spec.ts b/packages/hub/src/lib/snapshot-download.spec.ts index 0c44cc8424..0ecb938117 100644 --- a/packages/hub/src/lib/snapshot-download.spec.ts +++ b/packages/hub/src/lib/snapshot-download.spec.ts @@ -164,7 +164,7 @@ describe("snapshotDownload", () => { title: "feat: best commit", }, }, - ]) + ]), ); await snapshotDownload({ @@ -209,7 +209,7 @@ describe("snapshotDownload", () => { }, path: entry.path, revision: DUMMY_SHA, - }) + }), ); } }); @@ -233,7 +233,7 @@ describe("snapshotDownload", () => { title: "feat: best commit", }, }, - ]) + ]), ); await snapshotDownload({ @@ -251,7 +251,7 @@ describe("snapshotDownload", () => { fetch: fetchMock, hubUrl: hubMock, accessToken: accessTokenMock, - }) + }), ); // list files should receive custom fetch @@ -260,7 +260,7 @@ describe("snapshotDownload", () => { fetch: fetchMock, hubUrl: hubMock, accessToken: accessTokenMock, - }) + }), ); // download file to cache should receive custom fetch @@ -269,7 +269,7 @@ describe("snapshotDownload", () => { fetch: fetchMock, hubUrl: hubMock, accessToken: accessTokenMock, - }) + }), ); }); }); diff --git a/packages/hub/src/lib/snapshot-download.ts b/packages/hub/src/lib/snapshot-download.ts index b3e30c13f1..9b8321fd40 100644 --- a/packages/hub/src/lib/snapshot-download.ts +++ b/packages/hub/src/lib/snapshot-download.ts @@ -31,7 +31,7 @@ export async function snapshotDownload( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise { let cacheDir: string; if (params.cacheDir) { diff --git a/packages/hub/src/lib/space-info.ts b/packages/hub/src/lib/space-info.ts index 198c91d992..cbf0fb8555 100644 --- a/packages/hub/src/lib/space-info.ts +++ b/packages/hub/src/lib/space-info.ts @@ -22,7 +22,7 @@ export async function spaceInfo< * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & Partial + } & Partial, ): Promise> { const accessToken = params && checkCredentials(params); @@ -33,13 +33,13 @@ export async function spaceInfo< const response = await (params.fetch || fetch)( `${params?.hubUrl || HUB_URL}/api/spaces/${params.name}/revision/${encodeURIComponent( - params.revision ?? "HEAD" + params.revision ?? "HEAD", )}?${search.toString()}`, { headers: { ...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}), }, - } + }, ); if (!response.ok) { diff --git a/packages/hub/src/lib/upload-file.spec.ts b/packages/hub/src/lib/upload-file.spec.ts index af75349631..08006baa89 100644 --- a/packages/hub/src/lib/upload-file.spec.ts +++ b/packages/hub/src/lib/upload-file.spec.ts @@ -85,7 +85,7 @@ describe("uploadFile", () => { }, "vocab_size": 50257 } - `.trim() + `.trim(), ); } finally { await deleteRepo({ diff --git a/packages/hub/src/lib/upload-file.ts b/packages/hub/src/lib/upload-file.ts index da051cb0d5..400e741ab5 100644 --- a/packages/hub/src/lib/upload-file.ts +++ b/packages/hub/src/lib/upload-file.ts @@ -16,14 +16,14 @@ export function uploadFile( useWebWorkers?: CommitParams["useWebWorkers"]; abortSignal?: CommitParams["abortSignal"]; useXet?: CommitParams["useXet"]; - } & Partial + } & Partial, ): Promise { const path = params.file instanceof URL - ? params.file.pathname.split("/").at(-1) ?? "file" + ? (params.file.pathname.split("/").at(-1) ?? "file") : "path" in params.file - ? params.file.path - : params.file.name; + ? params.file.path + : params.file.name; return commit({ ...(params.accessToken ? { accessToken: params.accessToken } : { credentials: params.credentials }), diff --git a/packages/hub/src/lib/upload-files-with-progress.spec.ts b/packages/hub/src/lib/upload-files-with-progress.spec.ts index cd2f818024..c3dafbc103 100644 --- a/packages/hub/src/lib/upload-files-with-progress.spec.ts +++ b/packages/hub/src/lib/upload-files-with-progress.spec.ts @@ -72,7 +72,7 @@ describe("uploadFilesWithProgress", () => { progressEvents = progressEvents.filter( (e, i) => (e.event !== "fileProgress" || e.progress === 0 || e.progress === 1) && - (i === 0 || JSON.stringify(e) !== JSON.stringify(progressEvents[i - 1])) + (i === 0 || JSON.stringify(e) !== JSON.stringify(progressEvents[i - 1])), ); assert.deepStrictEqual(progressEvents, [ @@ -162,7 +162,7 @@ describe("uploadFilesWithProgress", () => { }, "vocab_size": 50257 } - `.trim() + `.trim(), ); } finally { await deleteRepo({ diff --git a/packages/hub/src/lib/upload-files-with-progress.ts b/packages/hub/src/lib/upload-files-with-progress.ts index 8009cad544..4c2bf1946b 100644 --- a/packages/hub/src/lib/upload-files-with-progress.ts +++ b/packages/hub/src/lib/upload-files-with-progress.ts @@ -34,14 +34,14 @@ export async function* uploadFilesWithProgress( * Set this to true in order to have progress events for hashing */ useWebWorkers?: CommitParams["useWebWorkers"]; - } & Partial + } & Partial, ): AsyncGenerator { return yield* commitIter({ ...(params.accessToken ? { accessToken: params.accessToken } : { credentials: params.credentials }), repo: params.repo, operations: params.files.map((file) => ({ operation: "addOrUpdate", - path: file instanceof URL ? file.pathname.split("/").at(-1) ?? "file" : "path" in file ? file.path : file.name, + path: file instanceof URL ? (file.pathname.split("/").at(-1) ?? "file") : "path" in file ? file.path : file.name, content: "content" in file ? file.content : file, })), title: params.commitTitle ?? `Add ${params.files.length} files`, @@ -130,9 +130,12 @@ export async function* uploadFilesWithProgress( .getAllResponseHeaders() .trim() .split("\n") - .map((header) => [header.slice(0, header.indexOf(":")), header.slice(header.indexOf(":") + 1).trim()]) + .map((header) => [ + header.slice(0, header.indexOf(":")), + header.slice(header.indexOf(":") + 1).trim(), + ]), ), - }) + }), ); }); xhr.addEventListener("error", () => { diff --git a/packages/hub/src/lib/upload-files.spec.ts b/packages/hub/src/lib/upload-files.spec.ts index 94258ad1b2..870bbf736a 100644 --- a/packages/hub/src/lib/upload-files.spec.ts +++ b/packages/hub/src/lib/upload-files.spec.ts @@ -82,7 +82,7 @@ describe("uploadFiles", () => { }, "vocab_size": 50257 } - `.trim() + `.trim(), ); } finally { await deleteRepo({ diff --git a/packages/hub/src/lib/upload-files.ts b/packages/hub/src/lib/upload-files.ts index 585273fa98..e7bc0c2321 100644 --- a/packages/hub/src/lib/upload-files.ts +++ b/packages/hub/src/lib/upload-files.ts @@ -17,14 +17,14 @@ export function uploadFiles( maxFolderDepth?: CommitParams["maxFolderDepth"]; abortSignal?: CommitParams["abortSignal"]; useXet?: CommitParams["useXet"]; - } & Partial + } & Partial, ): Promise { return commit({ ...(params.accessToken ? { accessToken: params.accessToken } : { credentials: params.credentials }), repo: params.repo, operations: params.files.map((file) => ({ operation: "addOrUpdate", - path: file instanceof URL ? file.pathname.split("/").at(-1) ?? "file" : "path" in file ? file.path : file.name, + path: file instanceof URL ? (file.pathname.split("/").at(-1) ?? "file") : "path" in file ? file.path : file.name, content: "content" in file ? file.content : file, })), title: params.commitTitle ?? `Add ${params.files.length} files`, diff --git a/packages/hub/src/lib/who-am-i.ts b/packages/hub/src/lib/who-am-i.ts index b65c4ba6e1..1c50650bc9 100644 --- a/packages/hub/src/lib/who-am-i.ts +++ b/packages/hub/src/lib/who-am-i.ts @@ -66,7 +66,7 @@ export async function whoAmI( * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers. */ fetch?: typeof fetch; - } & CredentialsParams + } & CredentialsParams, ): Promise { const accessToken = checkCredentials(params); diff --git a/packages/hub/src/utils/ChunkCache.ts b/packages/hub/src/utils/ChunkCache.ts index 86a052c6ff..cb64defb06 100644 --- a/packages/hub/src/utils/ChunkCache.ts +++ b/packages/hub/src/utils/ChunkCache.ts @@ -60,7 +60,7 @@ export class ChunkCache { /** * Set to null if you only want to check against locally created chunks, or the hash is already a hmac */ - hmacFunction: ((hash: string, key: string) => string) | null + hmacFunction: ((hash: string, key: string) => string) | null, ): | { xorbIndex: number; diff --git a/packages/hub/src/utils/SplicedBlob.spec.ts b/packages/hub/src/utils/SplicedBlob.spec.ts index 0e46598220..cf8520f15f 100644 --- a/packages/hub/src/utils/SplicedBlob.spec.ts +++ b/packages/hub/src/utils/SplicedBlob.spec.ts @@ -23,31 +23,31 @@ describe("SplicedBlob", () => { it("should throw error for negative start", () => { expect(() => SplicedBlob.create(originalBlob, [{ insert: insertBlob, start: -1, end: 5 }])).toThrow( - "Invalid start/end positions for SplicedBlob" + "Invalid start/end positions for SplicedBlob", ); }); it("should throw error for negative end", () => { expect(() => SplicedBlob.create(originalBlob, [{ insert: insertBlob, start: 5, end: -1 }])).toThrow( - "Invalid start/end positions for SplicedBlob" + "Invalid start/end positions for SplicedBlob", ); }); it("should throw error for start > original.size", () => { expect(() => SplicedBlob.create(originalBlob, [{ insert: insertBlob, start: 15, end: 5 }])).toThrow( - "Invalid start/end positions for SplicedBlob" + "Invalid start/end positions for SplicedBlob", ); }); it("should throw error for end > original.size", () => { expect(() => SplicedBlob.create(originalBlob, [{ insert: insertBlob, start: 5, end: 15 }])).toThrow( - "Invalid start/end positions for SplicedBlob" + "Invalid start/end positions for SplicedBlob", ); }); it("should throw error for start > end", () => { expect(() => SplicedBlob.create(originalBlob, [{ insert: insertBlob, start: 7, end: 5 }])).toThrow( - "Invalid start/end positions for SplicedBlob" + "Invalid start/end positions for SplicedBlob", ); }); }); diff --git a/packages/hub/src/utils/WebBlob.ts b/packages/hub/src/utils/WebBlob.ts index 364bd95094..f46db177c7 100644 --- a/packages/hub/src/utils/WebBlob.ts +++ b/packages/hub/src/utils/WebBlob.ts @@ -57,7 +57,7 @@ export class WebBlob extends Blob { contentType: string, full: boolean, customFetch: typeof fetch, - accessToken: string | undefined + accessToken: string | undefined, ) { super([]); @@ -90,7 +90,7 @@ export class WebBlob extends Blob { this.contentType, start === 0 && end === this.size ? this.full : false, this.fetch, - this.accessToken + this.accessToken, ); return slice; diff --git a/packages/hub/src/utils/XetBlob.spec.ts b/packages/hub/src/utils/XetBlob.spec.ts index 9a12d2f20d..7392c33b0e 100644 --- a/packages/hub/src/utils/XetBlob.spec.ts +++ b/packages/hub/src/utils/XetBlob.spec.ts @@ -35,7 +35,7 @@ describe("XetBlob", () => { headers: { Range: "bytes=0-29927", }, - } + }, ).then((res) => res.arrayBuffer()); expect(new Uint8Array(xetDownload)).toEqual(new Uint8Array(bridgeDownload)); @@ -63,7 +63,7 @@ describe("XetBlob", () => { headers: { Range: "bytes=0-29928", }, - } + }, ).then((res) => res.arrayBuffer()); expect(xetDownload.byteLength).toBe(29929); @@ -93,7 +93,7 @@ describe("XetBlob", () => { headers: { Range: "bytes=0-199999", }, - } + }, ).then((res) => res.arrayBuffer()); expect(xetDownload.byteLength).toBe(200_000); @@ -116,7 +116,7 @@ describe("XetBlob", () => { headers: { Range: "bytes=10000000-10099999", }, - } + }, ).then((res) => res.arrayBuffer()); console.log("xet", xetDownload.byteLength, "bridge", bridgeDownload.byteLength); @@ -174,25 +174,25 @@ describe("XetBlob", () => { describe("bg4_regoup_bytes", () => { it("should regroup bytes when the array is %4 length", () => { expect(bg4_regroup_bytes(new Uint8Array([1, 5, 2, 6, 3, 7, 4, 8]))).toEqual( - new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]) + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]), ); }); it("should regroup bytes when the array is %4 + 1 length", () => { expect(bg4_regroup_bytes(new Uint8Array([1, 5, 9, 2, 6, 3, 7, 4, 8]))).toEqual( - new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]) + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]), ); }); it("should regroup bytes when the array is %4 + 2 length", () => { expect(bg4_regroup_bytes(new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 4, 8]))).toEqual( - new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ); }); it("should regroup bytes when the array is %4 + 3 length", () => { expect(bg4_regroup_bytes(new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8]))).toEqual( - new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), ); }); }); @@ -200,25 +200,25 @@ describe("XetBlob", () => { describe("bg4_split_bytes", () => { it("should split bytes when the array is %4 length", () => { expect(bg4_split_bytes(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))).toEqual( - new Uint8Array([1, 5, 2, 6, 3, 7, 4, 8]) + new Uint8Array([1, 5, 2, 6, 3, 7, 4, 8]), ); }); it("should split bytes when the array is %4 + 1 length", () => { expect(bg4_split_bytes(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]))).toEqual( - new Uint8Array([1, 5, 9, 2, 6, 3, 7, 4, 8]) + new Uint8Array([1, 5, 9, 2, 6, 3, 7, 4, 8]), ); }); it("should split bytes when the array is %4 + 2 length", () => { expect(bg4_split_bytes(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))).toEqual( - new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 4, 8]) + new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 4, 8]), ); }); it("should split bytes when the array is %4 + 3 length", () => { expect(bg4_split_bytes(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]))).toEqual( - new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8]) + new Uint8Array([1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8]), ); }); @@ -273,7 +273,7 @@ describe("XetBlob", () => { casUrl: "https://cas.co", accessToken: "boo", exp: 1_000_000, - }) + }), ); } case "cas.co": { @@ -308,7 +308,7 @@ describe("XetBlob", () => { ], }, offset_into_first_range: start, - } satisfies ReconstructionInfo) + } satisfies ReconstructionInfo), ); } case "fetch.co": { @@ -319,7 +319,7 @@ describe("XetBlob", () => { controller.enqueue(new Uint8Array(mergedChunks)); controller.close(); }, - }) + }), //mergedChunks ); } @@ -376,7 +376,7 @@ describe("XetBlob", () => { casUrl: "https://cas.co", accessToken: "boo", exp: 1_000_000, - }) + }), ); } case "cas.co": { @@ -421,7 +421,7 @@ describe("XetBlob", () => { ], }, offset_into_first_range: start, - } satisfies ReconstructionInfo) + } satisfies ReconstructionInfo), ); } case "fetch.co": { @@ -432,7 +432,7 @@ describe("XetBlob", () => { controller.enqueue(new Uint8Array(mergedChunks)); controller.close(); }, - }) + }), //mergedChunks ); } @@ -491,7 +491,7 @@ describe("XetBlob", () => { casUrl: "https://cas.co", accessToken: "boo", exp: 1_000_000, - }) + }), ); } case "cas.co": { @@ -526,7 +526,7 @@ describe("XetBlob", () => { ], }, offset_into_first_range: start, - } satisfies ReconstructionInfo) + } satisfies ReconstructionInfo), ); } case "fetch.co": { @@ -546,7 +546,7 @@ describe("XetBlob", () => { ETag: `"test"`, "Content-Length": `${totalChunkLength}`, }, - } + }, ); } default: @@ -601,7 +601,7 @@ describe("XetBlob", () => { casUrl: "https://cas.co", accessToken: "boo", exp: 1_000_000, - }) + }), ); } case "cas.co": { @@ -636,7 +636,7 @@ describe("XetBlob", () => { ], }, offset_into_first_range: start, - } satisfies ReconstructionInfo) + } satisfies ReconstructionInfo), ); } case "fetch.co": { @@ -649,7 +649,7 @@ describe("XetBlob", () => { } controller.close(); }, - }) + }), ); } default: @@ -709,7 +709,7 @@ describe("XetBlob", () => { casUrl: "https://cas.co", accessToken: "boo", exp: 1_000_000, - }) + }), ); } case "cas.co": { @@ -744,7 +744,7 @@ describe("XetBlob", () => { ], }, offset_into_first_range: start, - } satisfies ReconstructionInfo) + } satisfies ReconstructionInfo), ); } case "fetch.co": { @@ -757,7 +757,7 @@ describe("XetBlob", () => { } controller.close(); }, - }) + }), ); } default: @@ -816,7 +816,7 @@ describe("XetBlob", () => { casUrl: "https://cas.co", accessToken: "boo", exp: 1_000_000, - }) + }), ); } case "cas.co": { @@ -851,7 +851,7 @@ describe("XetBlob", () => { ], }, offset_into_first_range: start, - } satisfies ReconstructionInfo) + } satisfies ReconstructionInfo), ); } case "fetch.co": { @@ -864,7 +864,7 @@ describe("XetBlob", () => { } controller.close(); }, - }) + }), ); } default: diff --git a/packages/hub/src/utils/XetBlob.ts b/packages/hub/src/utils/XetBlob.ts index 16b66b78cc..b1cf040aa1 100644 --- a/packages/hub/src/utils/XetBlob.ts +++ b/packages/hub/src/utils/XetBlob.ts @@ -208,7 +208,7 @@ export class XetBlob extends Blob { reconstructionInfo: ReconstructionInfo, customFetch: typeof fetch, maxBytes: number, - reloadReconstructionInfo: () => Promise + reloadReconstructionInfo: () => Promise, ) { let totalBytesRead = 0; let readBytesToSkip = reconstructionInfo.offset_into_first_range; @@ -259,12 +259,12 @@ export class XetBlob extends Blob { } const fetchInfo = reconstructionInfo.fetch_info[term.hash].find( - (info) => info.range.start <= term.range.start && info.range.end >= term.range.end + (info) => info.range.start <= term.range.start && info.range.end >= term.range.end, ); if (!fetchInfo) { throw new Error( - `Failed to find fetch info for term ${term.hash} and range ${term.range.start}-${term.range.end}` + `Failed to find fetch info for term ${term.hash} and range ${term.range.start}-${term.range.end}`, ); } @@ -297,7 +297,7 @@ export class XetBlob extends Blob { resp.headers.get("content-length"), "range", fetchInfo.url_range, - resp.headers.get("content-range") + resp.headers.get("content-range"), ); const reader = resp.body?.getReader(); @@ -361,7 +361,7 @@ export class XetBlob extends Blob { throw new Error( `Unsupported compression scheme ${ compressionSchemeLabels[chunkHeader.compression_scheme] ?? chunkHeader.compression_scheme - }` + }`, ); } @@ -377,13 +377,13 @@ export class XetBlob extends Blob { chunkHeader.compression_scheme === XetChunkCompressionScheme.LZ4 ? lz4_decompress(result.value.slice(0, chunkHeader.compressed_length), chunkHeader.uncompressed_length) : chunkHeader.compression_scheme === XetChunkCompressionScheme.ByteGroupingLZ4 - ? bg4_regroup_bytes( + ? bg4_regroup_bytes( lz4_decompress( result.value.slice(0, chunkHeader.compressed_length), - chunkHeader.uncompressed_length - ) - ) - : result.value.slice(0, chunkHeader.compressed_length); + chunkHeader.uncompressed_length, + ), + ) + : result.value.slice(0, chunkHeader.compressed_length); const range = ranges.find((range) => chunkIndex >= range.start && chunkIndex < range.end); const shouldYield = chunkIndex >= term.range.start && chunkIndex < term.range.end; @@ -416,7 +416,7 @@ export class XetBlob extends Blob { result.value.byteLength, "total read", totalBytesRead, - stored + stored, ); totalBytesRead += uncompressed.byteLength; yield stored ? uncompressed.slice() : uncompressed; @@ -439,7 +439,7 @@ export class XetBlob extends Blob { throw new Error( `Failed to fetch all data for term ${term.hash}, fetched ${totalFetchBytes} bytes out of ${ fetchInfo.url_range.end - fetchInfo.url_range.start + 1 - }` + }`, ); } @@ -455,7 +455,7 @@ export class XetBlob extends Blob { this.reconstructionInfo, this.fetch, this.end - this.start, - this.#loadReconstructionInfo.bind(this) + this.#loadReconstructionInfo.bind(this), ); // todo: when Chrome/Safari support it, use ReadableStream.from(readData) @@ -479,7 +479,7 @@ export class XetBlob extends Blob { // todo : use ByteLengthQueuingStrategy when there's good support for it, currently in Node.js it fails due to size being a function { highWaterMark: 1_000, // 1_000 chunks for ~1MB of RAM - } + }, ); } @@ -628,7 +628,7 @@ export function bg4_split_bytes(bytes: Uint8Array): Uint8Array { async function getAccessToken( initialAccessToken: string | undefined, customFetch: typeof fetch, - refreshUrl: string + refreshUrl: string, ): Promise<{ accessToken: string; casUrl: string }> { const key = cacheKey({ refreshUrl, initialAccessToken }); @@ -650,7 +650,7 @@ async function getAccessToken( ...(initialAccessToken ? { Authorization: `Bearer ${initialAccessToken}`, - } + } : {}), }, }); diff --git a/packages/hub/src/utils/combineUint8Arrays.ts b/packages/hub/src/utils/combineUint8Arrays.ts index c5ff60571f..f0be769b85 100644 --- a/packages/hub/src/utils/combineUint8Arrays.ts +++ b/packages/hub/src/utils/combineUint8Arrays.ts @@ -1,6 +1,6 @@ export function combineUint8Arrays( a: Uint8Array, - b: Uint8Array + b: Uint8Array, ): Uint8Array { const aLength = a.length; const combinedBytes = new Uint8Array(aLength + b.length); diff --git a/packages/hub/src/utils/createBlobs.ts b/packages/hub/src/utils/createBlobs.ts index 625bef5fde..93314ebf06 100644 --- a/packages/hub/src/utils/createBlobs.ts +++ b/packages/hub/src/utils/createBlobs.ts @@ -15,7 +15,7 @@ import { isFrontend } from "./isFrontend"; export async function createBlobs( url: URL, destPath: string, - opts?: { fetch?: typeof fetch; maxFolderDepth?: number; accessToken?: string } + opts?: { fetch?: typeof fetch; maxFolderDepth?: number; accessToken?: string }, ): Promise> { if (url.protocol === "http:" || url.protocol === "https:") { const blob = await WebBlob.create(url, { fetch: opts?.fetch, accessToken: opts?.accessToken }); @@ -43,7 +43,7 @@ export async function createBlobs( .replaceAll("//", "/") .replace(/^[.]?\//, ""), blob: await FileBlob.create(new URL(path.path)), - })) + })), ); } diff --git a/packages/hub/src/utils/createXorbs.ts b/packages/hub/src/utils/createXorbs.ts index 4006a004c7..d1ec8096d1 100644 --- a/packages/hub/src/utils/createXorbs.ts +++ b/packages/hub/src/utils/createXorbs.ts @@ -86,7 +86,7 @@ export async function* createXorbs( fileSources: AsyncGenerator<{ content: Blob; path: string; sha256: string }>, params: XetWriteTokenParams & { yieldCallback?: (event: { event: "fileProgress"; path: string; progress: number }) => void; - } + }, ): AsyncGenerator< | XorbEvent | { @@ -178,7 +178,7 @@ export async function* createXorbs( { maxChunks: 1, isAtBeginning: true, - } + }, ); } let bytesSinceRemoteDedup = Infinity; @@ -246,7 +246,7 @@ export async function* createXorbs( shardData, chunkCache, chunkMetadata, - dedupedBytes + dedupedBytes, ); if (dedupedBytes > oldDedupedBytes) { @@ -342,7 +342,7 @@ export async function* createXorbs( const fileRepresentation = buildFileRepresentation( chunkMetadata, fileChunks, - chunkModule.compute_verification_hash.bind(chunkModule) + chunkModule.compute_verification_hash.bind(chunkModule), ); xorb.immutableData = { chunkIndex: xorb.chunks.length, @@ -383,7 +383,7 @@ export function backtrackDedup( shardData: ShardData, chunkCache: ChunkCache, chunkMetadata: { xorbId: number | string; chunkIndex: number; length: number }[], - dedupedBytes: number + dedupedBytes: number, ): number { const chunkIndexesToBacktrackFor = new Map(); for ( @@ -562,7 +562,7 @@ function writeChunk(xorb: CurrentXorbInfo, chunk: Uint8Array, hash: string): boo const buildFileRepresentation = ( metadata: Array<{ xorbId: number | string; chunkIndex: number; length: number }>, chunks: Array<{ hash: string; length: number }>, - computeVerificationHash: (hashes: string[]) => string + computeVerificationHash: (hashes: string[]) => string, ): Array<{ xorbId: number | string; indexStart: number; @@ -664,7 +664,7 @@ async function loadDedupInfoToCache( * Will process content up to the end of the chunk after this position */ maxChunks?: number; - } + }, ): Promise { const chunker = new chunkModule.Chunker(TARGET_CHUNK_SIZE); const cache = chunkCache; diff --git a/packages/hub/src/utils/eventToGenerator.ts b/packages/hub/src/utils/eventToGenerator.ts index a06e503b69..1bbc84f997 100644 --- a/packages/hub/src/utils/eventToGenerator.ts +++ b/packages/hub/src/utils/eventToGenerator.ts @@ -2,8 +2,8 @@ export async function* eventToGenerator( cb: ( yieldCallback: (y: YieldType) => void, returnCallback: (r: ReturnType) => void, - rejectCallack: (reason: unknown) => void - ) => unknown + rejectCallack: (reason: unknown) => void, + ) => unknown, ): AsyncGenerator { const promises: Array<{ p: Promise<{ done: true; value: ReturnType } | { done: false; value: YieldType }>; @@ -35,8 +35,8 @@ export async function* eventToGenerator( addPromise(); promises.at(-2)?.resolve({ done: true, value: r }); }, - (err) => promises.shift()?.reject(err) - ) + (err) => promises.shift()?.reject(err), + ), ) .catch((err) => promises.shift()?.reject(err)); diff --git a/packages/hub/src/utils/normalizeInferenceProviderMapping.ts b/packages/hub/src/utils/normalizeInferenceProviderMapping.ts index b7cd0a8cfb..471997f2de 100644 --- a/packages/hub/src/utils/normalizeInferenceProviderMapping.ts +++ b/packages/hub/src/utils/normalizeInferenceProviderMapping.ts @@ -11,7 +11,7 @@ export function normalizeInferenceProviderMapping( hfModelId: string, inferenceProviderMapping?: | ApiModelInferenceProviderMappingEntry[] - | Record + | Record, ): ApiModelInferenceProviderMappingEntry[] { if (!inferenceProviderMapping) { return []; diff --git a/packages/hub/src/utils/omit.ts b/packages/hub/src/utils/omit.ts index 8743dba87f..e37f54b884 100644 --- a/packages/hub/src/utils/omit.ts +++ b/packages/hub/src/utils/omit.ts @@ -6,7 +6,7 @@ import { typedInclude } from "./typedInclude"; */ export function omit, K extends keyof T>( o: T, - props: K[] | K + props: K[] | K, ): Pick> { const propsArr = Array.isArray(props) ? props : [props]; const letsKeep = (Object.keys(o) as (keyof T)[]).filter((prop) => !typedInclude(propsArr, prop)); diff --git a/packages/hub/src/utils/pick.ts b/packages/hub/src/utils/pick.ts index bd32e4532e..a47a57f861 100644 --- a/packages/hub/src/utils/pick.ts +++ b/packages/hub/src/utils/pick.ts @@ -8,6 +8,6 @@ export function pick(o: T, props: K[] | ReadonlyArray): if (o[prop] !== undefined) { return { [prop]: o[prop] }; } - }) + }), ); } diff --git a/packages/hub/src/utils/promisesQueueStreaming.ts b/packages/hub/src/utils/promisesQueueStreaming.ts index cbe966276a..72f441afbc 100644 --- a/packages/hub/src/utils/promisesQueueStreaming.ts +++ b/packages/hub/src/utils/promisesQueueStreaming.ts @@ -9,7 +9,7 @@ */ export async function promisesQueueStreaming( factories: AsyncIterable<() => Promise> | Iterable<() => Promise>, - concurrency: number + concurrency: number, ): Promise { const executing: Promise[] = []; for await (const factory of factories) { diff --git a/packages/hub/src/utils/sha256-node.ts b/packages/hub/src/utils/sha256-node.ts index b068d1a218..a7c75ad776 100644 --- a/packages/hub/src/utils/sha256-node.ts +++ b/packages/hub/src/utils/sha256-node.ts @@ -6,7 +6,7 @@ export async function* sha256Node( buffer: ArrayBuffer | Blob, opts?: { abortSignal?: AbortSignal; - } + }, ): AsyncGenerator { const sha256Stream = createHash("sha256"); const size = buffer instanceof Blob ? buffer.size : buffer.byteLength; diff --git a/packages/hub/src/utils/sha256.ts b/packages/hub/src/utils/sha256.ts index b2b36af4f4..0458d0495c 100644 --- a/packages/hub/src/utils/sha256.ts +++ b/packages/hub/src/utils/sha256.ts @@ -71,7 +71,7 @@ function destroyWorker(worker: Worker): void { */ export async function* sha256( buffer: Blob, - opts?: { useWebWorker?: boolean | { minSize?: number; poolSize?: number }; abortSignal?: AbortSignal } + opts?: { useWebWorker?: boolean | { minSize?: number; poolSize?: number }; abortSignal?: AbortSignal }, ): AsyncGenerator { yield 0; @@ -82,8 +82,8 @@ export async function* sha256( if (buffer.size < maxCryptoSize && globalThis.crypto?.subtle) { const res = hexFromBytes( new Uint8Array( - await globalThis.crypto.subtle.digest("SHA-256", buffer instanceof Blob ? await buffer.arrayBuffer() : buffer) - ) + await globalThis.crypto.subtle.digest("SHA-256", buffer instanceof Blob ? await buffer.arrayBuffer() : buffer), + ), ); yield 1; diff --git a/packages/hub/src/utils/sub-paths.ts b/packages/hub/src/utils/sub-paths.ts index 15682c14f8..c15e73393a 100644 --- a/packages/hub/src/utils/sub-paths.ts +++ b/packages/hub/src/utils/sub-paths.ts @@ -6,7 +6,7 @@ import { fileURLToPath, pathToFileURL } from "node:url"; */ export async function subPaths( path: URL, - maxDepth = 10 + maxDepth = 10, ): Promise< Array<{ path: URL; @@ -27,7 +27,7 @@ export async function subPaths( ...(await subPaths(filePath, maxDepth - 1)).map((subPath) => ({ ...subPath, relativePath: `${file.name}/${subPath.relativePath}`, - })) + })), ); } else { ret.push({ path: filePath, relativePath: file.name }); diff --git a/packages/hub/src/utils/toRepoId.ts b/packages/hub/src/utils/toRepoId.ts index 9273266928..8394011a4f 100644 --- a/packages/hub/src/utils/toRepoId.ts +++ b/packages/hub/src/utils/toRepoId.ts @@ -7,7 +7,7 @@ export function toRepoId(repo: RepoDesignation): RepoId { if (repo.startsWith("model/") || repo.startsWith("models/")) { throw new TypeError( - "A repo designation for a model should not start with 'models/', directly specify the model namespace / name" + "A repo designation for a model should not start with 'models/', directly specify the model namespace / name", ); } diff --git a/packages/hub/src/utils/uploadShards.ts b/packages/hub/src/utils/uploadShards.ts index e04db5acb8..e4f3299f53 100644 --- a/packages/hub/src/utils/uploadShards.ts +++ b/packages/hub/src/utils/uploadShards.ts @@ -75,7 +75,7 @@ interface UploadShardsParams { */ export async function* uploadShards( source: AsyncGenerator<{ content: Blob; path: string; sha256: string }>, - params: UploadShardsParams + params: UploadShardsParams, ): AsyncGenerator< | { event: "file"; path: string; sha256: string; dedupRatio: number } | { event: "fileProgress"; path: string; progress: number } @@ -189,7 +189,7 @@ export async function* uploadShards( writeHashToArray( typeof repItem.xorbId === "number" ? xorbHashes[repItem.xorbId] : repItem.xorbId, fileInfoSection, - fileViewOffset + fileViewOffset, ); fileViewOffset += HASH_LENGTH; fileInfoView.setUint32(fileViewOffset, 0, true); // Xorb flags @@ -230,7 +230,7 @@ export async function* uploadShards( function createShard(): Uint8Array { const shard = new Uint8Array( - SHARD_HEADER_SIZE + SHARD_FOOTER_SIZE + xorbViewOffset + XORB_FOOTER_LENGTH + fileViewOffset + FILE_FOOTER_LENGTH + SHARD_HEADER_SIZE + SHARD_FOOTER_SIZE + xorbViewOffset + XORB_FOOTER_LENGTH + fileViewOffset + FILE_FOOTER_LENGTH, ); const shardView = new DataView(shard.buffer); @@ -365,7 +365,7 @@ function writeHashToArray(hash: string, array: Uint8Array, offset: number) { async function uploadXorb( xorb: { hash: string; xorb: Uint8Array; files: Array<{ path: string; progress: number; lastSentProgress: number }> }, - params: UploadShardsParams + params: UploadShardsParams, ) { const token = await xetWriteToken(params); diff --git a/packages/hub/src/utils/xetWriteToken.ts b/packages/hub/src/utils/xetWriteToken.ts index 858bd5bfee..e877dc55ae 100644 --- a/packages/hub/src/utils/xetWriteToken.ts +++ b/packages/hub/src/utils/xetWriteToken.ts @@ -52,7 +52,7 @@ export async function xetWriteToken(params: XetWriteTokenParams): Promise<{ acce ...(params.accessToken ? { Authorization: `Bearer ${params.accessToken}`, - } + } : {}), ...(params.xetParams.sessionId ? { "X-Xet-Session-Id": params.xetParams.sessionId } : {}), }, diff --git a/packages/hub/src/vendor/hash-wasm/sha256-wrapper.ts b/packages/hub/src/vendor/hash-wasm/sha256-wrapper.ts index c6ad75b36b..3a897696ed 100644 --- a/packages/hub/src/vendor/hash-wasm/sha256-wrapper.ts +++ b/packages/hub/src/vendor/hash-wasm/sha256-wrapper.ts @@ -8,7 +8,7 @@ export async function createSHA256(isInsideWorker = false): Promise<{ const BUFFER_MAX_SIZE = 8 * 1024 * 1024; const wasm: Awaited> = isInsideWorker ? // @ts-expect-error WasmModule will be populated inside self object - await self["SHA256WasmModule"]() + await self["SHA256WasmModule"]() : await WasmModule(); const heap = wasm.HEAPU8.subarray(wasm._GetBufferPtr()); return { diff --git a/packages/hub/src/vendor/lz4js/index.ts b/packages/hub/src/vendor/lz4js/index.ts index 067101fc21..150805de6f 100644 --- a/packages/hub/src/vendor/lz4js/index.ts +++ b/packages/hub/src/vendor/lz4js/index.ts @@ -241,7 +241,7 @@ export function compressBlock( dst: Uint8Array, sIndex: number, sLength: number, - hashTable: Uint32Array | number[] + hashTable: Uint32Array | number[], ) { let mIndex, mAnchor, mLength, mOffset, mStep; let literalCount, dIndex, sEnd, n; diff --git a/packages/hub/src/vendor/type-fest/entries.ts b/packages/hub/src/vendor/type-fest/entries.ts index 7716e47480..3975d823ae 100644 --- a/packages/hub/src/vendor/type-fest/entries.ts +++ b/packages/hub/src/vendor/type-fest/entries.ts @@ -54,12 +54,13 @@ const setEntries: Entries = [['a', 'a'], [1, 1]]; @category Set @category Array */ -export type Entries = BaseType extends Map - ? MapEntries - : BaseType extends Set - ? SetEntries - : BaseType extends readonly unknown[] - ? ArrayEntries - : BaseType extends object - ? ObjectEntries - : never; +export type Entries = + BaseType extends Map + ? MapEntries + : BaseType extends Set + ? SetEntries + : BaseType extends readonly unknown[] + ? ArrayEntries + : BaseType extends object + ? ObjectEntries + : never; diff --git a/packages/hub/src/vendor/type-fest/entry.ts b/packages/hub/src/vendor/type-fest/entry.ts index ed3650c90c..1f8dd55ccc 100644 --- a/packages/hub/src/vendor/type-fest/entry.ts +++ b/packages/hub/src/vendor/type-fest/entry.ts @@ -57,12 +57,13 @@ const setEntryNumber: Entry = [1, 1]; @category Array @category Set */ -export type Entry = BaseType extends Map - ? MapEntry - : BaseType extends Set - ? SetEntry - : BaseType extends readonly unknown[] - ? ArrayEntry - : BaseType extends object - ? ObjectEntry - : never; +export type Entry = + BaseType extends Map + ? MapEntry + : BaseType extends Set + ? SetEntry + : BaseType extends readonly unknown[] + ? ArrayEntry + : BaseType extends object + ? ObjectEntry + : never; diff --git a/packages/hub/src/vendor/type-fest/except.ts b/packages/hub/src/vendor/type-fest/except.ts index b18f739d16..d6a38169ee 100644 --- a/packages/hub/src/vendor/type-fest/except.ts +++ b/packages/hub/src/vendor/type-fest/except.ts @@ -27,11 +27,8 @@ type Filtered = Filter<'bar', 'foo'>; @see {Except} */ -type Filter = IsEqual extends true - ? never - : KeyType extends ExcludeType - ? never - : KeyType; +type Filter = + IsEqual extends true ? never : KeyType extends ExcludeType ? never : KeyType; /** Create a type from an object type without certain keys. diff --git a/packages/hub/src/vendor/xet-chunk/chunker_wasm.ts b/packages/hub/src/vendor/xet-chunk/chunker_wasm.ts index 4ce742d130..efc7d0294b 100644 --- a/packages/hub/src/vendor/xet-chunk/chunker_wasm.ts +++ b/packages/hub/src/vendor/xet-chunk/chunker_wasm.ts @@ -29,13 +29,13 @@ async function init(): Promise { // @ts-expect-error ok for any type [item.module]: [...(result[item.module] || []), item.name], }), - {} - ) + {}, + ), ).map(([from, names]) => ({ from, names })); const wasm = await WebAssembly.instantiate(wasmModule, { "./hf_xet_thin_wasm_bg.js": Object.fromEntries( // @ts-expect-error ok for any type - (imports[0].names as string[]).map((name) => [name, __glue_imports[name]]) + (imports[0].names as string[]).map((name) => [name, __glue_imports[name]]), ), }); __wbg_set_wasm(wasm.exports); diff --git a/packages/hub/src/vendor/xet-chunk/chunker_wasm_bg.wasm.base64.ts b/packages/hub/src/vendor/xet-chunk/chunker_wasm_bg.wasm.base64.ts index 3e25ba7265..5ecdcfc36b 100644 --- a/packages/hub/src/vendor/xet-chunk/chunker_wasm_bg.wasm.base64.ts +++ b/packages/hub/src/vendor/xet-chunk/chunker_wasm_bg.wasm.base64.ts @@ -1361,7 +1361,7 @@ ZW4HMC4yLjEwMABJD3RhcmdldF9mZWF0dXJlcwQrD211dGFibGUtZ2xvYmFscysIc2lnbi1leHQrD3Jl bXVsdGl2YWx1ZQ== ` .trim() - .replaceAll("\n", "") + .replaceAll("\n", ""), ); const wasmBinary = new Uint8Array(wasmBase64.length); for (let i = 0; i < wasmBase64.length; i++) { diff --git a/packages/inference/package.json b/packages/inference/package.json index 3d16d73cdc..686f253f9b 100644 --- a/packages/inference/package.json +++ b/packages/inference/package.json @@ -1,45 +1,48 @@ { "name": "@huggingface/inference", "version": "4.13.10", - "packageManager": "pnpm@10.10.0", - "license": "MIT", - "author": "Hugging Face and Tim Mikeladze ", "description": "Typescript client for the Hugging Face Inference Providers and Inference Endpoints", - "repository": { - "type": "git", - "url": "https://github.com/huggingface/huggingface.js.git" - }, - "publishConfig": { - "access": "public" - }, "keywords": [ + "ai", "hugging face", "hugging face typescript", "huggingface", "huggingface-inference-api", "huggingface-inference-api-typescript", - "inference", - "ai" + "inference" ], - "engines": { - "node": ">=18" + "license": "MIT", + "author": "Hugging Face and Tim Mikeladze ", + "repository": { + "type": "git", + "url": "https://github.com/huggingface/huggingface.js.git" }, + "source": "src/index.ts", "files": [ "dist", "src", "!src/snippets/templates/**/*.jinja" ], - "source": "src/index.ts", - "types": "./dist/commonjs/index.d.ts", + "type": "module", "main": "./dist/commonjs/index.js", "module": "./dist/esm/index.js", - "tshy": { - "exports": { - "./package.json": "./package.json", - ".": "./src/index.ts" + "types": "./dist/commonjs/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./dist/esm/index.d.ts", + "default": "./dist/esm/index.js" + }, + "require": { + "types": "./dist/commonjs/index.d.ts", + "default": "./dist/commonjs/index.js" + } } }, - "type": "module", + "publishConfig": { + "access": "public" + }, "scripts": { "build": "pnpm run export-templates && pnpm run package-to-ts && tshy", "lint": "eslint --quiet --fix --ext .cjs,.ts .", @@ -56,24 +59,21 @@ "package-to-ts": "tsx scripts/package-json-to-ts.ts" }, "dependencies": { - "@huggingface/tasks": "workspace:^", - "@huggingface/jinja": "workspace:^" + "@huggingface/jinja": "workspace:^", + "@huggingface/tasks": "workspace:^" }, "devDependencies": { "@types/node": "18.13.0" }, "resolutions": {}, - "exports": { - "./package.json": "./package.json", - ".": { - "import": { - "types": "./dist/esm/index.d.ts", - "default": "./dist/esm/index.js" - }, - "require": { - "types": "./dist/commonjs/index.d.ts", - "default": "./dist/commonjs/index.js" - } + "tshy": { + "exports": { + ".": "./src/index.ts", + "./package.json": "./package.json" } - } + }, + "engines": { + "node": ">=18" + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/inference/src/InferenceClient.ts b/packages/inference/src/InferenceClient.ts index 605e85bd55..fca26cccf7 100644 --- a/packages/inference/src/InferenceClient.ts +++ b/packages/inference/src/InferenceClient.ts @@ -16,7 +16,7 @@ export class InferenceClient { accessToken = "", defaultOptions: Options & { endpointUrl?: string; - } = {} + } = {}, ) { this.accessToken = accessToken; this.defaultOptions = defaultOptions; @@ -32,7 +32,7 @@ export class InferenceClient { { ...omit(defaultOptions, ["endpointUrl"]), ...options, - } + }, ), }); } diff --git a/packages/inference/src/errors.ts b/packages/inference/src/errors.ts index bcc0a773ce..4d8f9edb67 100644 --- a/packages/inference/src/errors.ts +++ b/packages/inference/src/errors.ts @@ -51,7 +51,7 @@ abstract class InferenceClientHttpRequestError extends InferenceClientError { ...("Authorization" in httpRequest.headers ? { Authorization: `Bearer [redacted]` } : undefined), /// redact authentication in the request headers }, - } + } : undefined), }; this.httpResponse = httpResponse; diff --git a/packages/inference/src/lib/getDefaultTask.ts b/packages/inference/src/lib/getDefaultTask.ts index a305dc0948..7d497116d8 100644 --- a/packages/inference/src/lib/getDefaultTask.ts +++ b/packages/inference/src/lib/getDefaultTask.ts @@ -23,7 +23,7 @@ export interface DefaultTaskOptions { export async function getDefaultTask( model: string, accessToken: string | undefined, - options?: DefaultTaskOptions + options?: DefaultTaskOptions, ): Promise { if (isUrl(model)) { return null; diff --git a/packages/inference/src/lib/getInferenceProviderMapping.ts b/packages/inference/src/lib/getInferenceProviderMapping.ts index f6e0dd5656..92401fa5f0 100644 --- a/packages/inference/src/lib/getInferenceProviderMapping.ts +++ b/packages/inference/src/lib/getInferenceProviderMapping.ts @@ -28,7 +28,7 @@ function normalizeInferenceProviderMapping( adapter?: string; adapterWeightsPath?: string; } - > + >, ): InferenceProviderMappingEntry[] { if (!inferenceProviderMapping) { return []; @@ -56,7 +56,7 @@ export async function fetchInferenceProviderMappingForModel( accessToken?: string, options?: { fetch?: (input: RequestInfo, init?: RequestInit) => Promise; - } + }, ): Promise { let inferenceProviderMapping: InferenceProviderMappingEntry[] | null; if (inferenceProviderMappingCache.has(modelId)) { @@ -74,14 +74,14 @@ export async function fetchInferenceProviderMappingForModel( throw new InferenceClientHubApiError( `Failed to fetch inference provider mapping for model ${modelId}: ${error.error}`, { url, method: "GET" }, - { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: error } + { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: error }, ); } } else { throw new InferenceClientHubApiError( `Failed to fetch inference provider mapping for model ${modelId}`, { url, method: "GET" }, - { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: await resp.text() } + { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: await resp.text() }, ); } } @@ -96,14 +96,14 @@ export async function fetchInferenceProviderMappingForModel( throw new InferenceClientHubApiError( `Failed to fetch inference provider mapping for model ${modelId}: malformed API response, invalid JSON`, { url, method: "GET" }, - { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: await resp.text() } + { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: await resp.text() }, ); } if (!payload?.inferenceProviderMapping) { throw new InferenceClientHubApiError( `We have not been able to find inference provider information for model ${modelId}.`, { url, method: "GET" }, - { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: await resp.text() } + { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: await resp.text() }, ); } inferenceProviderMapping = normalizeInferenceProviderMapping(modelId, payload.inferenceProviderMapping); @@ -121,7 +121,7 @@ export async function getInferenceProviderMapping( }, options: { fetch?: (input: RequestInfo, init?: RequestInit) => Promise; - } + }, ): Promise { const logger = getLogger(); if (params.provider === ("auto" as InferenceProvider) && params.task === "conversational") { @@ -147,12 +147,12 @@ export async function getInferenceProviderMapping( : [params.task]; if (!typedInclude(equivalentTasks, providerMapping.task)) { throw new InferenceClientInputError( - `Model ${params.modelId} is not supported for task ${params.task} and provider ${params.provider}. Supported task: ${providerMapping.task}.` + `Model ${params.modelId} is not supported for task ${params.task} and provider ${params.provider}. Supported task: ${providerMapping.task}.`, ); } if (providerMapping.status === "staging") { logger.warn( - `Model ${params.modelId} is in staging mode for provider ${params.provider}. Meant for test purposes only.` + `Model ${params.modelId} is in staging mode for provider ${params.provider}. Meant for test purposes only.`, ); } return providerMapping; @@ -163,7 +163,7 @@ export async function getInferenceProviderMapping( export async function resolveProvider( provider?: InferenceProviderOrPolicy, modelId?: string, - endpointUrl?: string + endpointUrl?: string, ): Promise { const logger = getLogger(); if (endpointUrl) { @@ -175,7 +175,7 @@ export async function resolveProvider( } if (!provider) { logger.log( - "Defaulting to 'auto' which will select the first provider available for the model, sorted by the user's order in https://hf.co/settings/inference-providers." + "Defaulting to 'auto' which will select the first provider available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.", ); provider = "auto"; } diff --git a/packages/inference/src/lib/getProviderHelper.ts b/packages/inference/src/lib/getProviderHelper.ts index a777b6593b..28e0eb2ad0 100644 --- a/packages/inference/src/lib/getProviderHelper.ts +++ b/packages/inference/src/lib/getProviderHelper.ts @@ -197,157 +197,157 @@ export const PROVIDERS: Record { const { model: maybeModel } = args; const provider = providerHelper.provider; @@ -46,7 +46,7 @@ export async function makeRequestOptions( providerHelper, args, undefined, - options + options, ); } @@ -71,7 +71,7 @@ export async function makeRequestOptions( status: "live", // eslint-disable-next-line @typescript-eslint/no-non-null-assertion task: task!, - } satisfies InferenceProviderMappingEntry) + } satisfies InferenceProviderMappingEntry) : await getInferenceProviderMapping( { modelId: hfModel, @@ -80,11 +80,11 @@ export async function makeRequestOptions( provider, accessToken: args.accessToken, }, - { fetch: options?.fetch } - ); + { fetch: options?.fetch }, + ); if (!inferenceProviderMapping) { throw new InferenceClientInputError( - `We have not been able to find inference provider information for model ${hfModel}.` + `We have not been able to find inference provider information for model ${hfModel}.`, ); } @@ -94,7 +94,7 @@ export async function makeRequestOptions( providerHelper, args, inferenceProviderMapping, - options + options, ); } @@ -113,7 +113,7 @@ export function makeRequestOptionsFromResolvedModel( options?: Options & { task?: InferenceTask; outputType?: OutputType; - } + }, ): { url: string; info: RequestInit } { const { accessToken, endpointUrl, provider: maybeProvider, model, urlTransform, ...remainingArgs } = args; void model; @@ -154,7 +154,7 @@ export function makeRequestOptionsFromResolvedModel( accessToken, authMethod, }, - "data" in args && !!args.data + "data" in args && !!args.data, ); if (billTo) { headers[HF_HEADER_X_BILL_TO] = billTo; @@ -203,7 +203,7 @@ async function loadDefaultModel(task: InferenceTask): Promise { const taskInfo = tasks[task]; if ((taskInfo?.models.length ?? 0) <= 0) { throw new InferenceClientInputError( - `No default model defined for task ${task}, please define the model explicitly.` + `No default model defined for task ${task}, please define the model explicitly.`, ); } return taskInfo.models[0].id; @@ -217,7 +217,7 @@ async function loadTaskInfo(): Promise> { const logger = getLogger(); const urlObj = new URL(response.polling_url); @@ -79,7 +79,7 @@ export class BlackForestLabsTextToImageTask extends TaskProviderHelper implement throw new InferenceClientProviderApiError( "Failed to fetch result from black forest labs API", { url: urlObj.toString(), method: "GET", headers: { "Content-Type": "application/json" } }, - { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: await resp.text() } + { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: await resp.text() }, ); } const payload = await resp.json(); @@ -106,7 +106,7 @@ export class BlackForestLabsTextToImageTask extends TaskProviderHelper implement } } throw new InferenceClientProviderOutputError( - `Timed out while waiting for the result from black forest labs API - aborting after 5 attempts` + `Timed out while waiting for the result from black forest labs API - aborting after 5 attempts`, ); } } diff --git a/packages/inference/src/providers/fal-ai.ts b/packages/inference/src/providers/fal-ai.ts index 4a396d663c..5fa7255b6d 100644 --- a/packages/inference/src/providers/fal-ai.ts +++ b/packages/inference/src/providers/fal-ai.ts @@ -106,7 +106,7 @@ abstract class FalAiQueueTask extends FalAITask { async getResponseFromQueueApi( response: FalAiQueueOutput, url?: string, - headers?: Record + headers?: Record, ): Promise { if (!url || !headers) { throw new InferenceClientInputError(`URL and headers are required for ${this.task} task`); @@ -114,7 +114,7 @@ abstract class FalAiQueueTask extends FalAITask { const requestId = response.request_id; if (!requestId) { throw new InferenceClientProviderOutputError( - `Received malformed response from Fal.ai ${this.task} API: no request ID found in the response` + `Received malformed response from Fal.ai ${this.task} API: no request ID found in the response`, ); } let status = response.status; @@ -144,14 +144,14 @@ abstract class FalAiQueueTask extends FalAITask { requestId: statusResponse.headers.get("x-request-id") ?? "", status: statusResponse.status, body: await statusResponse.text(), - } + }, ); } try { status = (await statusResponse.json()).status; } catch (error) { throw new InferenceClientProviderOutputError( - "Failed to parse status response from fal-ai API: received malformed response" + "Failed to parse status response from fal-ai API: received malformed response", ); } } @@ -162,7 +162,7 @@ abstract class FalAiQueueTask extends FalAITask { result = await resultResponse.json(); } catch (error) { throw new InferenceClientProviderOutputError( - "Failed to parse result response from fal-ai API: received malformed response" + "Failed to parse result response from fal-ai API: received malformed response", ); } return result; @@ -207,7 +207,7 @@ export class FalAITextToImageTask extends FalAiQueueTask implements TextToImageT response: FalAiQueueOutput, url?: string, headers?: Record, - outputType?: OutputType + outputType?: OutputType, ): Promise> { const result = (await this.getResponseFromQueueApi(response, url, headers)) as FalAITextToImageOutput; if ( @@ -232,8 +232,8 @@ export class FalAITextToImageTask extends FalAiQueueTask implements TextToImageT throw new InferenceClientProviderOutputError( `Received malformed response from Fal.ai text-to-image API: expected { images: Array<{ url: string }> } result format, got instead: ${JSON.stringify( - result - )}` + result, + )}`, ); } } @@ -261,7 +261,7 @@ export class FalAIImageToImageTask extends FalAiQueueTask implements ImageToImag async preparePayloadAsync(args: ImageToImageArgs): Promise { const mimeType = args.inputs instanceof Blob ? args.inputs.type : "image/png"; const imageDataUrl = `data:${mimeType};base64,${base64FromBytes( - new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()) + new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()), )}`; return { ...omit(args, ["inputs", "parameters"]), @@ -276,7 +276,7 @@ export class FalAIImageToImageTask extends FalAiQueueTask implements ImageToImag override async getResponse( response: FalAiQueueOutput, url?: string, - headers?: Record + headers?: Record, ): Promise { const result = await this.getResponseFromQueueApi(response, url, headers); @@ -297,8 +297,8 @@ export class FalAIImageToImageTask extends FalAiQueueTask implements ImageToImag } else { throw new InferenceClientProviderOutputError( `Received malformed response from Fal.ai image-to-image API: expected { images: Array<{ url: string }> } result format, got instead: ${JSON.stringify( - result - )}` + result, + )}`, ); } } @@ -346,7 +346,7 @@ export class FalAITextToVideoTask extends FalAiQueueTask implements TextToVideoT override async getResponse( response: FalAiQueueOutput, url?: string, - headers?: Record + headers?: Record, ): Promise { const result = await this.getResponseFromQueueApi(response, url, headers); @@ -365,8 +365,8 @@ export class FalAITextToVideoTask extends FalAiQueueTask implements TextToVideoT } else { throw new InferenceClientProviderOutputError( `Received malformed response from Fal.ai text-to-video API: expected { video: { url: string } } result format, got instead: ${JSON.stringify( - result - )}` + result, + )}`, ); } } @@ -396,7 +396,7 @@ export class FalAIImageToVideoTask extends FalAiQueueTask implements ImageToVide return { ...omit(args, ["inputs", "parameters"]), image_url: `data:${mimeType};base64,${base64FromBytes( - new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()) + new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()), )}`, ...args.parameters, ...args, @@ -407,7 +407,7 @@ export class FalAIImageToVideoTask extends FalAiQueueTask implements ImageToVide override async getResponse( response: FalAiQueueOutput, url?: string, - headers?: Record + headers?: Record, ): Promise { const result = await this.getResponseFromQueueApi(response, url, headers); @@ -428,8 +428,8 @@ export class FalAIImageToVideoTask extends FalAiQueueTask implements ImageToVide throw new InferenceClientProviderOutputError( `Received malformed response from Fal.ai image‑to‑video API: expected { video: { url: string } }, got: ${JSON.stringify( - result - )}` + result, + )}`, ); } } @@ -468,8 +468,8 @@ export class FalAIAutomaticSpeechRecognitionTask extends FalAITask implements Au if (typeof res?.text !== "string") { throw new InferenceClientProviderOutputError( `Received malformed response from Fal.ai Automatic Speech Recognition API: expected { text: string } format, got instead: ${JSON.stringify( - response - )}` + response, + )}`, ); } return { text: res.text }; @@ -480,14 +480,14 @@ export class FalAIAutomaticSpeechRecognitionTask extends FalAITask implements Au const contentType = blob?.type; if (!contentType) { throw new InferenceClientInputError( - `Unable to determine the input's content-type. Make sure your are passing a Blob when using provider fal-ai.` + `Unable to determine the input's content-type. Make sure your are passing a Blob when using provider fal-ai.`, ); } if (!FAL_AI_SUPPORTED_BLOB_TYPES.includes(contentType)) { throw new InferenceClientInputError( `Provider fal-ai does not support blob type ${contentType} - supported content types are: ${FAL_AI_SUPPORTED_BLOB_TYPES.join( - ", " - )}` + ", ", + )}`, ); } const base64audio = base64FromBytes(new Uint8Array(await blob.arrayBuffer())); @@ -512,8 +512,8 @@ export class FalAITextToSpeechTask extends FalAITask { if (typeof res?.audio?.url !== "string") { throw new InferenceClientProviderOutputError( `Received malformed response from Fal.ai Text-to-Speech API: expected { audio: { url: string } } format, got instead: ${JSON.stringify( - response - )}` + response, + )}`, ); } const urlResponse = await fetch(res.audio.url); @@ -525,7 +525,7 @@ export class FalAITextToSpeechTask extends FalAITask { requestId: urlResponse.headers.get("x-request-id") ?? "", status: urlResponse.status, body: await urlResponse.text(), - } + }, ); } try { @@ -538,7 +538,7 @@ export class FalAITextToSpeechTask extends FalAITask { requestId: urlResponse.headers.get("x-request-id") ?? "", status: urlResponse.status, body: await urlResponse.text(), - } + }, ); } } @@ -562,7 +562,7 @@ export class FalAIImageSegmentationTask extends FalAiQueueTask implements ImageS const blob = "data" in args && args.data instanceof Blob ? args.data : "inputs" in args ? args.inputs : undefined; const mimeType = blob instanceof Blob ? blob.type : "image/png"; const base64Image = base64FromBytes( - new Uint8Array(blob instanceof ArrayBuffer ? blob : await (blob as Blob).arrayBuffer()) + new Uint8Array(blob instanceof ArrayBuffer ? blob : await (blob as Blob).arrayBuffer()), ); return { ...omit(args, ["inputs", "parameters", "data"]), @@ -576,7 +576,7 @@ export class FalAIImageSegmentationTask extends FalAiQueueTask implements ImageS override async getResponse( response: FalAiQueueOutput, url?: string, - headers?: Record + headers?: Record, ): Promise { const result = await this.getResponseFromQueueApi(response, url, headers); if ( @@ -597,7 +597,7 @@ export class FalAIImageSegmentationTask extends FalAiQueueTask implements ImageS requestId: maskResponse.headers.get("x-request-id") ?? "", status: maskResponse.status, body: await maskResponse.text(), - } + }, ); } const maskBlob = await maskResponse.blob(); @@ -615,8 +615,8 @@ export class FalAIImageSegmentationTask extends FalAiQueueTask implements ImageS throw new InferenceClientProviderOutputError( `Received malformed response from Fal.ai image-segmentation API: expected { image: { url: string } } format, got instead: ${JSON.stringify( - response - )}` + response, + )}`, ); } } diff --git a/packages/inference/src/providers/featherless-ai.ts b/packages/inference/src/providers/featherless-ai.ts index 249ee28aa9..2d1f856266 100644 --- a/packages/inference/src/providers/featherless-ai.ts +++ b/packages/inference/src/providers/featherless-ai.ts @@ -40,7 +40,7 @@ export class FeatherlessAITextGenerationTask extends BaseTextGenerationTask { ? { max_tokens: params.args.parameters.max_new_tokens, ...omit(params.args.parameters, "max_new_tokens"), - } + } : undefined), prompt: params.args.inputs, }; diff --git a/packages/inference/src/providers/hf-inference.ts b/packages/inference/src/providers/hf-inference.ts index 914f9d2a07..a1614a7c86 100644 --- a/packages/inference/src/providers/hf-inference.ts +++ b/packages/inference/src/providers/hf-inference.ts @@ -127,7 +127,7 @@ export class HFInferenceTextToImageTask extends HFInferenceTask implements TextT override preparePayload(params: BodyParams): Record { if (params.outputType === "url") { throw new InferenceClientInputError( - "hf-inference provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead." + "hf-inference provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead.", ); } return params.args; @@ -137,11 +137,11 @@ export class HFInferenceTextToImageTask extends HFInferenceTask implements TextT response: Base64ImageGeneration | OutputUrlImageGeneration, url?: string, headers?: HeadersInit, - outputType?: OutputType + outputType?: OutputType, ): Promise> { if (!response) { throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference text-to-image API: response is undefined" + "Received malformed response from HF-Inference text-to-image API: response is undefined", ); } if (typeof response == "object") { @@ -172,7 +172,7 @@ export class HFInferenceTextToImageTask extends HFInferenceTask implements TextT return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference text-to-image API: expected a Blob" + "Received malformed response from HF-Inference text-to-image API: expected a Blob", ); } } @@ -215,7 +215,7 @@ export class HFInferenceTextGenerationTask extends HFInferenceTask implements Te return (res as TextGenerationOutput[])?.[0]; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference text generation API: expected Array<{generated_text: string}>" + "Received malformed response from HF-Inference text generation API: expected Array<{generated_text: string}>", ); } } @@ -226,13 +226,13 @@ export class HFInferenceAudioClassificationTask extends HFInferenceTask implemen Array.isArray(response) && response.every( (x): x is { label: string; score: number } => - typeof x === "object" && x !== null && typeof x.label === "string" && typeof x.score === "number" + typeof x === "object" && x !== null && typeof x.label === "string" && typeof x.score === "number", ) ) { return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference audio-classification API: expected Array<{label: string, score: number}> but received different format" + "Received malformed response from HF-Inference audio-classification API: expected Array<{label: string, score: number}> but received different format", ); } } @@ -251,7 +251,7 @@ export class HFInferenceAutomaticSpeechRecognitionTask : { ...omit(args, "inputs"), data: args.inputs, - }; + }; } } @@ -259,7 +259,7 @@ export class HFInferenceAudioToAudioTask extends HFInferenceTask implements Audi override async getResponse(response: AudioToAudioOutput[]): Promise { if (!Array.isArray(response)) { throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference audio-to-audio API: expected Array" + "Received malformed response from HF-Inference audio-to-audio API: expected Array", ); } if ( @@ -277,7 +277,7 @@ export class HFInferenceAudioToAudioTask extends HFInferenceTask implements Audi }) ) { throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference audio-to-audio API: expected Array<{label: string, audio: Blob}>" + "Received malformed response from HF-Inference audio-to-audio API: expected Array<{label: string, audio: Blob}>", ); } return response; @@ -289,7 +289,7 @@ export class HFInferenceDocumentQuestionAnsweringTask implements DocumentQuestionAnsweringTaskHelper { override async getResponse( - response: DocumentQuestionAnsweringOutput + response: DocumentQuestionAnsweringOutput, ): Promise { if ( Array.isArray(response) && @@ -300,13 +300,13 @@ export class HFInferenceDocumentQuestionAnsweringTask typeof elem?.answer === "string" && (typeof elem.end === "number" || typeof elem.end === "undefined") && (typeof elem.score === "number" || typeof elem.score === "undefined") && - (typeof elem.start === "number" || typeof elem.start === "undefined") + (typeof elem.start === "number" || typeof elem.start === "undefined"), ) ) { return response[0]; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference document-question-answering API: expected Array<{answer: string, end: number, score: number, start: number}>" + "Received malformed response from HF-Inference document-question-answering API: expected Array<{answer: string, end: number, score: number, start: number}>", ); } } @@ -325,7 +325,7 @@ export class HFInferenceFeatureExtractionTask extends HFInferenceTask implements return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference feature-extraction API: expected Array" + "Received malformed response from HF-Inference feature-extraction API: expected Array", ); } } @@ -336,7 +336,7 @@ export class HFInferenceImageClassificationTask extends HFInferenceTask implemen return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference image-classification API: expected Array<{label: string, score: number}>" + "Received malformed response from HF-Inference image-classification API: expected Array<{label: string, score: number}>", ); } } @@ -349,13 +349,13 @@ export class HFInferenceImageSegmentationTask extends HFInferenceTask implements (x) => typeof x.label === "string" && typeof x.mask === "string" && - (x.score === undefined || typeof x.score === "number") + (x.score === undefined || typeof x.score === "number"), ) ) { return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference image-segmentation API: expected Array<{label: string, mask: string, score: number}>" + "Received malformed response from HF-Inference image-segmentation API: expected Array<{label: string, mask: string, score: number}>", ); } @@ -363,7 +363,7 @@ export class HFInferenceImageSegmentationTask extends HFInferenceTask implements return { ...args, inputs: base64FromBytes( - new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()) + new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()), ), }; } @@ -373,7 +373,7 @@ export class HFInferenceImageToTextTask extends HFInferenceTask implements Image override async getResponse(response: ImageToTextOutput): Promise { if (typeof response?.generated_text !== "string") { throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference image-to-text API: expected {generated_text: string}" + "Received malformed response from HF-Inference image-to-text API: expected {generated_text: string}", ); } return response; @@ -392,7 +392,7 @@ export class HFInferenceImageToImageTask extends HFInferenceTask implements Imag return { ...args, inputs: base64FromBytes( - new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()) + new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()), ), }; } @@ -403,7 +403,7 @@ export class HFInferenceImageToImageTask extends HFInferenceTask implements Imag return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference image-to-image API: expected Blob" + "Received malformed response from HF-Inference image-to-image API: expected Blob", ); } } @@ -419,13 +419,13 @@ export class HFInferenceObjectDetectionTask extends HFInferenceTask implements O typeof x.box.xmin === "number" && typeof x.box.ymin === "number" && typeof x.box.xmax === "number" && - typeof x.box.ymax === "number" + typeof x.box.ymax === "number", ) ) { return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference object-detection API: expected Array<{label: string, score: number, box: {xmin: number, ymin: number, xmax: number, ymax: number}}>" + "Received malformed response from HF-Inference object-detection API: expected Array<{label: string, score: number, box: {xmin: number, ymin: number, xmax: number, ymax: number}}>", ); } } @@ -439,7 +439,7 @@ export class HFInferenceZeroShotImageClassificationTask return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference zero-shot-image-classification API: expected Array<{label: string, score: number}>" + "Received malformed response from HF-Inference zero-shot-image-classification API: expected Array<{label: string, score: number}>", ); } } @@ -451,14 +451,14 @@ export class HFInferenceTextClassificationTask extends HFInferenceTask implement return output; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference text-classification API: expected Array<{label: string, score: number}>" + "Received malformed response from HF-Inference text-classification API: expected Array<{label: string, score: number}>", ); } } export class HFInferenceQuestionAnsweringTask extends HFInferenceTask implements QuestionAnsweringTaskHelper { override async getResponse( - response: QuestionAnsweringOutput | QuestionAnsweringOutput[number] + response: QuestionAnsweringOutput | QuestionAnsweringOutput[number], ): Promise { if ( Array.isArray(response) @@ -469,19 +469,19 @@ export class HFInferenceQuestionAnsweringTask extends HFInferenceTask implements typeof elem.answer === "string" && typeof elem.end === "number" && typeof elem.score === "number" && - typeof elem.start === "number" - ) + typeof elem.start === "number", + ) : typeof response === "object" && - !!response && - typeof response.answer === "string" && - typeof response.end === "number" && - typeof response.score === "number" && - typeof response.start === "number" + !!response && + typeof response.answer === "string" && + typeof response.end === "number" && + typeof response.score === "number" && + typeof response.start === "number" ) { return Array.isArray(response) ? response[0] : response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference question-answering API: expected Array<{answer: string, end: number, score: number, start: number}>" + "Received malformed response from HF-Inference question-answering API: expected Array<{answer: string, end: number, score: number, start: number}>", ); } } @@ -495,13 +495,13 @@ export class HFInferenceFillMaskTask extends HFInferenceTask implements FillMask typeof x.score === "number" && typeof x.sequence === "string" && typeof x.token === "number" && - typeof x.token_str === "string" + typeof x.token_str === "string", ) ) { return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference fill-mask API: expected Array<{score: number, sequence: string, token: number, token_str: string}>" + "Received malformed response from HF-Inference fill-mask API: expected Array<{score: number, sequence: string, token: number, token_str: string}>", ); } } @@ -531,7 +531,7 @@ export class HFInferenceZeroShotClassificationTask extends HFInferenceTask imple return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference zero-shot-classification API: expected Array<{label: string, score: number}>" + "Received malformed response from HF-Inference zero-shot-classification API: expected Array<{label: string, score: number}>", ); } @@ -553,7 +553,7 @@ export class HFInferenceSentenceSimilarityTask extends HFInferenceTask implement return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference sentence-similarity API: expected Array" + "Received malformed response from HF-Inference sentence-similarity API: expected Array", ); } } @@ -573,7 +573,7 @@ export class HFInferenceTableQuestionAnsweringTask extends HFInferenceTask imple "coordinates" in elem && Array.isArray(elem.coordinates) && elem.coordinates.every( - (coord: unknown): coord is number[] => Array.isArray(coord) && coord.every((x) => typeof x === "number") + (coord: unknown): coord is number[] => Array.isArray(coord) && coord.every((x) => typeof x === "number"), ) ); } @@ -586,7 +586,7 @@ export class HFInferenceTableQuestionAnsweringTask extends HFInferenceTask imple return Array.isArray(response) ? response[0] : response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference table-question-answering API: expected {aggregator: string, answer: string, cells: string[], coordinates: number[][]}" + "Received malformed response from HF-Inference table-question-answering API: expected {aggregator: string, answer: string, cells: string[], coordinates: number[][]}", ); } } @@ -601,13 +601,13 @@ export class HFInferenceTokenClassificationTask extends HFInferenceTask implemen typeof x.entity_group === "string" && typeof x.score === "number" && typeof x.start === "number" && - typeof x.word === "string" + typeof x.word === "string", ) ) { return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference token-classification API: expected Array<{end: number, entity_group: string, score: number, start: number, word: string}>" + "Received malformed response from HF-Inference token-classification API: expected Array<{end: number, entity_group: string, score: number, start: number, word: string}>", ); } } @@ -618,7 +618,7 @@ export class HFInferenceTranslationTask extends HFInferenceTask implements Trans return response?.length === 1 ? response?.[0] : response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference translation API: expected Array<{translation_text: string}>" + "Received malformed response from HF-Inference translation API: expected Array<{translation_text: string}>", ); } } @@ -629,7 +629,7 @@ export class HFInferenceSummarizationTask extends HFInferenceTask implements Sum return response?.[0]; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference summarization API: expected Array<{summary_text: string}>" + "Received malformed response from HF-Inference summarization API: expected Array<{summary_text: string}>", ); } } @@ -646,7 +646,7 @@ export class HFInferenceTabularClassificationTask extends HFInferenceTask implem return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference tabular-classification API: expected Array" + "Received malformed response from HF-Inference tabular-classification API: expected Array", ); } } @@ -660,13 +660,13 @@ export class HFInferenceVisualQuestionAnsweringTask Array.isArray(response) && response.every( (elem) => - typeof elem === "object" && !!elem && typeof elem?.answer === "string" && typeof elem.score === "number" + typeof elem === "object" && !!elem && typeof elem?.answer === "string" && typeof elem.score === "number", ) ) { return response[0]; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference visual-question-answering API: expected Array<{answer: string, score: number}>" + "Received malformed response from HF-Inference visual-question-answering API: expected Array<{answer: string, score: number}>", ); } } @@ -677,7 +677,7 @@ export class HFInferenceTabularRegressionTask extends HFInferenceTask implements return response; } throw new InferenceClientProviderOutputError( - "Received malformed response from HF-Inference tabular-regression API: expected Array" + "Received malformed response from HF-Inference tabular-regression API: expected Array", ); } } diff --git a/packages/inference/src/providers/hyperbolic.ts b/packages/inference/src/providers/hyperbolic.ts index aad6607e82..6d46311bbb 100644 --- a/packages/inference/src/providers/hyperbolic.ts +++ b/packages/inference/src/providers/hyperbolic.ts @@ -58,7 +58,7 @@ export class HyperbolicTextGenerationTask extends BaseTextGenerationTask { ? { max_tokens: (params.args.parameters as Record).max_new_tokens, ...omit(params.args.parameters as Record, "max_new_tokens"), - } + } : undefined), ...omit(params.args, ["inputs", "parameters"]), model: params.model, @@ -95,7 +95,7 @@ export class HyperbolicTextToImageTask extends TaskProviderHelper implements Tex preparePayload(params: BodyParams): Record { if (params.outputType === "url") { throw new InferenceClientInputError( - "hyperbolic provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead." + "hyperbolic provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead.", ); } return { @@ -110,7 +110,7 @@ export class HyperbolicTextToImageTask extends TaskProviderHelper implements Tex response: HyperbolicTextToImageOutput, url?: string, headers?: HeadersInit, - outputType?: OutputType + outputType?: OutputType, ): Promise> { if ( typeof response === "object" && diff --git a/packages/inference/src/providers/nebius.ts b/packages/inference/src/providers/nebius.ts index ed838a5179..4098d6f175 100644 --- a/packages/inference/src/providers/nebius.ts +++ b/packages/inference/src/providers/nebius.ts @@ -117,7 +117,7 @@ export class NebiusTextToImageTask extends TaskProviderHelper implements TextToI response: NebiusImageGeneration, url?: string, headers?: HeadersInit, - outputType?: OutputType + outputType?: OutputType, ): Promise> { if ( typeof response === "object" && diff --git a/packages/inference/src/providers/novita.ts b/packages/inference/src/providers/novita.ts index 13c8ee2832..471af6a961 100644 --- a/packages/inference/src/providers/novita.ts +++ b/packages/inference/src/providers/novita.ts @@ -79,7 +79,7 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV override async getResponse( response: NovitaAsyncAPIOutput, url?: string, - headers?: Record + headers?: Record, ): Promise { if (!url || !headers) { throw new InferenceClientInputError("URL and headers are required for text-to-video task"); @@ -87,7 +87,7 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV const taskId = response.task_id; if (!taskId) { throw new InferenceClientProviderOutputError( - "Received malformed response from Novita text-to-video API: no task ID found in the response" + "Received malformed response from Novita text-to-video API: no task ID found in the response", ); } @@ -111,7 +111,7 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV requestId: resultResponse.headers.get("x-request-id") ?? "", status: resultResponse.status, body: await resultResponse.text(), - } + }, ); } try { @@ -128,12 +128,12 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV status = taskResult.task.status; } else { throw new InferenceClientProviderOutputError( - "Received malformed response from Novita text-to-video API: failed to get task status" + "Received malformed response from Novita text-to-video API: failed to get task status", ); } } catch (error) { throw new InferenceClientProviderOutputError( - "Received malformed response from Novita text-to-video API: failed to parse task result" + "Received malformed response from Novita text-to-video API: failed to parse task result", ); } } @@ -159,8 +159,8 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV } else { throw new InferenceClientProviderOutputError( `Received malformed response from Novita text-to-video API: expected { videos: [{ video_url: string }] } format, got instead: ${JSON.stringify( - taskResult - )}` + taskResult, + )}`, ); } } diff --git a/packages/inference/src/providers/nscale.ts b/packages/inference/src/providers/nscale.ts index 6f9ddba785..8115a4d750 100644 --- a/packages/inference/src/providers/nscale.ts +++ b/packages/inference/src/providers/nscale.ts @@ -42,7 +42,7 @@ export class NscaleTextToImageTask extends TaskProviderHelper implements TextToI preparePayload(params: BodyParams): Record { if (params.outputType === "url") { throw new InferenceClientInputError( - "nscale provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead." + "nscale provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead.", ); } return { @@ -62,7 +62,7 @@ export class NscaleTextToImageTask extends TaskProviderHelper implements TextToI response: NscaleCloudBase64ImageGeneration, url?: string, headers?: HeadersInit, - outputType?: OutputType + outputType?: OutputType, ): Promise> { if ( typeof response === "object" && diff --git a/packages/inference/src/providers/ovhcloud.ts b/packages/inference/src/providers/ovhcloud.ts index ff9c52f961..de8c190ce9 100644 --- a/packages/inference/src/providers/ovhcloud.ts +++ b/packages/inference/src/providers/ovhcloud.ts @@ -52,7 +52,7 @@ export class OvhCloudTextGenerationTask extends BaseTextGenerationTask { ? { max_tokens: (params.args.parameters as Record).max_new_tokens, ...omit(params.args.parameters as Record, "max_new_tokens"), - } + } : undefined), prompt: params.args.inputs, }; diff --git a/packages/inference/src/providers/providerHelper.ts b/packages/inference/src/providers/providerHelper.ts index e33d092180..6343c7b8f7 100644 --- a/packages/inference/src/providers/providerHelper.ts +++ b/packages/inference/src/providers/providerHelper.ts @@ -75,7 +75,7 @@ export abstract class TaskProviderHelper { constructor( readonly provider: InferenceProvider, protected baseUrl: string, - readonly clientSideRoutingOnly: boolean = false + readonly clientSideRoutingOnly: boolean = false, ) {} /** @@ -86,7 +86,7 @@ export abstract class TaskProviderHelper { response: unknown, url?: string, headers?: HeadersInit, - outputType?: OutputType + outputType?: OutputType, ): Promise; /** @@ -152,7 +152,7 @@ export interface TextToImageTaskHelper { response: unknown, url?: string, headers?: HeadersInit, - outputType?: OutputType + outputType?: OutputType, ): Promise>; preparePayload(params: BodyParams): Record; } @@ -282,7 +282,7 @@ export interface TextToAudioTaskHelper { export interface AudioToAudioTaskHelper { getResponse(response: unknown, url?: string, headers?: HeadersInit): Promise; preparePayload( - params: BodyParams> + params: BodyParams>, ): Record | BodyInit; } export interface AutomaticSpeechRecognitionTaskHelper { @@ -315,14 +315,14 @@ export interface VisualQuestionAnsweringTaskHelper { export interface TabularClassificationTaskHelper { getResponse(response: unknown, url?: string, headers?: HeadersInit): Promise; preparePayload( - params: BodyParams } } & Record> + params: BodyParams } } & Record>, ): Record | BodyInit; } export interface TabularRegressionTaskHelper { getResponse(response: unknown, url?: string, headers?: HeadersInit): Promise; preparePayload( - params: BodyParams } } & Record> + params: BodyParams } } & Record>, ): Record | BodyInit; } @@ -387,7 +387,7 @@ export class BaseTextGenerationTask extends TaskProviderHelper implements TextGe res.length > 0 && res.every( (x): x is { generated_text: string } => - typeof x === "object" && !!x && "generated_text" in x && typeof x.generated_text === "string" + typeof x === "object" && !!x && "generated_text" in x && typeof x.generated_text === "string", ) ) { return res[0]; diff --git a/packages/inference/src/providers/replicate.ts b/packages/inference/src/providers/replicate.ts index d627d3ce6b..6933ab76dd 100644 --- a/packages/inference/src/providers/replicate.ts +++ b/packages/inference/src/providers/replicate.ts @@ -92,7 +92,7 @@ export class ReplicateTextToImageTask extends ReplicateTask implements TextToIma res: ReplicateOutput | Blob, url?: string, headers?: Record, - outputType?: OutputType + outputType?: OutputType, ): Promise> { void url; void headers; @@ -236,7 +236,7 @@ export class ReplicateAutomaticSpeechRecognitionTask } } throw new InferenceClientProviderOutputError( - "Received malformed response from Replicate automatic-speech-recognition API" + "Received malformed response from Replicate automatic-speech-recognition API", ); } } diff --git a/packages/inference/src/providers/sambanova.ts b/packages/inference/src/providers/sambanova.ts index 7c66f81733..5de3778a32 100644 --- a/packages/inference/src/providers/sambanova.ts +++ b/packages/inference/src/providers/sambanova.ts @@ -54,7 +54,7 @@ export class SambanovaFeatureExtractionTask extends TaskProviderHelper implement return response.data.map((item) => item.embedding); } throw new InferenceClientProviderOutputError( - "Received malformed response from Sambanova feature-extraction (embeddings) API" + "Received malformed response from Sambanova feature-extraction (embeddings) API", ); } diff --git a/packages/inference/src/providers/together.ts b/packages/inference/src/providers/together.ts index cd30969271..2f911d26ed 100644 --- a/packages/inference/src/providers/together.ts +++ b/packages/inference/src/providers/together.ts @@ -119,7 +119,7 @@ export class TogetherTextToImageTask extends TaskProviderHelper implements TextT response: TogetherImageGeneration, url?: string, headers?: HeadersInit, - outputType?: OutputType + outputType?: OutputType, ): Promise> { if ( typeof response === "object" && diff --git a/packages/inference/src/providers/wavespeed.ts b/packages/inference/src/providers/wavespeed.ts index ba4aeb23b5..788456f5eb 100644 --- a/packages/inference/src/providers/wavespeed.ts +++ b/packages/inference/src/providers/wavespeed.ts @@ -76,10 +76,10 @@ interface WaveSpeedAISubmitTaskResponse { async function buildImagesField( inputs: Blob | ArrayBuffer, - hasImages: unknown + hasImages: unknown, ): Promise<{ base: string; images: string[] }> { const base = base64FromBytes( - new Uint8Array(inputs instanceof ArrayBuffer ? inputs : await (inputs as Blob).arrayBuffer()) + new Uint8Array(inputs instanceof ArrayBuffer ? inputs : await (inputs as Blob).arrayBuffer()), ); const images = Array.isArray(hasImages) && hasImages.every((value): value is string => typeof value === "string") @@ -105,7 +105,7 @@ abstract class WavespeedAITask extends TaskProviderHelper { | TextToImageArgs | TextToVideoArgs | ImageToVideoArgs - > + >, ): Record { const payload: Record = { ...omit(params.args, ["inputs", "parameters"]), @@ -128,7 +128,7 @@ abstract class WavespeedAITask extends TaskProviderHelper { response: WaveSpeedAISubmitTaskResponse, url?: string, headers?: Record, - outputType?: OutputType + outputType?: OutputType, ): Promise> { if (!url || !headers) { throw new InferenceClientInputError("Headers are required for WaveSpeed AI API calls"); @@ -154,7 +154,7 @@ abstract class WavespeedAITask extends TaskProviderHelper { requestId: resultResponse.headers.get("x-request-id") ?? "", status: resultResponse.status, body: await resultResponse.text(), - } + }, ); } @@ -166,7 +166,7 @@ abstract class WavespeedAITask extends TaskProviderHelper { // Get the media data from the first output URL if (!taskResult.outputs?.[0]) { throw new InferenceClientProviderOutputError( - "Received malformed response from WaveSpeed AI API: No output URL in completed response" + "Received malformed response from WaveSpeed AI API: No output URL in completed response", ); } const mediaUrl = taskResult.outputs[0]; @@ -188,7 +188,7 @@ abstract class WavespeedAITask extends TaskProviderHelper { requestId: mediaResponse.headers.get("x-request-id") ?? "", status: mediaResponse.status, body: await mediaResponse.text(), - } + }, ); } const blob = await mediaResponse.blob(); @@ -222,7 +222,7 @@ export class WavespeedAITextToVideoTask extends WavespeedAITask implements TextT override async getResponse( response: WaveSpeedAISubmitTaskResponse, url?: string, - headers?: Record + headers?: Record, ): Promise { return super.getResponse(response, url, headers) as Promise; } @@ -243,7 +243,7 @@ export class WavespeedAIImageToImageTask extends WavespeedAITask implements Imag override async getResponse( response: WaveSpeedAISubmitTaskResponse, url?: string, - headers?: Record + headers?: Record, ): Promise { return super.getResponse(response, url, headers) as Promise; } @@ -264,7 +264,7 @@ export class WavespeedAIImageToVideoTask extends WavespeedAITask implements Imag override async getResponse( response: WaveSpeedAISubmitTaskResponse, url?: string, - headers?: Record + headers?: Record, ): Promise { return super.getResponse(response, url, headers) as Promise; } diff --git a/packages/inference/src/providers/zai-org.ts b/packages/inference/src/providers/zai-org.ts index 95d2267bbe..2944f8c554 100644 --- a/packages/inference/src/providers/zai-org.ts +++ b/packages/inference/src/providers/zai-org.ts @@ -97,7 +97,7 @@ export class ZaiTextToImageTask extends TaskProviderHelper implements TextToImag response: ZaiTextToImageResponse, url?: string, headers?: Record, - outputType?: OutputType + outputType?: OutputType, ): Promise> { if (!url || !headers) { throw new InferenceClientInputError(`URL and headers are required for 'text-to-image' task`); @@ -111,8 +111,8 @@ export class ZaiTextToImageTask extends TaskProviderHelper implements TextToImag ) { throw new InferenceClientProviderOutputError( `Received malformed response from ZAI text-to-image API: expected { id: string, task_status: string }, got: ${JSON.stringify( - response - )}` + response, + )}`, ); } @@ -145,7 +145,7 @@ export class ZaiTextToImageTask extends TaskProviderHelper implements TextToImag throw new InferenceClientProviderApiError( `Failed to fetch result from ZAI text-to-image API: ${resp.status}`, { url: pollUrl, method: "GET" }, - { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: await resp.text() } + { requestId: resp.headers.get("x-request-id") ?? "", status: resp.status, body: await resp.text() }, ); } @@ -165,8 +165,8 @@ export class ZaiTextToImageTask extends TaskProviderHelper implements TextToImag ) { throw new InferenceClientProviderOutputError( `Received malformed response from ZAI text-to-image API: expected { image_result: Array<{ url: string }> }, got: ${JSON.stringify( - result - )}` + result, + )}`, ); } @@ -186,7 +186,7 @@ export class ZaiTextToImageTask extends TaskProviderHelper implements TextToImag } throw new InferenceClientProviderOutputError( - `Timed out while waiting for the result from ZAI API - aborting after ${MAX_POLL_ATTEMPTS} attempts` + `Timed out while waiting for the result from ZAI API - aborting after ${MAX_POLL_ATTEMPTS} attempts`, ); } } diff --git a/packages/inference/src/snippets/getInferenceSnippets.ts b/packages/inference/src/snippets/getInferenceSnippets.ts index d9ecdbc36b..43e5b15de3 100644 --- a/packages/inference/src/snippets/getInferenceSnippets.ts +++ b/packages/inference/src/snippets/getInferenceSnippets.ts @@ -72,7 +72,7 @@ const hasTemplate = (language: InferenceSnippetLanguage, client: Client, templat const loadTemplate = ( language: InferenceSnippetLanguage, client: Client, - templateName: string + templateName: string, ): ((data: TemplateParams) => string) => { const template = templates[language]?.[client]?.[templateName]; if (!template) { @@ -148,7 +148,7 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar model: ModelDataMinimal, provider: InferenceProviderOrPolicy, inferenceProviderMapping?: InferenceProviderMappingEntry, - opts?: InferenceSnippetOptions + opts?: InferenceSnippetOptions, ): InferenceSnippet[] => { const logger = getLogger(); const providerModelId = inferenceProviderMapping?.providerId ?? model.id; @@ -180,8 +180,8 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar const inputs = opts?.inputs ? { inputs: opts.inputs } : inputPreparationFn - ? inputPreparationFn(model, opts) - : { inputs: getModelInputSnippet(model) }; + ? inputPreparationFn(model, opts) + : { inputs: getModelInputSnippet(model) }; const request = makeRequestOptionsFromResolvedModel( providerModelId, providerHelper, @@ -195,7 +195,7 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar { task, billTo: opts?.billTo, - } + }, ); /// Parse request.info.body if not a binary. @@ -218,11 +218,11 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar ? { ...inputs, model: `${model.id}:${provider}`, - } + } : { ...inputs, model: `${model.id}`, // if no :provider => auto - } + } : providerInputs; /// Prepare template injection data @@ -265,7 +265,7 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar ? provider !== "auto" ? `${model.id}:${provider}` // e.g. "moonshotai/Kimi-K2-Instruct:groq" : model.id - : providerModelId ?? model.id, + : (providerModelId ?? model.id), billTo: opts?.billTo, endpointUrl: opts?.endpointUrl, task, @@ -324,7 +324,7 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar snippet, language, provider, - opts?.endpointUrl + opts?.endpointUrl, ); } @@ -354,7 +354,7 @@ const prepareConversationalInput = ( temperature?: GenerationParameters["temperature"]; max_tokens?: GenerationParameters["max_new_tokens"]; top_p?: GenerationParameters["top_p"]; - } + }, ): object => { return { messages: opts?.messages ?? getModelInputSnippet(model), @@ -381,7 +381,7 @@ const snippets: Partial< model: ModelDataMinimal, provider: InferenceProviderOrPolicy, inferenceProviderMapping?: InferenceProviderMappingEntry, - opts?: InferenceSnippetOptions + opts?: InferenceSnippetOptions, ) => InferenceSnippet[] > > = { @@ -422,10 +422,10 @@ export function getInferenceSnippets( model: ModelDataMinimal, provider: InferenceProviderOrPolicy, inferenceProviderMapping?: InferenceProviderMappingEntry, - opts?: Record + opts?: Record, ): InferenceSnippet[] { return model.pipeline_tag && model.pipeline_tag in snippets - ? snippets[model.pipeline_tag]?.(model, provider, inferenceProviderMapping, opts) ?? [] + ? (snippets[model.pipeline_tag]?.(model, provider, inferenceProviderMapping, opts) ?? []) : []; } @@ -447,7 +447,7 @@ function formatBody(obj: object, format: "curl" | "json" | "python" | "ts"): str const formattedValue = JSON.stringify(value, null, 4).replace(/"/g, '"'); return `${key}=${formattedValue},`; }) - .join("\n") + .join("\n"), ); case "ts": @@ -507,7 +507,7 @@ function replaceAccessTokenPlaceholder( snippet: string, language: InferenceSnippetLanguage, provider: InferenceProviderOrPolicy, - endpointUrl?: string + endpointUrl?: string, ): string { // If "opts.accessToken" is not set, the snippets are generated with a placeholder. // Once snippets are rendered, we replace the placeholder with code to fetch the access token from an environment variable. @@ -522,49 +522,49 @@ function replaceAccessTokenPlaceholder( const accessTokenEnvVar = useHfToken ? "HF_TOKEN" // e.g. routed request or hf-inference : endpointUrl - ? "API_TOKEN" - : provider.toUpperCase().replace("-", "_") + "_API_KEY"; // e.g. "REPLICATE_API_KEY" + ? "API_TOKEN" + : provider.toUpperCase().replace("-", "_") + "_API_KEY"; // e.g. "REPLICATE_API_KEY" // Replace the placeholder with the env variable if (language === "sh") { snippet = snippet.replace( `'Authorization: Bearer ${placeholder}'`, - `"Authorization: Bearer $${accessTokenEnvVar}"` // e.g. "Authorization: Bearer $HF_TOKEN" + `"Authorization: Bearer $${accessTokenEnvVar}"`, // e.g. "Authorization: Bearer $HF_TOKEN" ); } else if (language === "python") { snippet = "import os\n" + snippet; snippet = snippet.replace( `"${placeholder}"`, - `os.environ["${accessTokenEnvVar}"]` // e.g. os.environ["HF_TOKEN") + `os.environ["${accessTokenEnvVar}"]`, // e.g. os.environ["HF_TOKEN") ); snippet = snippet.replace( `"Bearer ${placeholder}"`, - `f"Bearer {os.environ['${accessTokenEnvVar}']}"` // e.g. f"Bearer {os.environ['HF_TOKEN']}" + `f"Bearer {os.environ['${accessTokenEnvVar}']}"`, // e.g. f"Bearer {os.environ['HF_TOKEN']}" ); snippet = snippet.replace( `"Key ${placeholder}"`, - `f"Key {os.environ['${accessTokenEnvVar}']}"` // e.g. f"Key {os.environ['FAL_AI_API_KEY']}" + `f"Key {os.environ['${accessTokenEnvVar}']}"`, // e.g. f"Key {os.environ['FAL_AI_API_KEY']}" ); snippet = snippet.replace( `"X-Key ${placeholder}"`, - `f"X-Key {os.environ['${accessTokenEnvVar}']}"` // e.g. f"X-Key {os.environ['BLACK_FOREST_LABS_API_KEY']}" + `f"X-Key {os.environ['${accessTokenEnvVar}']}"`, // e.g. f"X-Key {os.environ['BLACK_FOREST_LABS_API_KEY']}" ); } else if (language === "js") { snippet = snippet.replace( `"${placeholder}"`, - `process.env.${accessTokenEnvVar}` // e.g. process.env.HF_TOKEN + `process.env.${accessTokenEnvVar}`, // e.g. process.env.HF_TOKEN ); snippet = snippet.replace( `Authorization: "Bearer ${placeholder}",`, - `Authorization: \`Bearer $\{process.env.${accessTokenEnvVar}}\`,` // e.g. Authorization: `Bearer ${process.env.HF_TOKEN}`, + `Authorization: \`Bearer $\{process.env.${accessTokenEnvVar}}\`,`, // e.g. Authorization: `Bearer ${process.env.HF_TOKEN}`, ); snippet = snippet.replace( `Authorization: "Key ${placeholder}",`, - `Authorization: \`Key $\{process.env.${accessTokenEnvVar}}\`,` // e.g. Authorization: `Key ${process.env.FAL_AI_API_KEY}`, + `Authorization: \`Key $\{process.env.${accessTokenEnvVar}}\`,`, // e.g. Authorization: `Key ${process.env.FAL_AI_API_KEY}`, ); snippet = snippet.replace( `Authorization: "X-Key ${placeholder}",`, - `Authorization: \`X-Key $\{process.env.${accessTokenEnvVar}}\`,` // e.g. Authorization: `X-Key ${process.env.BLACK_FOREST_LABS_AI_API_KEY}`, + `Authorization: \`X-Key $\{process.env.${accessTokenEnvVar}}\`,`, // e.g. Authorization: `X-Key ${process.env.BLACK_FOREST_LABS_AI_API_KEY}`, ); } return snippet; diff --git a/packages/inference/src/tasks/audio/audioClassification.ts b/packages/inference/src/tasks/audio/audioClassification.ts index 89737e2597..bd500d62d4 100644 --- a/packages/inference/src/tasks/audio/audioClassification.ts +++ b/packages/inference/src/tasks/audio/audioClassification.ts @@ -14,7 +14,7 @@ export type AudioClassificationArgs = BaseArgs & (AudioClassificationInput | Leg */ export async function audioClassification( args: AudioClassificationArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "audio-classification"); diff --git a/packages/inference/src/tasks/audio/automaticSpeechRecognition.ts b/packages/inference/src/tasks/audio/automaticSpeechRecognition.ts index c5a716d5bc..565687eb52 100644 --- a/packages/inference/src/tasks/audio/automaticSpeechRecognition.ts +++ b/packages/inference/src/tasks/audio/automaticSpeechRecognition.ts @@ -12,7 +12,7 @@ export type AutomaticSpeechRecognitionArgs = BaseArgs & (AutomaticSpeechRecognit */ export async function automaticSpeechRecognition( args: AutomaticSpeechRecognitionArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "automatic-speech-recognition"); diff --git a/packages/inference/src/tasks/audio/utils.ts b/packages/inference/src/tasks/audio/utils.ts index a5be1afe79..151cc55a72 100644 --- a/packages/inference/src/tasks/audio/utils.ts +++ b/packages/inference/src/tasks/audio/utils.ts @@ -15,5 +15,5 @@ export function preparePayload(args: BaseArgs & ({ inputs: Blob } | LegacyAudioI : { ...omit(args, "inputs"), data: args.inputs, - }; + }; } diff --git a/packages/inference/src/tasks/custom/request.ts b/packages/inference/src/tasks/custom/request.ts index f2c78f2292..9d0ddc93d9 100644 --- a/packages/inference/src/tasks/custom/request.ts +++ b/packages/inference/src/tasks/custom/request.ts @@ -13,11 +13,11 @@ export async function request( options?: Options & { /** In most cases (unless we pass a endpointUrl) we know the task */ task?: InferenceTask; - } + }, ): Promise { const logger = getLogger(); logger.warn( - "The request method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead." + "The request method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead.", ); const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, options?.task); diff --git a/packages/inference/src/tasks/custom/streamingRequest.ts b/packages/inference/src/tasks/custom/streamingRequest.ts index 05e41402fe..39681b57a4 100644 --- a/packages/inference/src/tasks/custom/streamingRequest.ts +++ b/packages/inference/src/tasks/custom/streamingRequest.ts @@ -13,11 +13,11 @@ export async function* streamingRequest( options?: Options & { /** In most cases (unless we pass a endpointUrl) we know the task */ task?: InferenceTask; - } + }, ): AsyncGenerator { const logger = getLogger(); logger.warn( - "The streamingRequest method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead." + "The streamingRequest method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead.", ); const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, options?.task); diff --git a/packages/inference/src/tasks/cv/imageClassification.ts b/packages/inference/src/tasks/cv/imageClassification.ts index 2a39f57e26..7d93d1371b 100644 --- a/packages/inference/src/tasks/cv/imageClassification.ts +++ b/packages/inference/src/tasks/cv/imageClassification.ts @@ -13,7 +13,7 @@ export type ImageClassificationArgs = BaseArgs & (ImageClassificationInput | Leg */ export async function imageClassification( args: ImageClassificationArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "image-classification"); diff --git a/packages/inference/src/tasks/cv/imageSegmentation.ts b/packages/inference/src/tasks/cv/imageSegmentation.ts index 33bf5d434f..a22c4ee33e 100644 --- a/packages/inference/src/tasks/cv/imageSegmentation.ts +++ b/packages/inference/src/tasks/cv/imageSegmentation.ts @@ -13,7 +13,7 @@ export type ImageSegmentationArgs = BaseArgs & ImageSegmentationInput; */ export async function imageSegmentation( args: ImageSegmentationArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "image-segmentation"); diff --git a/packages/inference/src/tasks/cv/textToImage.ts b/packages/inference/src/tasks/cv/textToImage.ts index 20f70ea604..56f2019ff0 100644 --- a/packages/inference/src/tasks/cv/textToImage.ts +++ b/packages/inference/src/tasks/cv/textToImage.ts @@ -17,23 +17,23 @@ interface TextToImageOptions extends Options { */ export async function textToImage( args: TextToImageArgs, - options?: TextToImageOptions & { outputType: "url" } + options?: TextToImageOptions & { outputType: "url" }, ): Promise; export async function textToImage( args: TextToImageArgs, - options?: TextToImageOptions & { outputType: "dataUrl" } + options?: TextToImageOptions & { outputType: "dataUrl" }, ): Promise; export async function textToImage( args: TextToImageArgs, - options?: TextToImageOptions & { outputType?: undefined | "blob" } + options?: TextToImageOptions & { outputType?: undefined | "blob" }, ): Promise; export async function textToImage( args: TextToImageArgs, - options?: TextToImageOptions & { outputType?: undefined | "json" } + options?: TextToImageOptions & { outputType?: undefined | "json" }, ): Promise>; export async function textToImage( args: TextToImageArgs, - options?: TextToImageOptions + options?: TextToImageOptions, ): Promise> { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "text-to-image"); diff --git a/packages/inference/src/tasks/cv/textToVideo.ts b/packages/inference/src/tasks/cv/textToVideo.ts index 507eda8118..7461205ee5 100644 --- a/packages/inference/src/tasks/cv/textToVideo.ts +++ b/packages/inference/src/tasks/cv/textToVideo.ts @@ -21,7 +21,7 @@ export async function textToVideo(args: TextToVideoArgs, options?: Options): Pro { ...options, task: "text-to-video", - } + }, ); const { url, info } = await makeRequestOptions(args, providerHelper, { ...options, task: "text-to-video" }); return providerHelper.getResponse(response, url, info.headers as Record); diff --git a/packages/inference/src/tasks/cv/zeroShotImageClassification.ts b/packages/inference/src/tasks/cv/zeroShotImageClassification.ts index 5843affb97..763ceec243 100644 --- a/packages/inference/src/tasks/cv/zeroShotImageClassification.ts +++ b/packages/inference/src/tasks/cv/zeroShotImageClassification.ts @@ -29,8 +29,8 @@ async function preparePayload(args: ZeroShotImageClassificationArgs): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "zero-shot-image-classification"); diff --git a/packages/inference/src/tasks/multimodal/documentQuestionAnswering.ts b/packages/inference/src/tasks/multimodal/documentQuestionAnswering.ts index cccddb10db..4d5a7883ae 100644 --- a/packages/inference/src/tasks/multimodal/documentQuestionAnswering.ts +++ b/packages/inference/src/tasks/multimodal/documentQuestionAnswering.ts @@ -18,7 +18,7 @@ export type DocumentQuestionAnsweringArgs = BaseArgs & */ export async function documentQuestionAnswering( args: DocumentQuestionAnsweringArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "document-question-answering"); @@ -36,7 +36,7 @@ export async function documentQuestionAnswering( { ...options, task: "document-question-answering", - } + }, ); return providerHelper.getResponse(res); } diff --git a/packages/inference/src/tasks/multimodal/visualQuestionAnswering.ts b/packages/inference/src/tasks/multimodal/visualQuestionAnswering.ts index 00a96f573d..07125d046c 100644 --- a/packages/inference/src/tasks/multimodal/visualQuestionAnswering.ts +++ b/packages/inference/src/tasks/multimodal/visualQuestionAnswering.ts @@ -18,7 +18,7 @@ export type VisualQuestionAnsweringArgs = BaseArgs & */ export async function visualQuestionAnswering( args: VisualQuestionAnsweringArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "visual-question-answering"); diff --git a/packages/inference/src/tasks/nlp/chatCompletion.ts b/packages/inference/src/tasks/nlp/chatCompletion.ts index ca3cefb0cf..252bf3ba90 100644 --- a/packages/inference/src/tasks/nlp/chatCompletion.ts +++ b/packages/inference/src/tasks/nlp/chatCompletion.ts @@ -11,7 +11,7 @@ import { AutoRouterConversationalTask } from "../../providers/providerHelper.js" */ export async function chatCompletion( args: BaseArgs & ChatCompletionInput, - options?: Options + options?: Options, ): Promise { let providerHelper: ConversationalTaskHelper & TaskProviderHelper; if (!args.provider || args.provider === "auto") { diff --git a/packages/inference/src/tasks/nlp/chatCompletionStream.ts b/packages/inference/src/tasks/nlp/chatCompletionStream.ts index b4196d7a30..66229ca4a1 100644 --- a/packages/inference/src/tasks/nlp/chatCompletionStream.ts +++ b/packages/inference/src/tasks/nlp/chatCompletionStream.ts @@ -11,7 +11,7 @@ import { AutoRouterConversationalTask } from "../../providers/providerHelper.js" */ export async function* chatCompletionStream( args: BaseArgs & ChatCompletionInput, - options?: Options + options?: Options, ): AsyncGenerator { let providerHelper: ConversationalTaskHelper & TaskProviderHelper; if (!args.provider || args.provider === "auto") { diff --git a/packages/inference/src/tasks/nlp/featureExtraction.ts b/packages/inference/src/tasks/nlp/featureExtraction.ts index f1e2402237..0aea582b3a 100644 --- a/packages/inference/src/tasks/nlp/featureExtraction.ts +++ b/packages/inference/src/tasks/nlp/featureExtraction.ts @@ -21,7 +21,7 @@ export type FeatureExtractionOutput = (number | number[] | number[][])[]; */ export async function featureExtraction( args: FeatureExtractionArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "feature-extraction"); diff --git a/packages/inference/src/tasks/nlp/questionAnswering.ts b/packages/inference/src/tasks/nlp/questionAnswering.ts index 22a1b2be15..8bfdcfaa08 100644 --- a/packages/inference/src/tasks/nlp/questionAnswering.ts +++ b/packages/inference/src/tasks/nlp/questionAnswering.ts @@ -12,7 +12,7 @@ export type QuestionAnsweringArgs = BaseArgs & QuestionAnsweringInput; */ export async function questionAnswering( args: QuestionAnsweringArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "question-answering"); @@ -22,7 +22,7 @@ export async function questionAnswering( { ...options, task: "question-answering", - } + }, ); return providerHelper.getResponse(res); } diff --git a/packages/inference/src/tasks/nlp/sentenceSimilarity.ts b/packages/inference/src/tasks/nlp/sentenceSimilarity.ts index 238c8c13de..0f79ab76d6 100644 --- a/packages/inference/src/tasks/nlp/sentenceSimilarity.ts +++ b/packages/inference/src/tasks/nlp/sentenceSimilarity.ts @@ -11,7 +11,7 @@ export type SentenceSimilarityArgs = BaseArgs & SentenceSimilarityInput; */ export async function sentenceSimilarity( args: SentenceSimilarityArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "sentence-similarity"); diff --git a/packages/inference/src/tasks/nlp/tableQuestionAnswering.ts b/packages/inference/src/tasks/nlp/tableQuestionAnswering.ts index 3614910350..43beb4de90 100644 --- a/packages/inference/src/tasks/nlp/tableQuestionAnswering.ts +++ b/packages/inference/src/tasks/nlp/tableQuestionAnswering.ts @@ -11,7 +11,7 @@ export type TableQuestionAnsweringArgs = BaseArgs & TableQuestionAnsweringInput; */ export async function tableQuestionAnswering( args: TableQuestionAnsweringArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "table-question-answering"); @@ -21,7 +21,7 @@ export async function tableQuestionAnswering( { ...options, task: "table-question-answering", - } + }, ); return providerHelper.getResponse(res); } diff --git a/packages/inference/src/tasks/nlp/textClassification.ts b/packages/inference/src/tasks/nlp/textClassification.ts index cf977a86bc..76c949f381 100644 --- a/packages/inference/src/tasks/nlp/textClassification.ts +++ b/packages/inference/src/tasks/nlp/textClassification.ts @@ -11,7 +11,7 @@ export type TextClassificationArgs = BaseArgs & TextClassificationInput; */ export async function textClassification( args: TextClassificationArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "text-classification"); diff --git a/packages/inference/src/tasks/nlp/textGeneration.ts b/packages/inference/src/tasks/nlp/textGeneration.ts index 344082e674..01eb1ddfc0 100644 --- a/packages/inference/src/tasks/nlp/textGeneration.ts +++ b/packages/inference/src/tasks/nlp/textGeneration.ts @@ -12,7 +12,7 @@ export type { TextGenerationInput, TextGenerationOutput }; */ export async function textGeneration( args: BaseArgs & TextGenerationInput, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "text-generation"); diff --git a/packages/inference/src/tasks/nlp/textGenerationStream.ts b/packages/inference/src/tasks/nlp/textGenerationStream.ts index 9aaf34f511..ae138c685f 100644 --- a/packages/inference/src/tasks/nlp/textGenerationStream.ts +++ b/packages/inference/src/tasks/nlp/textGenerationStream.ts @@ -89,7 +89,7 @@ export interface TextGenerationStreamOutput { */ export async function* textGenerationStream( args: BaseArgs & TextGenerationInput, - options?: Options + options?: Options, ): AsyncGenerator { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "text-generation"); diff --git a/packages/inference/src/tasks/nlp/tokenClassification.ts b/packages/inference/src/tasks/nlp/tokenClassification.ts index fc9868c3b8..6d56efa619 100644 --- a/packages/inference/src/tasks/nlp/tokenClassification.ts +++ b/packages/inference/src/tasks/nlp/tokenClassification.ts @@ -11,7 +11,7 @@ export type TokenClassificationArgs = BaseArgs & TokenClassificationInput; */ export async function tokenClassification( args: TokenClassificationArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "token-classification"); @@ -21,7 +21,7 @@ export async function tokenClassification( { ...options, task: "token-classification", - } + }, ); return providerHelper.getResponse(res); } diff --git a/packages/inference/src/tasks/nlp/zeroShotClassification.ts b/packages/inference/src/tasks/nlp/zeroShotClassification.ts index ba5f1fda36..73deb9671a 100644 --- a/packages/inference/src/tasks/nlp/zeroShotClassification.ts +++ b/packages/inference/src/tasks/nlp/zeroShotClassification.ts @@ -11,7 +11,7 @@ export type ZeroShotClassificationArgs = BaseArgs & ZeroShotClassificationInput; */ export async function zeroShotClassification( args: ZeroShotClassificationArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "zero-shot-classification"); @@ -21,7 +21,7 @@ export async function zeroShotClassification( { ...options, task: "zero-shot-classification", - } + }, ); return providerHelper.getResponse(res); } diff --git a/packages/inference/src/tasks/tabular/tabularClassification.ts b/packages/inference/src/tasks/tabular/tabularClassification.ts index 44e7a25013..26bee76e47 100644 --- a/packages/inference/src/tasks/tabular/tabularClassification.ts +++ b/packages/inference/src/tasks/tabular/tabularClassification.ts @@ -24,7 +24,7 @@ export type TabularClassificationOutput = number[]; */ export async function tabularClassification( args: TabularClassificationArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "tabular-classification"); diff --git a/packages/inference/src/tasks/tabular/tabularRegression.ts b/packages/inference/src/tasks/tabular/tabularRegression.ts index 6c3d27af24..c08b439fd7 100644 --- a/packages/inference/src/tasks/tabular/tabularRegression.ts +++ b/packages/inference/src/tasks/tabular/tabularRegression.ts @@ -24,7 +24,7 @@ export type TabularRegressionOutput = number[]; */ export async function tabularRegression( args: TabularRegressionArgs, - options?: Options + options?: Options, ): Promise { const provider = await resolveProvider(args.provider, args.model, args.endpointUrl); const providerHelper = getProviderHelper(provider, "tabular-regression"); diff --git a/packages/inference/src/utils/pick.ts b/packages/inference/src/utils/pick.ts index 7bb040cbba..cec9abad79 100644 --- a/packages/inference/src/utils/pick.ts +++ b/packages/inference/src/utils/pick.ts @@ -8,6 +8,6 @@ export function pick(o: T, props: K[] | ReadonlyArray): if (o[prop] !== undefined) { return { [prop]: o[prop] }; } - }) + }), ); } diff --git a/packages/inference/src/utils/request.ts b/packages/inference/src/utils/request.ts index b84d6762c9..c26cce4910 100644 --- a/packages/inference/src/utils/request.ts +++ b/packages/inference/src/utils/request.ts @@ -42,7 +42,7 @@ export async function innerRequest( task?: InferenceTask; /** Is chat completion compatible */ chatCompletion?: boolean; - } + }, ): Promise> { const { url, info } = await makeRequestOptions(args, providerHelper, options); const response = await (options?.fetch ?? fetch)(url, info); @@ -68,7 +68,7 @@ export async function innerRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }, ); } if (typeof output.error === "string" || typeof output.detail === "string" || typeof output.message === "string") { @@ -80,7 +80,7 @@ export async function innerRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }, ); } else { throw new InferenceClientProviderApiError( @@ -91,7 +91,7 @@ export async function innerRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }, ); } } @@ -104,7 +104,7 @@ export async function innerRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: message ?? "" } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: message ?? "" }, ); } @@ -128,7 +128,7 @@ export async function* innerStreamingRequest( task?: InferenceTask; /** Is chat completion compatible */ chatCompletion?: boolean; - } + }, ): AsyncGenerator { const { url, info } = await makeRequestOptions({ ...args, stream: true }, providerHelper, options); const response = await (options?.fetch ?? fetch)(url, info); @@ -150,7 +150,7 @@ export async function* innerStreamingRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }, ); } if (typeof output.error === "string") { @@ -162,7 +162,7 @@ export async function* innerStreamingRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }, ); } if (output.error && "message" in output.error && typeof output.error.message === "string") { @@ -175,7 +175,7 @@ export async function* innerStreamingRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }, ); } // Sambanova errors @@ -188,7 +188,7 @@ export async function* innerStreamingRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }, ); } } @@ -201,7 +201,7 @@ export async function* innerStreamingRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" }, ); } if (!response.headers.get("content-type")?.startsWith("text/event-stream")) { @@ -214,7 +214,7 @@ export async function* innerStreamingRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" }, ); } @@ -234,8 +234,8 @@ export async function* innerStreamingRequest( getMessages( () => {}, () => {}, - onEvent - ) + onEvent, + ), ); try { @@ -256,11 +256,11 @@ export async function* innerStreamingRequest( typeof data.error === "string" ? data.error : typeof data.error === "object" && - data.error && - "message" in data.error && - typeof data.error.message === "string" - ? data.error.message - : JSON.stringify(data.error); + data.error && + "message" in data.error && + typeof data.error.message === "string" + ? data.error.message + : JSON.stringify(data.error); throw new InferenceClientProviderApiError( `Failed to perform inference: an occurred while streaming the response: ${errorStr}`, { @@ -269,7 +269,7 @@ export async function* innerStreamingRequest( headers: info.headers as Record, body: bodyToJson(info.body), }, - { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: data } + { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: data }, ); } yield data as T; diff --git a/packages/inference/src/utils/typedEntries.ts b/packages/inference/src/utils/typedEntries.ts index d801950826..01660c6799 100644 --- a/packages/inference/src/utils/typedEntries.ts +++ b/packages/inference/src/utils/typedEntries.ts @@ -1,5 +1,5 @@ export function typedEntries>( - obj: T + obj: T, ): [keyof T, T[keyof T]][] { return Object.entries(obj) as [keyof T, T[keyof T]][]; } diff --git a/packages/inference/test/InferenceClient.spec.ts b/packages/inference/test/InferenceClient.spec.ts index ac68a90f72..50e3ba49fa 100644 --- a/packages/inference/test/InferenceClient.spec.ts +++ b/packages/inference/test/InferenceClient.spec.ts @@ -247,7 +247,7 @@ describe.skip("InferenceClient", () => { hf.fillMask({ model: "this-model/does-not-exist-123", inputs: "[MASK] world!", - }) + }), ).rejects.toThrowError("Model this-model/does-not-exist-123 does not exist"); }); @@ -256,7 +256,7 @@ describe.skip("InferenceClient", () => { await hf.fillMask({ model: "google-bert/bert-base-uncased", inputs: "[MASK] world!", - }) + }), ).toEqual( expect.arrayContaining([ expect.objectContaining({ @@ -265,7 +265,7 @@ describe.skip("InferenceClient", () => { token_str: expect.any(String), sequence: expect.any(String), }), - ]) + ]), ); }); @@ -273,7 +273,7 @@ describe.skip("InferenceClient", () => { expect( await hf.fillMask({ inputs: "[MASK] world!", - }) + }), ).toEqual( expect.arrayContaining([ expect.objectContaining({ @@ -282,7 +282,7 @@ describe.skip("InferenceClient", () => { token_str: expect.any(String), sequence: expect.any(String), }), - ]) + ]), ); }); @@ -295,7 +295,7 @@ describe.skip("InferenceClient", () => { parameters: { max_length: 100, }, - }) + }), ).toEqual({ summary_text: "The Eiffel Tower is one of the most famous buildings in the world.", }); @@ -309,7 +309,7 @@ describe.skip("InferenceClient", () => { question: "What is the capital of France?", context: "The capital of France is Paris.", }, - }) + }), ).toMatchObject({ answer: "Paris", score: expect.any(Number), @@ -331,7 +331,7 @@ describe.skip("InferenceClient", () => { "Programming language": ["Python", "Python", "Rust, Python and NodeJS"], }, }, - }) + }), ).toMatchObject({ answer: "AVERAGE > 36542", coordinates: [[0, 1]], @@ -348,7 +348,7 @@ describe.skip("InferenceClient", () => { question: "Invoice number?", image: new Blob([readTestFile("invoice.png")], { type: "image/png" }), }, - }) + }), ).toMatchObject({ answer: "us-001", score: expect.any(Number), @@ -367,7 +367,7 @@ describe.skip("InferenceClient", () => { question: "Invoice number?", image: new Blob([readTestFile("invoice.png")], { type: "image/png" }), }, - }) + }), ).toMatchObject({ answer: "us-001", }); @@ -381,7 +381,7 @@ describe.skip("InferenceClient", () => { question: "How many cats are lying down?", image: new Blob([readTestFile("cats.png")], { type: "image/png" }), }, - }) + }), ).toMatchObject({ answer: "2", score: expect.any(Number), @@ -393,14 +393,14 @@ describe.skip("InferenceClient", () => { await hf.textClassification({ model: "distilbert-base-uncased-finetuned-sst-2-english", inputs: "I like you. I love you.", - }) + }), ).toEqual( expect.arrayContaining([ expect.objectContaining({ label: expect.any(String), score: expect.any(Number), }), - ]) + ]), ); }); @@ -409,7 +409,7 @@ describe.skip("InferenceClient", () => { await hf.textGeneration({ model: "gpt2", inputs: "The answer to the universe is", - }) + }), ).toMatchObject({ generated_text: expect.any(String), }); @@ -420,7 +420,7 @@ describe.skip("InferenceClient", () => { await hf.textGeneration({ model: "openai-community/gpt2", inputs: "The answer to the universe is", - }) + }), ).toMatchObject({ generated_text: expect.any(String), }); @@ -463,7 +463,7 @@ describe.skip("InferenceClient", () => { }); await expect(response.next()).rejects.toThrow( - "Error forwarded from backend: Input validation error: `inputs` tokens + `max_new_tokens` must be <= 4096. Given: 17 `inputs` tokens and 10000 `max_new_tokens`" + "Error forwarded from backend: Input validation error: `inputs` tokens + `max_new_tokens` must be <= 4096. Given: 17 `inputs` tokens and 10000 `max_new_tokens`", ); }); @@ -477,7 +477,7 @@ describe.skip("InferenceClient", () => { max_new_tokens: 100, }, }, - { signal: controller.signal } + { signal: controller.signal }, ); await expect(response.next()).resolves.toBeDefined(); await expect(response.next()).resolves.toBeDefined(); @@ -490,7 +490,7 @@ describe.skip("InferenceClient", () => { await hf.tokenClassification({ model: "dbmdz/bert-large-cased-finetuned-conll03-english", inputs: "My name is Sarah Jessica Parker but you can call me Jessica", - }) + }), ).toEqual( expect.arrayContaining([ expect.objectContaining({ @@ -500,7 +500,7 @@ describe.skip("InferenceClient", () => { start: expect.any(Number), end: expect.any(Number), }), - ]) + ]), ); }); @@ -509,7 +509,7 @@ describe.skip("InferenceClient", () => { await hf.translation({ model: "t5-base", inputs: "My name is Wolfgang and I live in Berlin", - }) + }), ).toMatchObject({ translation_text: "Mein Name ist Wolfgang und ich lebe in Berlin", }); @@ -519,7 +519,7 @@ describe.skip("InferenceClient", () => { model: "t5-base", // eslint-disable-next-line @typescript-eslint/no-explicit-any inputs: ["My name is Wolfgang and I live in Berlin", "I work as programmer"] as any, - }) + }), ).toMatchObject([ { translation_text: "Mein Name ist Wolfgang und ich lebe in Berlin", @@ -538,7 +538,7 @@ describe.skip("InferenceClient", () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any ] as any, parameters: { candidate_labels: ["refund", "legal", "faq"] }, - }) + }), ).toEqual( expect.arrayContaining([ expect.objectContaining({ @@ -551,7 +551,7 @@ describe.skip("InferenceClient", () => { expect.closeTo(0.01698593981564045, 5), ], }), - ]) + ]), ); }); it("sentenceSimilarity", async () => { @@ -562,7 +562,7 @@ describe.skip("InferenceClient", () => { source_sentence: "That is a happy person", sentences: ["That is a happy dog", "That is a very happy person", "Today is a sunny day"], }, - }) + }), ).toEqual([expect.any(Number), expect.any(Number), expect.any(Number)]); }); it("FeatureExtraction", async () => { @@ -631,7 +631,7 @@ describe.skip("InferenceClient", () => { await hf.automaticSpeechRecognition({ model: "facebook/wav2vec2-large-960h-lv60-self", data: new Blob([readTestFile("sample1.flac")], { type: "audio/flac" }), - }) + }), ).toMatchObject({ text: "GOING ALONG SLUSHY COUNTRY ROADS AND SPEAKING TO DAMP AUDIENCES IN DRAUGHTY SCHOOLROOMS DAY AFTER DAY FOR A FORTNIGHT HE'LL HAVE TO PUT IN AN APPEARANCE AT SOME PLACE OF WORSHIP ON SUNDAY MORNING AND HE CAN COME TO US IMMEDIATELY AFTERWARDS", }); @@ -641,14 +641,14 @@ describe.skip("InferenceClient", () => { await hf.audioClassification({ model: "superb/hubert-large-superb-er", data: new Blob([readTestFile("sample1.flac")], { type: "audio/flac" }), - }) + }), ).toEqual( expect.arrayContaining([ expect.objectContaining({ score: expect.any(Number), label: expect.any(String), }), - ]) + ]), ); }); @@ -657,7 +657,7 @@ describe.skip("InferenceClient", () => { await hf.audioToAudio({ model: "speechbrain/sepformer-wham", data: new Blob([readTestFile("sample1.flac")], { type: "audio/flac" }), - }) + }), ).toEqual( expect.arrayContaining([ expect.objectContaining({ @@ -665,7 +665,7 @@ describe.skip("InferenceClient", () => { blob: expect.any(String), "content-type": expect.any(String), }), - ]) + ]), ); }); @@ -674,7 +674,7 @@ describe.skip("InferenceClient", () => { await hf.textToSpeech({ model: "espnet/kan-bayashi_ljspeech_vits", inputs: "hello there!", - }) + }), ).toBeInstanceOf(Blob); }); @@ -683,14 +683,14 @@ describe.skip("InferenceClient", () => { await hf.imageClassification({ data: new Blob([readTestFile("cheetah.png")], { type: "image/png" }), model: "google/vit-base-patch16-224", - }) + }), ).toEqual( expect.arrayContaining([ expect.objectContaining({ score: expect.any(Number), label: expect.any(String), }), - ]) + ]), ); }); @@ -702,7 +702,7 @@ describe.skip("InferenceClient", () => { parameters: { candidate_labels: ["animal", "toy", "car"], }, - }) + }), ).toEqual([ { label: "animal", @@ -724,7 +724,7 @@ describe.skip("InferenceClient", () => { await hf.objectDetection({ data: new Blob([readTestFile("cats.png")], { type: "image/png" }), model: "facebook/detr-resnet-50", - }) + }), ).toEqual( expect.arrayContaining([ expect.objectContaining({ @@ -737,7 +737,7 @@ describe.skip("InferenceClient", () => { ymax: expect.any(Number), }), }), - ]) + ]), ); }); it("imageSegmentation", async () => { @@ -745,7 +745,7 @@ describe.skip("InferenceClient", () => { await hf.imageSegmentation({ inputs: new Blob([readTestFile("cats.png")], { type: "image/png" }), model: "facebook/detr-resnet-50-panoptic", - }) + }), ).toEqual( expect.arrayContaining([ expect.objectContaining({ @@ -753,7 +753,7 @@ describe.skip("InferenceClient", () => { label: expect.any(String), mask: expect.any(String), }), - ]) + ]), ); }); it("imageToImage", async () => { @@ -818,7 +818,7 @@ describe.skip("InferenceClient", () => { await hf.imageToText({ data: new Blob([readTestFile("cheetah.png")], { type: "image/png" }), model: "nlpconnect/vit-gpt2-image-captioning", - }) + }), ).toEqual({ generated_text: "a large brown and white giraffe standing in a field ", }); @@ -830,7 +830,7 @@ describe.skip("InferenceClient", () => { await hf.request({ model: "openai-community/gpt2", inputs: "one plus two equals", - }) + }), ).toMatchObject([ { generated_text: expect.any(String), @@ -853,7 +853,7 @@ describe.skip("InferenceClient", () => { Width: ["4.02", "4.3056", "4.6961"], }, }, - }) + }), ).toMatchObject([270.5473526976245, 313.6843425638086, 328.3727133404402]); }); @@ -877,7 +877,7 @@ describe.skip("InferenceClient", () => { alcohol: ["9.4", "9.8", "12.6"], }, }, - }) + }), ).toMatchObject([5, 5, 7]); }); @@ -946,9 +946,9 @@ describe.skip("InferenceClient", () => { temperature: 0.1, seed: 0, }) - .next() + .next(), ).rejects.toThrowError( - "Server google/gemma-2b does not seem to support chat completion. Error: Template error: template not found" + "Server google/gemma-2b does not seem to support chat completion. Error: Template error: template not found", ); }); @@ -1021,11 +1021,11 @@ describe.skip("InferenceClient", () => { model: "gpt-3.5-turbo", // must be "openai/gpt-3.5-turbo" provider: "openai", messages: [{ role: "user", content: "Complete this sentence with words, one plus one is equal " }], - }) + }), ).rejects.toThrowError(`Models from openai must be prefixed by "openai/". Got "gpt-3.5-turbo".`); }); }, - TIMEOUT + TIMEOUT, ); /** @@ -1112,7 +1112,7 @@ describe.skip("InferenceClient", () => { expect(res).toBeInstanceOf(Blob); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -1187,7 +1187,7 @@ describe.skip("InferenceClient", () => { expect(res).toMatchObject({ generated_text: "2.2 million people, and it is the" }); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -1311,7 +1311,7 @@ describe.skip("InferenceClient", () => { expect(res).toBeInstanceOf(Blob); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( "SambaNova", @@ -1353,7 +1353,7 @@ describe.skip("InferenceClient", () => { expect(res[0]).toBeInstanceOf(Array); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -1408,7 +1408,7 @@ describe.skip("InferenceClient", () => { expect(res).toMatchObject({ generated_text: " a city of love, and it’s also" }); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -1513,7 +1513,7 @@ describe.skip("InferenceClient", () => { }); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -1623,7 +1623,7 @@ describe.skip("InferenceClient", () => { expect(res[0]).toEqual(expect.arrayContaining([expect.any(Number)])); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent("3rd party providers", () => { @@ -1634,9 +1634,9 @@ describe.skip("InferenceClient", () => { provider: "together", messages: [{ role: "user", content: "Complete this sentence with words, one plus one is equal " }], accessToken: env.HF_TOGETHER_KEY ?? "dummy", - }) + }), ).rejects.toThrowError( - "Model black-forest-labs/Flux.1-dev is not supported for task conversational and provider together" + "Model black-forest-labs/Flux.1-dev is not supported for task conversational and provider together", ); }); }); @@ -1691,7 +1691,7 @@ describe.skip("InferenceClient", () => { expect(fullResponse.length).toBeGreaterThan(0); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -1794,7 +1794,7 @@ describe.skip("InferenceClient", () => { expect(res).toMatchObject({ generated_text: "...the capital and most populous city of France," }); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -1854,7 +1854,7 @@ describe.skip("InferenceClient", () => { expect(fullResponse.length).toBeGreaterThan(0); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( "Black Forest Labs", @@ -1900,13 +1900,13 @@ describe.skip("InferenceClient", () => { seed: 8817, }, }, - { outputType: "url" } + { outputType: "url" }, ); expect(res).toBeTypeOf("string"); expect(isUrl(res)).toBeTruthy(); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( "Cohere", @@ -1965,7 +1965,7 @@ describe.skip("InferenceClient", () => { expect(fullResponse.length).toBeGreaterThan(0); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( "Cerebras", @@ -2017,7 +2017,7 @@ describe.skip("InferenceClient", () => { expect(fullResponse.length).toBeGreaterThan(0); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( "Nscale", @@ -2080,7 +2080,7 @@ describe.skip("InferenceClient", () => { expect(res).toBeInstanceOf(Blob); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( "Groq", @@ -2132,7 +2132,7 @@ describe.skip("InferenceClient", () => { expect(fullResponse.length).toBeGreaterThan(0); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( "ZAI", @@ -2201,7 +2201,7 @@ describe.skip("InferenceClient", () => { expect(res).toBeInstanceOf(Blob); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( "OVHcloud", @@ -2305,7 +2305,7 @@ describe.skip("InferenceClient", () => { expect(fullResponse).toContain("D"); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -2481,7 +2481,7 @@ describe.skip("InferenceClient", () => { expect(res).toBeInstanceOf(Blob); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -2534,7 +2534,7 @@ describe.skip("InferenceClient", () => { expect(fullResponse.length).toBeGreaterThan(0); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -2592,7 +2592,7 @@ describe.skip("InferenceClient", () => { expect(fullResponse).toMatch(/1.*2.*3/); }); }, - TIMEOUT + TIMEOUT, ); describe.concurrent( @@ -2650,6 +2650,6 @@ describe.skip("InferenceClient", () => { expect(fullResponse).toMatch(/1.*2.*3/); }); }, - TIMEOUT + TIMEOUT, ); }); diff --git a/packages/jinja/package.json b/packages/jinja/package.json index b291e3453d..08b74acb54 100644 --- a/packages/jinja/package.json +++ b/packages/jinja/package.json @@ -1,12 +1,24 @@ { "name": "@huggingface/jinja", - "packageManager": "pnpm@10.10.0", "version": "0.5.3", "description": "A minimalistic JavaScript implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.", + "keywords": [ + "face", + "hugging", + "huggingface", + "jinja", + "templates" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" - }, + "source": "src/index.ts", + "files": [ + "dist", + "README.md", + "src", + "tsconfig.json" + ], "type": "module", "main": "./dist/index.cjs", "module": "./dist/index.js", @@ -18,10 +30,9 @@ "import": "./dist/index.js" } }, - "engines": { - "node": ">=18" + "publishConfig": { + "access": "public" }, - "source": "src/index.ts", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -34,24 +45,13 @@ "test:browser": "vitest run --browser.name=chrome --browser.headless", "check": "tsc" }, - "files": [ - "src", - "dist", - "README.md", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "jinja", - "templates", - "hugging", - "face" - ], - "author": "Hugging Face", - "license": "MIT", "devDependencies": { - "typescript": "^5.3.2", "@huggingface/hub": "workspace:^", - "@huggingface/transformers": "^3.0.0" - } + "@huggingface/transformers": "^3.0.0", + "typescript": "^5.3.2" + }, + "engines": { + "node": ">=18" + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/jinja/src/ast.ts b/packages/jinja/src/ast.ts index c0515d2be8..8868852a3c 100644 --- a/packages/jinja/src/ast.ts +++ b/packages/jinja/src/ast.ts @@ -24,7 +24,7 @@ export class If extends Statement { constructor( public test: Expression, public body: Statement[], - public alternate: Statement[] + public alternate: Statement[], ) { super(); } @@ -41,7 +41,7 @@ export class For extends Statement { public loopvar: Identifier | TupleLiteral, public iterable: Expression, public body: Statement[], - public defaultBlock: Statement[] // if no iteration took place + public defaultBlock: Statement[], // if no iteration took place ) { super(); } @@ -59,7 +59,7 @@ export class SetStatement extends Statement { constructor( public assignee: Expression, public value: Expression | null, - public body: Statement[] + public body: Statement[], ) { super(); } @@ -71,7 +71,7 @@ export class Macro extends Statement { constructor( public name: Identifier, public args: Expression[], - public body: Statement[] + public body: Statement[], ) { super(); } @@ -97,7 +97,7 @@ export class MemberExpression extends Expression { constructor( public object: Expression, public property: Expression, - public computed: boolean + public computed: boolean, ) { super(); } @@ -108,7 +108,7 @@ export class CallExpression extends Expression { constructor( public callee: Expression, - public args: Expression[] + public args: Expression[], ) { super(); } @@ -187,7 +187,7 @@ export class BinaryExpression extends Expression { constructor( public operator: Token, public left: Expression, - public right: Expression + public right: Expression, ) { super(); } @@ -202,7 +202,7 @@ export class FilterExpression extends Expression { constructor( public operand: Expression, - public filter: Identifier | CallExpression + public filter: Identifier | CallExpression, ) { super(); } @@ -213,7 +213,7 @@ export class FilterStatement extends Statement { constructor( public filter: Identifier | CallExpression, - public body: Statement[] + public body: Statement[], ) { super(); } @@ -230,7 +230,7 @@ export class SelectExpression extends Expression { constructor( public lhs: Expression, - public test: Expression + public test: Expression, ) { super(); } @@ -245,7 +245,7 @@ export class TestExpression extends Expression { constructor( public operand: Expression, public negate: boolean, - public test: Identifier // TODO: Add support for non-identifier tests + public test: Identifier, // TODO: Add support for non-identifier tests ) { super(); } @@ -259,7 +259,7 @@ export class UnaryExpression extends Expression { constructor( public operator: Token, - public argument: Expression + public argument: Expression, ) { super(); } @@ -271,7 +271,7 @@ export class SliceExpression extends Expression { constructor( public start: Expression | undefined = undefined, public stop: Expression | undefined = undefined, - public step: Expression | undefined = undefined + public step: Expression | undefined = undefined, ) { super(); } @@ -282,7 +282,7 @@ export class KeywordArgumentExpression extends Expression { constructor( public key: Identifier, - public value: Expression + public value: Expression, ) { super(); } @@ -302,7 +302,7 @@ export class CallStatement extends Statement { constructor( public call: CallExpression, public callerArgs: Expression[] | null, - public body: Statement[] + public body: Statement[], ) { super(); } @@ -313,7 +313,7 @@ export class Ternary extends Expression { constructor( public condition: Expression, public trueExpr: Expression, - public falseExpr: Expression + public falseExpr: Expression, ) { super(); } diff --git a/packages/jinja/src/format.ts b/packages/jinja/src/format.ts index 0280d09af6..b10a646565 100644 --- a/packages/jinja/src/format.ts +++ b/packages/jinja/src/format.ts @@ -290,7 +290,7 @@ function formatExpression(node: Expression, parentPrec: number = -1): string { } case "ObjectLiteral": { const entries = Array.from((node as ObjectLiteral).value.entries()).map( - ([k, v]) => `${formatExpression(k)}: ${formatExpression(v)}` + ([k, v]) => `${formatExpression(k)}: ${formatExpression(v)}`, ); return `{${entries.join(", ")}}`; } @@ -308,7 +308,7 @@ function formatExpression(node: Expression, parentPrec: number = -1): string { case "Ternary": { const n = node as Ternary; const expr = `${formatExpression(n.trueExpr)} if ${formatExpression(n.condition, 0)} else ${formatExpression( - n.falseExpr + n.falseExpr, )}`; return parentPrec > -1 ? `(${expr})` : expr; } diff --git a/packages/jinja/src/lexer.ts b/packages/jinja/src/lexer.ts index 201cc219ef..a0f2b7320b 100644 --- a/packages/jinja/src/lexer.ts +++ b/packages/jinja/src/lexer.ts @@ -44,7 +44,7 @@ export class Token { */ constructor( public value: string, - public type: TokenType + public type: TokenType, ) {} } @@ -330,7 +330,7 @@ export function tokenize(source: string, options: PreprocessOptions = {}): Token // Check for numbers following the unary operator const num = consumeWhile(isInteger); tokens.push( - new Token(`${char}${num}`, num.length > 0 ? TOKEN_TYPES.NumericLiteral : TOKEN_TYPES.UnaryOperator) + new Token(`${char}${num}`, num.length > 0 ? TOKEN_TYPES.NumericLiteral : TOKEN_TYPES.UnaryOperator), ); continue; } diff --git a/packages/jinja/src/runtime.ts b/packages/jinja/src/runtime.ts index e161110933..d692a8689e 100644 --- a/packages/jinja/src/runtime.ts +++ b/packages/jinja/src/runtime.ts @@ -283,7 +283,7 @@ function toJSON( input: AnyRuntimeValue, indent?: number | null, depth?: number, - convertUndefinedToNull: boolean = true + convertUndefinedToNull: boolean = true, ): string { const currentDepth = depth ?? 0; switch (input.type) { @@ -304,7 +304,7 @@ function toJSON( if (input.type === "ArrayValue") { const core = (input as ArrayValue).value.map((x) => - toJSON(x, indent, currentDepth + 1, convertUndefinedToNull) + toJSON(x, indent, currentDepth + 1, convertUndefinedToNull), ); return indent ? `[${childrenPadding}${core.join(`,${childrenPadding}`)}${basePadding}]` @@ -412,7 +412,7 @@ export class ObjectValue extends RuntimeValue> { items(): ArrayValue { return new ArrayValue( - Array.from(this.value.entries()).map(([key, value]) => new ArrayValue([new StringValue(key), value])) + Array.from(this.value.entries()).map(([key, value]) => new ArrayValue([new StringValue(key), value])), ); } keys(): ArrayValue { @@ -863,7 +863,7 @@ export class Interpreter { private evaluateArguments( args: Expression[], - environment: Environment + environment: Environment, ): [AnyRuntimeValue[], Map] { // Accumulate args and kwargs const positionalArguments: AnyRuntimeValue[] = []; @@ -972,9 +972,9 @@ export class Interpreter { .split("\n") .map((x, i) => // By default, don't indent the first line or empty lines - i === 0 || x.length === 0 ? x : " " + x + i === 0 || x.length === 0 ? x : " " + x, ) - .join("\n") + .join("\n"), ); case "join": case "string": @@ -1007,7 +1007,7 @@ export class Interpreter { switch (filter.value) { case "items": return new ArrayValue( - Array.from(operand.value.entries()).map(([key, value]) => new ArrayValue([new StringValue(key), value])) + Array.from(operand.value.entries()).map(([key, value]) => new ArrayValue([new StringValue(key), value])), ); case "length": return new IntegerValue(operand.value.size); @@ -1143,7 +1143,7 @@ export class Interpreter { const bVal = getSortValue(b); const result = compareRuntimeValues(aVal, bVal, caseSensitive.value); return reverse.value ? -result : result; - }) + }), ); } case "selectattr": @@ -1198,7 +1198,7 @@ export class Interpreter { } const value = getAttributeValue(item, attr.value); - return value instanceof UndefinedValue ? defaultValue ?? new UndefinedValue() : value; + return value instanceof UndefinedValue ? (defaultValue ?? new UndefinedValue()) : value; }); return new ArrayValue(mapped); } else { @@ -1229,7 +1229,7 @@ export class Interpreter { const lines = operand.value.split("\n"); const indent = " ".repeat(width.value); const indented = lines.map((x, i) => - (!first.value && i === 0) || (!blank.value && x.length === 0) ? x : indent + x + (!first.value && i === 0) || (!blank.value && x.length === 0) ? x : indent + x, ); return new StringValue(indented.join("\n")); } @@ -1363,7 +1363,7 @@ export class Interpreter { private evaluateSliceExpression( object: AnyRuntimeValue, expr: SliceExpression, - environment: Environment + environment: Environment, ): ArrayValue | StringValue { if (!(object instanceof ArrayValue || object instanceof StringValue)) { throw new Error("Slice object must be an array or string"); @@ -1633,7 +1633,7 @@ export class Interpreter { } } return this.evaluateBlock(node.body, macroScope); - }) + }), ); // Macros are not evaluated immediately, so we return null @@ -1767,7 +1767,7 @@ function convertToRuntimeValues(input: unknown): AnyRuntimeValue { return new ArrayValue(input.map(convertToRuntimeValues)); } else { return new ObjectValue( - new Map(Object.entries(input).map(([key, value]) => [key, convertToRuntimeValues(value)])) + new Map(Object.entries(input).map(([key, value]) => [key, convertToRuntimeValues(value)])), ); } case "function": diff --git a/packages/languages/package.json b/packages/languages/package.json index a3283e07f6..2e0fffd152 100644 --- a/packages/languages/package.json +++ b/packages/languages/package.json @@ -1,12 +1,21 @@ { "name": "@huggingface/languages", - "packageManager": "pnpm@10.10.0", "version": "1.0.0", "description": "List of ISO-639 languages used in the Hub", + "keywords": [ + "hub", + "huggingface", + "languages" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" - }, + "source": "index.ts", + "files": [ + "dist", + "src", + "tsconfig.json" + ], "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -17,7 +26,9 @@ "import": "./dist/index.mjs" } }, - "source": "index.ts", + "publishConfig": { + "access": "public" + }, "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -28,17 +39,6 @@ "test": "vitest run", "check": "tsc" }, - "files": [ - "dist", - "src", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "hub", - "languages" - ], - "author": "Hugging Face", - "license": "MIT", - "devDependencies": {} + "devDependencies": {}, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/mcp-client/cli.ts b/packages/mcp-client/cli.ts index 5437c4b9cc..7422b8df93 100644 --- a/packages/mcp-client/cli.ts +++ b/packages/mcp-client/cli.ts @@ -74,13 +74,13 @@ async function main() { model: MODEL_ID, apiKey: process.env.HF_TOKEN, servers: SERVERS, - } + } : { provider: PROVIDER, model: MODEL_ID, apiKey: process.env.HF_TOKEN, servers: SERVERS, - } + }, ); const rl = readline.createInterface({ input: stdin, output: stdout }); diff --git a/packages/mcp-client/package.json b/packages/mcp-client/package.json index ec54e33889..9e30ffab71 100644 --- a/packages/mcp-client/package.json +++ b/packages/mcp-client/package.json @@ -1,18 +1,31 @@ { "name": "@huggingface/mcp-client", - "packageManager": "pnpm@10.10.0", "version": "0.2.3", "description": "Client for the Model Context Protocol", + "keywords": [ + "agent", + "client", + "huggingface", + "mcp", + "model context protocol", + "tiny-agent" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" + "bin": { + "tiny-agent": "./dist/cli.js" }, + "source": "index.ts", + "files": [ + "cli.ts", + "dist", + "src", + "tsconfig.json" + ], "main": "./dist/src/index.js", "module": "./dist/src/index.mjs", "types": "./dist/src/index.d.ts", - "bin": { - "tiny-agent": "./dist/cli.js" - }, "exports": { ".": { "types": "./dist/src/index.d.ts", @@ -20,10 +33,9 @@ "import": "./dist/src/index.mjs" } }, - "engines": { - "node": ">=18" + "publishConfig": { + "access": "public" }, - "source": "index.ts", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -36,25 +48,13 @@ "check": "tsc", "cli": "tsx cli.ts" }, - "files": [ - "src", - "dist", - "cli.ts", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "mcp", - "model context protocol", - "client", - "agent", - "tiny-agent" - ], - "author": "Hugging Face", - "license": "MIT", "dependencies": { "@huggingface/inference": "workspace:^", "@huggingface/tasks": "workspace:^", "@modelcontextprotocol/sdk": "^1.11.2" - } + }, + "engines": { + "node": ">=18" + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/mcp-client/src/Agent.ts b/packages/mcp-client/src/Agent.ts index 4708761612..655bc678d6 100644 --- a/packages/mcp-client/src/Agent.ts +++ b/packages/mcp-client/src/Agent.ts @@ -99,7 +99,7 @@ export class Agent extends McpClient { async *run( input: string | ChatCompletionInputMessage[], - opts: { abortSignal?: AbortSignal } = {} + opts: { abortSignal?: AbortSignal } = {}, ): AsyncGenerator { let messages: ChatCompletionInputMessage[]; if (typeof input === "string") { diff --git a/packages/mcp-client/src/McpClient.ts b/packages/mcp-client/src/McpClient.ts index 9c5f0726d5..7d211fe4ca 100644 --- a/packages/mcp-client/src/McpClient.ts +++ b/packages/mcp-client/src/McpClient.ts @@ -94,7 +94,7 @@ export class McpClient { const toolsResult = await mcp.listTools(); debug( "Connected to server with tools:", - toolsResult.tools.map(({ name }) => name) + toolsResult.tools.map(({ name }) => name), ); for (const tool of toolsResult.tools) { @@ -111,7 +111,7 @@ export class McpClient { parameters: tool.inputSchema, }, } satisfies ChatCompletionInputTool; - }) + }), ); } @@ -121,7 +121,7 @@ export class McpClient { exitLoopTools?: ChatCompletionInputTool[]; exitIfFirstChunkNoTool?: boolean; abortSignal?: AbortSignal; - } = {} + } = {}, ): AsyncGenerator { debug("start of single turn"); @@ -135,7 +135,7 @@ export class McpClient { }, { signal: opts.abortSignal, - } + }, ); const message = { diff --git a/packages/mcp-client/src/ResultFormatter.ts b/packages/mcp-client/src/ResultFormatter.ts index 04c93e9e7f..2caa4fb73a 100644 --- a/packages/mcp-client/src/ResultFormatter.ts +++ b/packages/mcp-client/src/ResultFormatter.ts @@ -35,7 +35,7 @@ export class ResultFormatter { // Summarize image content const imageSize = this.getBase64Size(item.data); formattedParts.push( - `[Binary Content: Image ${item.mimeType}, ${imageSize} bytes]\nThe task is complete and the content accessible to the User` + `[Binary Content: Image ${item.mimeType}, ${imageSize} bytes]\nThe task is complete and the content accessible to the User`, ); break; } @@ -44,7 +44,7 @@ export class ResultFormatter { // Summarize audio content const audioSize = this.getBase64Size(item.data); formattedParts.push( - `[Binary Content: Audio ${item.mimeType}, ${audioSize} bytes]\nThe task is complete and the content accessible to the User` + `[Binary Content: Audio ${item.mimeType}, ${audioSize} bytes]\nThe task is complete and the content accessible to the User`, ); break; } @@ -62,7 +62,7 @@ export class ResultFormatter { const uri = blobResource.uri ? ` (${blobResource.uri})` : ""; const mimeType = blobResource.mimeType ? blobResource.mimeType : "unknown type"; formattedParts.push( - `[Binary Content${uri}: ${mimeType}, ${blobSize} bytes]\nThe task is complete and the content accessible to the User` + `[Binary Content${uri}: ${mimeType}, ${blobSize} bytes]\nThe task is complete and the content accessible to the User`, ); } break; diff --git a/packages/mcp-client/src/utils.ts b/packages/mcp-client/src/utils.ts index 66e8f8ece6..8f5ad208e1 100644 --- a/packages/mcp-client/src/utils.ts +++ b/packages/mcp-client/src/utils.ts @@ -54,7 +54,7 @@ export function urlToServerConfig(urlStr: string, authToken?: string): ServerCon Authorization: `Bearer ${authToken}`, }, }, - } + } : undefined, }, }; @@ -81,7 +81,7 @@ export function urlToServerConfig(urlStr: string, authToken?: string): ServerCon }); }, }, - } + } : undefined, }, }; diff --git a/packages/ollama-utils/package.json b/packages/ollama-utils/package.json index 6b5893def3..8e735d9d21 100644 --- a/packages/ollama-utils/package.json +++ b/packages/ollama-utils/package.json @@ -1,14 +1,28 @@ { "name": "@huggingface/ollama-utils", - "packageManager": "pnpm@10.10.0", "version": "0.0.17", "description": "Various utilities for maintaining Ollama compatibility with models on Hugging Face hub", + "keywords": [ + "gguf", + "hub", + "huggingface" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" - }, + "source": "index.ts", + "files": [ + "dist", + "src", + "tsconfig.json" + ], "main": "./dist/index.js", "module": "./dist/index.mjs", + "browser": { + "./src/utils/FileBlob.ts": false, + "./dist/index.js": "./dist/browser/index.js", + "./dist/index.mjs": "./dist/browser/index.mjs" + }, "types": "./dist/index.d.ts", "exports": { ".": { @@ -17,15 +31,9 @@ "import": "./dist/index.mjs" } }, - "browser": { - "./src/utils/FileBlob.ts": false, - "./dist/index.js": "./dist/browser/index.js", - "./dist/index.mjs": "./dist/browser/index.mjs" - }, - "engines": { - "node": ">=20" + "publishConfig": { + "access": "public" }, - "source": "index.ts", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -37,22 +45,14 @@ "test": "vitest run", "check": "tsc" }, - "files": [ - "dist", - "src", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "hub", - "gguf" - ], - "author": "Hugging Face", - "license": "MIT", "dependencies": { "@huggingface/jinja": "workspace:^" }, "devDependencies": { "@types/node": "^20.12.8" - } + }, + "engines": { + "node": ">=20" + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/ollama-utils/scripts/generate-automap.ts b/packages/ollama-utils/scripts/generate-automap.ts index 12d154f5a4..34b0b792bf 100644 --- a/packages/ollama-utils/scripts/generate-automap.ts +++ b/packages/ollama-utils/scripts/generate-automap.ts @@ -88,7 +88,7 @@ const getSpecialTokens = (tmpl: string): string[] => { await Promise.all( Array(N_WORKERS) .fill(null) - .map(() => workerGetTags()) + .map(() => workerGetTags()), ); console.log({ modelsWithTag }); @@ -198,7 +198,7 @@ const getSpecialTokens = (tmpl: string): string[] => { await Promise.all( Array(N_WORKERS) .fill(null) - .map(() => workerGetTemplate()) + .map(() => workerGetTemplate()), ); console.log("===================================="); @@ -224,6 +224,6 @@ ${skippedModelsDueToErr.map((m) => ` * - ${m}`).join("\n")} */ export const OLLAMA_CHAT_TEMPLATE_MAPPING: OllamaChatTemplateMapEntry[] = ${JSON.stringify(output, null, "\t")}; - `.trim() + `.trim(), ); })(); diff --git a/packages/ollama-utils/src/chat-template.spec.ts b/packages/ollama-utils/src/chat-template.spec.ts index e451d968ef..bbd70c2278 100644 --- a/packages/ollama-utils/src/chat-template.spec.ts +++ b/packages/ollama-utils/src/chat-template.spec.ts @@ -17,7 +17,7 @@ describe("chat-template", () => { }); expect(ollamaTmpl && ollamaTmpl.ollama); expect(ollamaTmpl?.ollama.template).toEqual( - "<|im_start|>system\n{{ .System }}<|im_end|>\n<|im_start|>user\n{{ .Prompt }}<|im_end|>\n<|im_start|>assistant\n" + "<|im_start|>system\n{{ .System }}<|im_end|>\n<|im_start|>user\n{{ .Prompt }}<|im_end|>\n<|im_start|>assistant\n", ); expect(ollamaTmpl?.ollama.tokens).toEqual(["<|im_start|>", "<|im_end|>"]); expect(ollamaTmpl?.ollama.params?.stop).toEqual(["<|im_start|>", "<|im_end|>"]); @@ -30,7 +30,7 @@ describe("chat-template", () => { }); expect(ollamaTmpl && ollamaTmpl.ollama); expect(ollamaTmpl?.ollama.template).toEqual( - "{{ if .System }}<|im_start|>system\n{{ .System }}<|im_end|>\n{{ end }}{{ if .Prompt }}<|im_start|>user\n{{ .Prompt }}<|im_end|>\n{{ end }}<|im_start|>assistant\n{{ .Response }}<|im_end|>\n" + "{{ if .System }}<|im_start|>system\n{{ .System }}<|im_end|>\n{{ end }}{{ if .Prompt }}<|im_start|>user\n{{ .Prompt }}<|im_end|>\n{{ end }}<|im_start|>assistant\n{{ .Response }}<|im_end|>\n", ); expect(ollamaTmpl?.ollama.tokens).toEqual(["<|im_start|>", "<|im_end|>"]); }); @@ -42,7 +42,7 @@ describe("chat-template", () => { }); expect(ollamaTmpl && ollamaTmpl.ollama); expect(ollamaTmpl?.ollama.template).toEqual( - "{{ if .System }}<|system|>\n{{ .System }}{{ end }}{{ if .Prompt }}<|user|>\n{{ .Prompt }}{{ end }}<|assistant|>\n{{ .Response }}" + "{{ if .System }}<|system|>\n{{ .System }}{{ end }}{{ if .Prompt }}<|user|>\n{{ .Prompt }}{{ end }}<|assistant|>\n{{ .Response }}", ); }); @@ -55,7 +55,7 @@ describe("chat-template", () => { }); expect(ollamaTmpl && ollamaTmpl.ollama); expect(ollamaTmpl?.ollama.template).toEqual( - "{{ if .System }}<|MY_CUSTOM_TOKEN_START|>system\n{{ .System }}<|MY_CUSTOM_TOKEN_END|>\n{{ end }}{{ if .Prompt }}<|MY_CUSTOM_TOKEN_START|>user\n{{ .Prompt }}<|MY_CUSTOM_TOKEN_END|>\n{{ end }}<|MY_CUSTOM_TOKEN_START|>assistant\n{{ .Response }}<|MY_CUSTOM_TOKEN_END|>\n" + "{{ if .System }}<|MY_CUSTOM_TOKEN_START|>system\n{{ .System }}<|MY_CUSTOM_TOKEN_END|>\n{{ end }}{{ if .Prompt }}<|MY_CUSTOM_TOKEN_START|>user\n{{ .Prompt }}<|MY_CUSTOM_TOKEN_END|>\n{{ end }}<|MY_CUSTOM_TOKEN_START|>assistant\n{{ .Response }}<|MY_CUSTOM_TOKEN_END|>\n", ); expect(ollamaTmpl?.ollama.params?.stop).toEqual([ "<|MY_CUSTOM_TOKEN_START|>", diff --git a/packages/ollama-utils/src/chat-template.ts b/packages/ollama-utils/src/chat-template.ts index fa65c651d5..1fbdd04fd5 100644 --- a/packages/ollama-utils/src/chat-template.ts +++ b/packages/ollama-utils/src/chat-template.ts @@ -10,21 +10,21 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate ggufTmpl.match(/<用户>/) && ggufTmpl.match(//) ? { ollamaTmpl: "<用户>{{ .Prompt }}", - } + } : undefined, (ggufTmpl: string) => ggufTmpl.match(/### Instruction:/) ? { ollamaTmpl: "{{ .System }}\n### Instruction:\n{{ .Prompt }}\n### Response:\n", stop: "### Instruction:", - } + } : undefined, (ggufTmpl: string) => ggufTmpl.match(/Human:/) ? { ollamaTmpl: "{{ .System }}\nHuman: {{ .Prompt }}\n\nAssistant:", stop: "Human:", - } + } : undefined, (ggufTmpl: string) => ggufTmpl.match(//) @@ -33,7 +33,7 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate ollamaTmpl: "user\n{{ if .System }}{{ .System }} {{ end }}{{ .Prompt }}\nmodel\n{{ .Response }}\n", stop: "", - } + } : undefined, (ggufTmpl: string) => ggufTmpl.match(/(bos_token|'') \+ message\['role'\]/) @@ -42,7 +42,7 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate ollamaTmpl: "{{ if .System }}system\n{{ .System }}{{ end }}{{ if .Prompt }}user\n{{ .Prompt }}{{ end }}assistant\n{{ .Response }}", stop: "", - } + } : undefined, (ggufTmpl: string) => ggufTmpl.match(/<\|start_header_id\|>/) && ggufTmpl.match(/eos_token|<\/s>/) @@ -51,7 +51,7 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate ollamaTmpl: "{{ if .System }}<|start_header_id|>system<|end_header_id|>\n\n{{ .System }}{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>\n\n{{ .Prompt }}{{ end }}<|start_header_id|>assistant<|end_header_id|>\n\n{{ .Response }}", stop: "", - } + } : undefined, (ggufTmpl: string) => ggufTmpl.match(/<\|assistant\|>/) && ggufTmpl.match(/<\|end\|>/) @@ -60,7 +60,7 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate ollamaTmpl: "{{ if .System }}<|system|>\n{{ .System }}<|end|>\n{{ end }}{{ if .Prompt }}<|user|>\n{{ .Prompt }}<|end|>\n{{ end }}<|assistant|>\n{{ .Response }}<|end|>", stop: "<|end|>", - } + } : undefined, (ggufTmpl: string) => ggufTmpl.match(/<\|{{ item\['role'\] }}\|>/) && ggufTmpl.match(/<\|begin_of_image\|>/) @@ -70,7 +70,7 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate ollamaTmpl: "{{ if .System }}<|system|>\n{{ .System }}{{ end }}{{ if .Prompt }}<|user|>\n{{ .Prompt }}{{ end }}<|assistant|>\n{{ .Response }}", stop: "<|user|>", - } + } : undefined, (ggufTmpl: string) => ggufTmpl.match(/<\|START_OF_TURN_TOKEN\|>/) && ggufTmpl.match(/<\|USER_TOKEN\|>/) @@ -79,7 +79,7 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate ollamaTmpl: "{{ if .System }}<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ .System }}<|END_OF_TURN_TOKEN|>{{ end }}{{ if .Prompt }}<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{ .Prompt }}<|END_OF_TURN_TOKEN|>{{ end }}<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><|START_RESPONSE|>{{ .Response }}<|END_RESPONSE|><|END_OF_TURN_TOKEN|>", stop: "<|END_OF_TURN_TOKEN|>", - } + } : undefined, (ggufTmpl: string) => ggufTmpl.match(/Mistral Small 3/) && ggufTmpl.match(/2023-10-01/) @@ -89,7 +89,7 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate ollamaTmpl: '{{- range $index, $_ := .Messages }}\n{{- if eq .Role "system" }}[SYSTEM_PROMPT]{{ .Content }}[/SYSTEM_PROMPT]\n{{- else if eq .Role "user" }}\n{{- if and (le (len (slice $.Messages $index)) 2) $.Tools }}[AVAILABLE_TOOLS]{{ $.Tools }}[/AVAILABLE_TOOLS]\n{{- end }}[INST]{{ .Content }}[/INST]\n{{- else if eq .Role "assistant" }}\n{{- if .Content }}{{ .Content }}\n{{- if not (eq (len (slice $.Messages $index)) 1) }}\n{{- end }}\n{{- else if .ToolCalls }}[TOOL_CALLS][\n{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}\n{{- end }}]\n{{- end }}\n{{- else if eq .Role "tool" }}[TOOL_RESULTS]{"content": {{ .Content }}}[/TOOL_RESULTS]\n{{- end }}\n{{- end }}', stop: "[INST]", - } + } : undefined, (ggufTmpl: string) => ggufTmpl.match(/rwkv-world/) @@ -97,7 +97,7 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate // ref: https://huggingface.co/BlinkDL/rwkv-5-world ollamaTmpl: "{{ .System }}\nUser: {{ .Prompt }}\n\nAssistant:", stop: "### Instruction:", - } + } : undefined, (ggufTmpl: string) => (ggufTmpl.match(/\[gMASK\]/) && ggufTmpl.match(/<\|user\|>/)) || ggufTmpl.match(/chatglm4/) @@ -106,7 +106,7 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate ollamaTmpl: "[gMASK]{{ if .System }}<|system|>\n{{ .System }}{{ end }}{{ if .Prompt }}<|user|>\n{{ .Prompt }}{{ end }}<|assistant|>\n{{ .Response }}", stop: "<|user|>", - } + } : undefined, ]; @@ -116,7 +116,7 @@ export function convertGGUFTemplateToOllama( // for error tracking purpose debugModelId?: string; logDebug?: (typeof console)["debug"]; - } + }, ): OllamaChatTemplateMapEntry | undefined { if (!gguf.chat_template) { return undefined; @@ -148,7 +148,7 @@ export function convertGGUFTemplateToOllama( if (matched) { // @ngxson wants to track this options?.logDebug?.( - `🔍 Custom map Jinja to Go:\n\n\`\`\`${matched.ollamaTmpl}\`\`\`\n\nhttps://hf.co/api/models/${options?.debugModelId}` + `🔍 Custom map Jinja to Go:\n\n\`\`\`${matched.ollamaTmpl}\`\`\`\n\nhttps://hf.co/api/models/${options?.debugModelId}`, ); return { model: "custom-matching", @@ -159,7 +159,7 @@ export function convertGGUFTemplateToOllama( params: matched.stop ? { stop: [matched.stop], - } + } : {}, }, }; @@ -176,7 +176,7 @@ export function convertGGUFTemplateToOllama( } // @ngxson wants to track this options?.logDebug?.( - `🙏 Converted Jinja to Go:\n\n\`\`\`${convertedToGo.tmpl}\`\`\`\n\nhttps://hf.co/api/models/${options?.debugModelId}` + `🙏 Converted Jinja to Go:\n\n\`\`\`${convertedToGo.tmpl}\`\`\`\n\nhttps://hf.co/api/models/${options?.debugModelId}`, ); return { model: "auto-conversion", @@ -192,8 +192,8 @@ export function convertGGUFTemplateToOllama( options?.logDebug?.( `❌ Cannot map jinja template:\n\n\`\`\`${gguf.chat_template.substring( 0, - 200 - )}...\`\`\`\n\nhttps://hf.co/api/models/${options?.debugModelId}` + 200, + )}...\`\`\`\n\nhttps://hf.co/api/models/${options?.debugModelId}`, ); } diff --git a/packages/space-header/package.json b/packages/space-header/package.json index 5e67ecd195..0863ca0fdf 100644 --- a/packages/space-header/package.json +++ b/packages/space-header/package.json @@ -1,14 +1,27 @@ { "name": "@huggingface/space-header", "version": "1.0.4", - "packageManager": "pnpm@10.10.0", "description": "Use the Space mini_header outside Hugging Face", + "keywords": [ + "huggingface", + "space-header", + "spaces" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" - }, + "files": [ + "dist", + "index.ts", + "src", + "tsconfig.json" + ], "main": "./dist/index.js", "module": "./dist/index.mjs", + "browser": { + "./dist/index.js": "./dist/browser/index.js", + "./dist/index.mjs": "./dist/browser/index.mjs" + }, "types": "./dist/index.d.ts", "exports": { ".": { @@ -17,9 +30,8 @@ "import": "./dist/index.mjs" } }, - "browser": { - "./dist/index.js": "./dist/browser/index.js", - "./dist/index.mjs": "./dist/browser/index.mjs" + "publishConfig": { + "access": "public" }, "scripts": { "build": "tsup && tsc --emitDeclarationOnly --declaration", @@ -29,21 +41,9 @@ "format:check": "oxfmt --check .", "prepublishOnly": "pnpm run build" }, - "keywords": [ - "huggingface", - "spaces", - "space-header" - ], - "files": [ - "src", - "dist", - "index.ts", - "tsconfig.json" - ], - "author": "Hugging Face", - "license": "MIT", "devDependencies": { "tsup": "^8.1.0", "typescript": "^5.4.5" - } + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/space-header/src/header/components/collapse/arrow.ts b/packages/space-header/src/header/components/collapse/arrow.ts index 2671e87b26..3a820a75ee 100644 --- a/packages/space-header/src/header/components/collapse/arrow.ts +++ b/packages/space-header/src/header/components/collapse/arrow.ts @@ -15,7 +15,7 @@ export const ArrowCollapse = (): SVGElement => { path.setAttribute( "d", - "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" + "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", ); arrow.appendChild(path); diff --git a/packages/space-header/src/header/components/like/heart.ts b/packages/space-header/src/header/components/like/heart.ts index c370e593cb..09d0f284f6 100644 --- a/packages/space-header/src/header/components/like/heart.ts +++ b/packages/space-header/src/header/components/like/heart.ts @@ -15,7 +15,7 @@ export const Heart = (): SVGElement => { path.setAttribute( "d", - "M22.45,6a5.47,5.47,0,0,1,3.91,1.64,5.7,5.7,0,0,1,0,8L16,26.13,5.64,15.64a5.7,5.7,0,0,1,0-8,5.48,5.48,0,0,1,7.82,0L16,10.24l2.53-2.58A5.44,5.44,0,0,1,22.45,6m0-2a7.47,7.47,0,0,0-5.34,2.24L16,7.36,14.89,6.24a7.49,7.49,0,0,0-10.68,0,7.72,7.72,0,0,0,0,10.82L16,29,27.79,17.06a7.72,7.72,0,0,0,0-10.82A7.49,7.49,0,0,0,22.45,4Z" + "M22.45,6a5.47,5.47,0,0,1,3.91,1.64,5.7,5.7,0,0,1,0,8L16,26.13,5.64,15.64a5.7,5.7,0,0,1,0-8,5.48,5.48,0,0,1,7.82,0L16,10.24l2.53-2.58A5.44,5.44,0,0,1,22.45,6m0-2a7.47,7.47,0,0,0-5.34,2.24L16,7.36,14.89,6.24a7.49,7.49,0,0,0-10.68,0,7.72,7.72,0,0,0,0,10.82L16,29,27.79,17.06a7.72,7.72,0,0,0,0-10.82A7.49,7.49,0,0,0,22.45,4Z", ); heart.appendChild(path); diff --git a/packages/space-header/src/index.ts b/packages/space-header/src/index.ts index 35fe129d19..dfb9e4fa81 100644 --- a/packages/space-header/src/index.ts +++ b/packages/space-header/src/index.ts @@ -13,7 +13,7 @@ async function main(initialSpace: string | Space, options?: Options) { const has_huggingface_ancestor = Object.values( window.location?.ancestorOrigins ?? { 0: window.document.referrer, - } + }, ).some((origin) => new URL(origin)?.origin === "https://huggingface.co"); if (has_huggingface_ancestor) return; diff --git a/packages/tasks-gen/package.json b/packages/tasks-gen/package.json index 4b1c767fcf..969bfd45c9 100644 --- a/packages/tasks-gen/package.json +++ b/packages/tasks-gen/package.json @@ -1,10 +1,12 @@ { "name": "@huggingface/tasks-gen", - "packageManager": "pnpm@10.10.0", "version": "0.13.1", + "private": true, "description": "Utilities to generate files for @huggingface/tasks, and avoid unnecessary deps in the published package", + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "private": true, + "type": "module", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -17,16 +19,14 @@ "inference-tei-import": "tsx scripts/inference-tei-import.ts && oxfmt ../tasks/src/tasks/feature-extraction/spec/*.json", "test": "vitest run" }, - "type": "module", - "author": "Hugging Face", - "license": "MIT", + "dependencies": { + "@huggingface/inference": "workspace:^", + "@huggingface/tasks": "workspace:^" + }, "devDependencies": { "@types/node": "^20.11.5", "quicktype-core": "https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz", "type-fest": "^3.13.1" }, - "dependencies": { - "@huggingface/tasks": "workspace:^", - "@huggingface/inference": "workspace:^" - } + "packageManager": "pnpm@10.10.0" } diff --git a/packages/tasks-gen/scripts/generate-snippets-fixtures.ts b/packages/tasks-gen/scripts/generate-snippets-fixtures.ts index 4b23c4a8dc..69c8c00013 100644 --- a/packages/tasks-gen/scripts/generate-snippets-fixtures.ts +++ b/packages/tasks-gen/scripts/generate-snippets-fixtures.ts @@ -357,7 +357,7 @@ function generateInferenceSnippet( provider: InferenceProviderOrPolicy, task: WidgetType, lora: boolean = false, - opts?: Record + opts?: Record, ): InferenceSnippet[] { const allSnippets = snippets.getInferenceSnippets( model, @@ -372,10 +372,10 @@ function generateInferenceSnippet( ? { adapter: "lora", adapterWeightsPath: ``, - } + } : {}), }, - opts + opts, ); return allSnippets .filter((snippet) => snippet.language == language) @@ -385,7 +385,7 @@ function generateInferenceSnippet( async function getExpectedInferenceSnippet( testName: string, language: Language, - provider: SnippetInferenceProvider + provider: SnippetInferenceProvider, ): Promise { const fixtureFolder = getFixtureFolder(testName); const languageFolder = path.join(fixtureFolder, language); @@ -407,7 +407,7 @@ async function saveExpectedInferenceSnippet( testName: string, language: Language, provider: SnippetInferenceProvider, - snippets: InferenceSnippet[] + snippets: InferenceSnippet[], ) { const fixtureFolder = getFixtureFolder(testName); await fs.mkdir(fixtureFolder, { recursive: true }); diff --git a/packages/tasks-gen/scripts/inference-codegen.ts b/packages/tasks-gen/scripts/inference-codegen.ts index 8c6911dde5..ff5fbb14b2 100644 --- a/packages/tasks-gen/scripts/inference-codegen.ts +++ b/packages/tasks-gen/scripts/inference-codegen.ts @@ -101,7 +101,7 @@ interface JSONSchemaSpec { async function postProcessOutput( path2generated: string, outputSpec: JSONSchemaSpec, - inputSpec: JSONSchemaSpec + inputSpec: JSONSchemaSpec, ): Promise { await generateBinaryInputTypes(path2generated, inputSpec, outputSpec); await generateTopLevelArrays(path2generated, outputSpec); @@ -110,12 +110,12 @@ async function postProcessOutput( async function generateBinaryInputTypes( path2generated: string, inputSpec: JSONSchemaSpec, - outputSpec: JSONSchemaSpec + outputSpec: JSONSchemaSpec, ): Promise { const tsSource = ts.createSourceFile( path.basename(path2generated), await fs.readFile(path2generated, { encoding: "utf-8" }), - ts.ScriptTarget.ES2022 + ts.ScriptTarget.ES2022, ); const inputRootName = inputSpec.title; @@ -128,7 +128,7 @@ async function generateBinaryInputTypes( let newNodes = [...topLevelNodes]; for (const interfaceNode of topLevelNodes.filter( - (node): node is ts.InterfaceDeclaration => node.kind === ts.SyntaxKind.InterfaceDeclaration + (node): node is ts.InterfaceDeclaration => node.kind === ts.SyntaxKind.InterfaceDeclaration, )) { if (interfaceNode.name.escapedText !== inputRootName && interfaceNode.name.escapedText !== outputRootName) { continue; @@ -150,7 +150,7 @@ async function generateBinaryInputTypes( // eslint-disable-next-line @typescript-eslint/no-explicit-any typeof (spec as any)["properties"]?.[propName]?.["comment"] === "string" ? // eslint-disable-next-line @typescript-eslint/no-explicit-any - !!(spec as any)["properties"][propName]["comment"].includes("type=binary") + !!(spec as any)["properties"][propName]["comment"].includes("type=binary") : false; if (!propIsMedia) { return; @@ -161,7 +161,7 @@ async function generateBinaryInputTypes( propSignature.modifiers, propSignature.name, propSignature.questionToken, - updatedType + updatedType, ); const updatedInterface = ts.factory.updateInterfaceDeclaration( interfaceNode, @@ -169,7 +169,7 @@ async function generateBinaryInputTypes( interfaceNode.name, interfaceNode.typeParameters, interfaceNode.heritageClauses, - [updated, ...interfaceNode.members.filter((member) => member.name?.getText(tsSource) !== propName)] + [updated, ...interfaceNode.members.filter((member) => member.name?.getText(tsSource) !== propName)], ); newNodes = [updatedInterface, ...newNodes.filter((node) => node !== interfaceNode)]; }); @@ -182,7 +182,7 @@ async function generateBinaryInputTypes( { flag: "w+", encoding: "utf-8", - } + }, ); } @@ -201,7 +201,7 @@ async function generateTopLevelArrays(path2generated: string, outputSpec: Record const source = ts.createSourceFile( path.basename(path2generated), await fs.readFile(path2generated, { encoding: "utf-8" }), - ts.ScriptTarget.ES2022 + ts.ScriptTarget.ES2022, ); const exportedName = outputSpec.title; if (outputSpec.type !== "array" || typeof exportedName !== "string") { @@ -212,7 +212,7 @@ async function generateTopLevelArrays(path2generated: string, outputSpec: Record const hasTypeAlias = topLevelNodes.some( (node) => node.kind === ts.SyntaxKind.TypeAliasDeclaration && - (node as ts.TypeAliasDeclaration).name.escapedText === exportedName + (node as ts.TypeAliasDeclaration).name.escapedText === exportedName, ); if (hasTypeAlias) { return; @@ -237,13 +237,13 @@ async function generateTopLevelArrays(path2generated: string, outputSpec: Record ts.factory.createIdentifier(interfaceDeclaration.name.getText(source) + "Element"), interfaceDeclaration.typeParameters, interfaceDeclaration.heritageClauses, - interfaceDeclaration.members + interfaceDeclaration.members, ); const arrayDeclaration = ts.factory.createTypeAliasDeclaration( [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], exportedName, undefined, - ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode(updatedInterface.name)) + ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode(updatedInterface.name)), ); const printer = ts.createPrinter(); @@ -270,7 +270,7 @@ const allTasks = await Promise.all( (await fs.readdir(tasksDir, { withFileTypes: true })) .filter((entry) => entry.isDirectory()) .filter((entry) => entry.name !== "placeholder") - .map(async (entry) => ({ task: entry.name, dirPath: path.join(entry.parentPath, entry.name) })) + .map(async (entry) => ({ task: entry.name, dirPath: path.join(entry.parentPath, entry.name) })), ); const allSpecFiles = [ path.join(tasksDir, "common-definitions.json"), diff --git a/packages/tasks/package.json b/packages/tasks/package.json index 34db238d5a..171fa92c9b 100644 --- a/packages/tasks/package.json +++ b/packages/tasks/package.json @@ -1,12 +1,25 @@ { "name": "@huggingface/tasks", - "packageManager": "pnpm@10.10.0", "version": "0.19.78", "description": "List of ML tasks for huggingface.co/tasks", + "keywords": [ + "hub", + "huggingface", + "languages" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" - }, + "source": "./src/index.ts", + "files": [ + "dist", + "src", + "tsconfig.json" + ], + "type": "module", + "main": "./dist/commonjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/commonjs/index.d.ts", "exports": { "./package.json": "./package.json", ".": { @@ -20,7 +33,9 @@ } } }, - "source": "./src/index.ts", + "publishConfig": { + "access": "public" + }, "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -35,26 +50,11 @@ "check": "tsc", "test": "vitest run" }, - "type": "module", - "files": [ - "dist", - "src", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "hub", - "languages" - ], - "author": "Hugging Face", - "license": "MIT", "tshy": { "exports": { - "./package.json": "./package.json", - ".": "./src/index.ts" + ".": "./src/index.ts", + "./package.json": "./package.json" } }, - "main": "./dist/commonjs/index.js", - "types": "./dist/commonjs/index.d.ts", - "module": "./dist/esm/index.js" + "packageManager": "pnpm@10.10.0" } diff --git a/packages/tasks/src/default-widget-inputs.ts b/packages/tasks/src/default-widget-inputs.ts index 4d74561a16..7185abe6da 100644 --- a/packages/tasks/src/default-widget-inputs.ts +++ b/packages/tasks/src/default-widget-inputs.ts @@ -642,11 +642,7 @@ const MAPPING_DV: PerLanguageMapping = new Map([ ["text-classification", [`އަހަރެން ގަޔާވޭ. އަހަރެން ލޯބިވޭ`]], [ "token-classification", - [ - `އަހަރެންގެ ނަމަކީ އަހުމަދު އަދި އަހަރެން ދިރިއުޅެނީ މާލޭގަ`, - `އަހަރެންގެ ނަމަކީ ސާރާ އަދި އަހަރެން ދިރިއުޅެނީ އުތީމުގަ`, - `އަހަރެންގެ ނަމަކީ އައިޝާ އަދި އަހަރެން ދިރިއުޅެނީ ފޭދޫ، އައްޑޫގަ`, - ], + [`އަހަރެންގެ ނަމަކީ އަހުމަދު އަދި އަހަރެން ދިރިއުޅެނީ މާލޭގަ`, `އަހަރެންގެ ނަމަކީ ސާރާ އަދި އަހަރެން ދިރިއުޅެނީ އުތީމުގަ`, `އަހަރެންގެ ނަމަކީ އައިޝާ އަދި އަހަރެން ދިރިއުޅެނީ ފޭދޫ، އައްޑޫގަ`], ], [ "question-answering", @@ -669,13 +665,7 @@ const MAPPING_DV: PerLanguageMapping = new Map([ }, ], ], - [ - "translation", - [ - `އަހަރެންގެ ނަމަކީ އަހުމަދު އަދި އަހަރެން ދިރިއުޅެނީ މާލޭގަ`, - `އަހަރެންގެ ނަމަކީ ސާރާ އަދި އަހަރެން ދިރިއުޅެނީ އުތީމުގަ`, - ], - ], + ["translation", [`އަހަރެންގެ ނަމަކީ އަހުމަދު އަދި އަހަރެން ދިރިއުޅެނީ މާލޭގަ`, `އަހަރެންގެ ނަމަކީ ސާރާ އަދި އަހަރެން ދިރިއުޅެނީ އުތީމުގަ`]], [ "summarization", [ @@ -684,12 +674,7 @@ const MAPPING_DV: PerLanguageMapping = new Map([ ], [ "text-generation", - [ - `އަހަރެންގެ ނަމަކީ ޔޫސުފް އަދި އަހަރެންގެ މައިގަނޑު`, - `އަހަރެންގެ ނަމަކީ މަރިއަމް، އަހަރެން އެންމެ ގަޔާވާ`, - `އަހަރެންގެ ނަމަކީ ފާތުމަތު އަދި އަހަރެން`, - `،އެއް ޒަމާނެއްގައި`, - ], + [`އަހަރެންގެ ނަމަކީ ޔޫސުފް އަދި އަހަރެންގެ މައިގަނޑު`, `އަހަރެންގެ ނަމަކީ މަރިއަމް، އަހަރެން އެންމެ ގަޔާވާ`, `އަހަރެންގެ ނަމަކީ ފާތުމަތު އަދި އަހަރެން`, `،އެއް ޒަމާނެއްގައި`], ], ["fill-mask", [`. މާލެ އަކީ ދިވެހިރާއްޖޭގެ`, `ގަރުދިޔައަކީ ދިވެހިންގެ މެދުގައި ކެއުމެއް.`]], ]); diff --git a/packages/tasks/src/gguf.ts b/packages/tasks/src/gguf.ts index 828a40a8f5..d7ed5843e9 100644 --- a/packages/tasks/src/gguf.ts +++ b/packages/tasks/src/gguf.ts @@ -128,7 +128,7 @@ export const GGUF_QUANT_ORDER: GGMLFileQuantizationType[] = [ // It returns undefined if no such quantization type is found. export function findNearestQuantType( quant: GGMLFileQuantizationType, - availableQuants: GGMLFileQuantizationType[] + availableQuants: GGMLFileQuantizationType[], ): GGMLFileQuantizationType | undefined { // Create a map for quick index lookup from the defined order const orderMap = new Map(); diff --git a/packages/tasks/src/local-apps.ts b/packages/tasks/src/local-apps.ts index 65517f86fd..5d1f4d5f94 100644 --- a/packages/tasks/src/local-apps.ts +++ b/packages/tasks/src/local-apps.ts @@ -189,7 +189,7 @@ const snippetLocalAI = (model: ModelData, filepath?: string): LocalAppSnippet[] "docker pull localai/localai:latest-cpu", ].join("\n"), content: command( - "docker run -p 8080:8080 --name localai -v $PWD/models:/build/models localai/localai:latest-cpu" + "docker run -p 8080:8080 --name localai -v $PWD/models:/build/models localai/localai:latest-cpu", ), }, ]; @@ -317,7 +317,7 @@ const snippetMlxLm = (model: ModelData): LocalAppSnippet[] => { setup: ["# Install MLX LM", "uv tool install mlx-lm"].join("\n"), content: ["# Start the server", `mlx_lm.server --model "${model.id}"`, ...openaiCurl].join("\n"), }, - ] + ] : []), ]; }; diff --git a/packages/tasks/src/model-libraries-snippets.ts b/packages/tasks/src/model-libraries-snippets.ts index c0bd91e447..5dc3a0346b 100644 --- a/packages/tasks/src/model-libraries-snippets.ts +++ b/packages/tasks/src/model-libraries-snippets.ts @@ -1024,7 +1024,7 @@ python -m lerobot.record \\ --dataset.repo_id=HF_USER/dataset_name \\ # <- This will be the dataset name on HF Hub --dataset.episode_time_s=50 \\ --dataset.num_episodes=10 \\ - --policy.path=${model.id}` + --policy.path=${model.id}`, ); } return smolvlaSnippets; @@ -1644,14 +1644,14 @@ export const transformers = (model: ModelData): string[] => { info.processor === "AutoTokenizer" ? "tokenizer" : info.processor === "AutoFeatureExtractor" - ? "extractor" - : "processor"; + ? "extractor" + : "processor"; autoSnippet.push( "# Load model directly", `from transformers import ${info.processor}, ${info.auto_model}`, "", `${processorVarName} = ${info.processor}.from_pretrained("${model.id}"` + remote_code_snippet + ")", - `model = ${info.auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ")" + `model = ${info.auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ")", ); if (model.tags.includes("conversational") && hasChatTemplate(model)) { if (model.tags.includes("image-text-to-text")) { @@ -1666,7 +1666,7 @@ export const transformers = (model: ModelData): string[] => { " ]", " },", ].join("\n"), - "]" + "]", ); } else { autoSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]"); @@ -1681,14 +1681,14 @@ export const transformers = (model: ModelData): string[] => { ").to(model.device)", "", "outputs = model.generate(**inputs, max_new_tokens=40)", - `print(${processorVarName}.decode(outputs[0][inputs["input_ids"].shape[-1]:]))` + `print(${processorVarName}.decode(outputs[0][inputs["input_ids"].shape[-1]:]))`, ); } } else { autoSnippet.push( "# Load model directly", `from transformers import ${info.auto_model}`, - `model = ${info.auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', dtype="auto")' + `model = ${info.auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', dtype="auto")', ); } @@ -1713,7 +1713,7 @@ export const transformers = (model: ModelData): string[] => { " ]", " },", ].join("\n"), - "]" + "]", ); pipelineSnippet.push("pipe(text=messages)"); } else { @@ -1725,11 +1725,11 @@ export const transformers = (model: ModelData): string[] => { "pipe(", ' "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png",', ' candidate_labels=["animals", "humans", "landscape"],', - ")" + ")", ); } else if (model.pipeline_tag === "image-classification") { pipelineSnippet.push( - 'pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")' + 'pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")', ); } @@ -2140,7 +2140,7 @@ export const pruna = (model: ModelData): string[] => { if (model.tags.includes("pruna_pro-ai")) { return snippets.map((snippet) => - snippet.replace(/\bpruna\b/g, "pruna_pro").replace(/\bPrunaModel\b/g, "PrunaProModel") + snippet.replace(/\bpruna\b/g, "pruna_pro").replace(/\bPrunaModel\b/g, "PrunaProModel"), ); } @@ -2164,7 +2164,7 @@ const pruna_diffusers = (model: ModelData): string[] => { .replace(/from diffusers import PrunaModel, ([^,\n]+)/g, "from diffusers import $1") // Clean up whitespace .replace(/\n\n+/g, "\n") - .trim() + .trim(), ); }; @@ -2176,7 +2176,7 @@ const pruna_transformers = (model: ModelData): string[] => { let processedSnippets = transformersSnippets.map((snippet) => snippet .replace(/from transformers import pipeline/g, "from pruna import PrunaModel") - .replace(/pipeline\([^)]*\)/g, `PrunaModel.from_pretrained("${model.id}")`) + .replace(/pipeline\([^)]*\)/g, `PrunaModel.from_pretrained("${model.id}")`), ); // Additional cleanup if auto_model info is available @@ -2186,8 +2186,8 @@ const pruna_transformers = (model: ModelData): string[] => { .replace(new RegExp(`from transformers import ${info.auto_model}\n?`, "g"), "") .replace(new RegExp(`${info.auto_model}.from_pretrained`, "g"), "PrunaModel.from_pretrained") .replace(new RegExp(`^.*from.*import.*(, *${info.auto_model})+.*$`, "gm"), (line) => - line.replace(new RegExp(`, *${info.auto_model}`, "g"), "") - ) + line.replace(new RegExp(`, *${info.auto_model}`, "g"), ""), + ), ); } diff --git a/packages/tasks/src/snippets/common.ts b/packages/tasks/src/snippets/common.ts index 907bc34089..5b325d35f7 100644 --- a/packages/tasks/src/snippets/common.ts +++ b/packages/tasks/src/snippets/common.ts @@ -6,7 +6,7 @@ export function stringifyMessages( indent?: string; attributeKeyQuotes?: boolean; customContentEscaper?: (str: string) => string; - } + }, ): string { let messagesStr = JSON.stringify(messages, null, "\t"); if (opts?.indent) { @@ -29,7 +29,7 @@ export function stringifyGenerationConfig( indent: string; attributeValueConnector: string; attributeKeyQuotes?: boolean; - } + }, ): string { const quote = opts.attributeKeyQuotes ? `"` : ""; diff --git a/packages/tasks/src/snippets/inputs.ts b/packages/tasks/src/snippets/inputs.ts index 4a55d20a65..cffcde67ad 100644 --- a/packages/tasks/src/snippets/inputs.ts +++ b/packages/tasks/src/snippets/inputs.ts @@ -61,7 +61,7 @@ const inputsTextGeneration = (model: ModelDataMinimal): string | ChatCompletionI }, ], }, - ]; + ]; } return `"Can you please let us know more details about your "`; }; @@ -168,7 +168,7 @@ const modelInputSnippets: { export function getModelInputSnippet( model: ModelDataMinimal, noWrap = false, - noQuotes = false + noQuotes = false, ): string | ChatCompletionInputMessage[] { if (model.pipeline_tag) { const inputs = modelInputSnippets[model.pipeline_tag]; diff --git a/packages/tasks/src/tasks/tabular-regression/about.md b/packages/tasks/src/tasks/tabular-regression/about.md index 53c7b6599e..4a6d9d302c 100644 --- a/packages/tasks/src/tasks/tabular-regression/about.md +++ b/packages/tasks/src/tasks/tabular-regression/about.md @@ -71,7 +71,6 @@ gr.Interface.load("huggingface/username/my-awesome-model").launch() - [Notebook: Persisting your scikit-learn model using skops](https://www.kaggle.com/code/unofficialmerve/persisting-your-scikit-learn-model-using-skops) - For starting with tabular regression: - - Doing [Exploratory Data Analysis](https://neptune.ai/blog/exploratory-data-analysis-for-tabular-data) for tabular data. - The data considered here consists of details of Olympic athletes and medal results from Athens 1896 to Rio 2016. - Here you can learn more about how to explore and analyse the data and visualize them in order to get a better understanding of dataset. diff --git a/packages/tasks/src/widget-example.ts b/packages/tasks/src/widget-example.ts index 780953bcae..2f60cd76bc 100644 --- a/packages/tasks/src/widget-example.ts +++ b/packages/tasks/src/widget-example.ts @@ -61,8 +61,9 @@ export interface WidgetExampleTextInput extends W text: string; } -export interface WidgetExampleTextAndContextInput - extends WidgetExampleTextInput { +export interface WidgetExampleTextAndContextInput< + TOutput = WidgetExampleOutput, +> extends WidgetExampleTextInput { context: string; } @@ -73,8 +74,9 @@ export interface WidgetExampleTextAndTableInput e export interface WidgetExampleAssetInput extends WidgetExampleBase { src: string; } -export interface WidgetExampleAssetAndPromptInput - extends WidgetExampleAssetInput { +export interface WidgetExampleAssetAndPromptInput< + TOutput = WidgetExampleOutput, +> extends WidgetExampleAssetInput { prompt: string; } @@ -98,8 +100,9 @@ export interface WidgetExampleZeroShotTextInput e multi_class: boolean; } -export interface WidgetExampleSentenceSimilarityInput - extends WidgetExampleBase { +export interface WidgetExampleSentenceSimilarityInput< + TOutput = WidgetExampleOutput, +> extends WidgetExampleBase { source_sentence: string; sentences: string[]; } diff --git a/packages/tiny-agents/package.json b/packages/tiny-agents/package.json index f8d2c37cab..5380650558 100644 --- a/packages/tiny-agents/package.json +++ b/packages/tiny-agents/package.json @@ -1,18 +1,29 @@ { "name": "@huggingface/tiny-agents", - "packageManager": "pnpm@10.10.0", "version": "0.3.4", "description": "Lightweight, composable agents for AI applications", + "keywords": [ + "agent", + "ai", + "huggingface", + "llm", + "tiny-agent" + ], + "license": "MIT", + "author": "Hugging Face", "repository": "https://github.com/huggingface/huggingface.js.git", - "publishConfig": { - "access": "public" + "bin": { + "tiny-agents": "./dist/cli.js" }, + "source": "index.ts", + "files": [ + "dist", + "src", + "tsconfig.json" + ], "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", - "bin": { - "tiny-agents": "./dist/cli.js" - }, "exports": { ".": { "types": "./dist/index.d.ts", @@ -20,10 +31,9 @@ "import": "./dist/index.mjs" } }, - "engines": { - "node": ">=18" + "publishConfig": { + "access": "public" }, - "source": "index.ts", "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .", "lint:check": "eslint --ext .cjs,.ts .", @@ -37,26 +47,16 @@ "cli": "tsx src/cli.ts", "cli:watch": "tsx watch src/cli.ts" }, - "files": [ - "src", - "dist", - "tsconfig.json" - ], - "keywords": [ - "huggingface", - "agent", - "ai", - "llm", - "tiny-agent" - ], - "author": "Hugging Face", - "license": "MIT", "dependencies": { + "@huggingface/hub": "workspace:^", "@huggingface/inference": "workspace:^", "@huggingface/mcp-client": "workspace:^", "@huggingface/tasks": "workspace:^", - "@huggingface/hub": "workspace:^", "@modelcontextprotocol/sdk": "^1.11.4", "zod": "^3.25.7" - } + }, + "engines": { + "node": ">=18" + }, + "packageManager": "pnpm@10.10.0" } diff --git a/packages/tiny-agents/src/cli.ts b/packages/tiny-agents/src/cli.ts index cda8bd3ca7..6e1d1b9ce6 100644 --- a/packages/tiny-agents/src/cli.ts +++ b/packages/tiny-agents/src/cli.ts @@ -235,7 +235,7 @@ async function main() { apiKey: config.apiKey ?? process.env.API_KEY ?? process.env.HF_TOKEN, servers: formattedServers, prompt, - } + } : { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion provider: config.provider!, @@ -243,7 +243,7 @@ async function main() { apiKey: config.apiKey ?? process.env.API_KEY ?? process.env.HF_TOKEN, servers: formattedServers, prompt, - } + }, ); debug(agent); diff --git a/packages/tiny-agents/src/lib/loadConfigFrom.ts b/packages/tiny-agents/src/lib/loadConfigFrom.ts index 365c7444af..4f5a047e81 100644 --- a/packages/tiny-agents/src/lib/loadConfigFrom.ts +++ b/packages/tiny-agents/src/lib/loadConfigFrom.ts @@ -39,7 +39,7 @@ async function tryLoadFromDirectory(dirPath: string): Promise } error( - `Config file not found in tiny-agents! Please make sure it exists locally or in https://huggingface.co/datasets/tiny-agents/tiny-agents.` + `Config file not found in tiny-agents! Please make sure it exists locally or in https://huggingface.co/datasets/tiny-agents/tiny-agents.`, ); process.exit(1); } diff --git a/packages/tiny-agents/src/lib/webServer.ts b/packages/tiny-agents/src/lib/webServer.ts index 21cf17a53c..a56db6f291 100644 --- a/packages/tiny-agents/src/lib/webServer.ts +++ b/packages/tiny-agents/src/lib/webServer.ts @@ -26,11 +26,11 @@ const ChatCompletionInputSchema = z.object({ image_url: z.object({ url: z.string(), }), - }) - ) - ) + }), + ), + ), ), - }) + }), ), /// Only allow stream: true stream: z.literal(true), @@ -81,7 +81,7 @@ export function startServer(agent: Agent): void { "Content-Type": "text/event-stream", "Cache-Control": "no-cache", Connection: "keep-alive", - }) + }), ); /// Prepend the agent's prompt From e48d0797c81d19d23ecf0840caa57967a51127fb Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 20 Jan 2026 11:23:19 +0000 Subject: [PATCH 03/10] remove reference to pretierrc --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6590bbba31..ea4ba5a426 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .eslintrc.cjs", "lint:check": "eslint --ext .cjs,.ts .eslintrc.cjs", - "format": "oxfmt package.json .prettierrc .vscode .eslintrc.cjs e2e .github *.md", - "format:check": "oxfmt --check package.json .prettierrc .vscode .eslintrc.cjs .github *.md", + "format": "oxfmt package.json .vscode .eslintrc.cjs e2e .github *.md .devcontainer oxfmtrc.json", + "format:check": "oxfmt --check package.json .vscode .eslintrc.cjs .github *.md .devcontainer oxfmtrc.json", "check-deps": "tsx scripts/check-deps.ts" }, "devDependencies": { From 53c500a58308a92cd288b93eee1a164b16560369 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 20 Jan 2026 11:29:03 +0000 Subject: [PATCH 04/10] avoid CI issues --- .oxfmtrc.json | 3 ++- .vscode/settings.json | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.oxfmtrc.json b/.oxfmtrc.json index c886b57061..d0dae2ef23 100644 --- a/.oxfmtrc.json +++ b/.oxfmtrc.json @@ -2,5 +2,6 @@ "$schema": "./node_modules/oxfmt/configuration_schema.json", "ignorePatterns": [], "useTabs": true, - "printWidth": 120 + "printWidth": 120, + "experimentalSortPackageJson": false } diff --git a/.vscode/settings.json b/.vscode/settings.json index 2aa98ee0f2..af686f945e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,5 +17,8 @@ }, "[jsonc]": { "editor.defaultFormatter": "oxc.oxc-vscode" + }, + "[json]": { + "editor.defaultFormatter": "oxc.oxc-vscode" } } From 346f561131265b54c8e7f07fb45aa7986c05c047 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 20 Jan 2026 11:37:32 +0000 Subject: [PATCH 05/10] revert some json ordering --- packages/inference/package.json | 4 ++-- packages/tasks/package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/inference/package.json b/packages/inference/package.json index 686f253f9b..e3237a0426 100644 --- a/packages/inference/package.json +++ b/packages/inference/package.json @@ -28,7 +28,6 @@ "module": "./dist/esm/index.js", "types": "./dist/commonjs/index.d.ts", "exports": { - "./package.json": "./package.json", ".": { "import": { "types": "./dist/esm/index.d.ts", @@ -38,7 +37,8 @@ "types": "./dist/commonjs/index.d.ts", "default": "./dist/commonjs/index.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/packages/tasks/package.json b/packages/tasks/package.json index 171fa92c9b..463c62beb4 100644 --- a/packages/tasks/package.json +++ b/packages/tasks/package.json @@ -21,7 +21,6 @@ "module": "./dist/esm/index.js", "types": "./dist/commonjs/index.d.ts", "exports": { - "./package.json": "./package.json", ".": { "import": { "types": "./dist/esm/index.d.ts", @@ -31,7 +30,8 @@ "types": "./dist/commonjs/index.d.ts", "default": "./dist/commonjs/index.js" } - } + }, + "./package.json": "./package.json" }, "publishConfig": { "access": "public" From 4321aff538bf212813422425488635cdaf52fc7e Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 20 Jan 2026 11:38:32 +0000 Subject: [PATCH 06/10] fix editor config --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index 0cf077588e..baa6575ec1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,3 +1,4 @@ +[js,json,jsonc,ts,tsx] max_line_length = 120 indent_style = tab indent_size = 2 From ebe77f5147efbd29fb1fee1e19643c212b877e82 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 20 Jan 2026 11:39:18 +0000 Subject: [PATCH 07/10] add dot --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ea4ba5a426..43c3b472fe 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "scripts": { "lint": "eslint --quiet --fix --ext .cjs,.ts .eslintrc.cjs", "lint:check": "eslint --ext .cjs,.ts .eslintrc.cjs", - "format": "oxfmt package.json .vscode .eslintrc.cjs e2e .github *.md .devcontainer oxfmtrc.json", - "format:check": "oxfmt --check package.json .vscode .eslintrc.cjs .github *.md .devcontainer oxfmtrc.json", + "format": "oxfmt package.json .vscode .eslintrc.cjs e2e .github *.md .devcontainer .oxfmtrc.json", + "format:check": "oxfmt --check package.json .vscode .eslintrc.cjs .github *.md .devcontainer .oxfmtrc.json", "check-deps": "tsx scripts/check-deps.ts" }, "devDependencies": { From d83fec3f70cee807158115954504a06a159377cf Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 20 Jan 2026 11:42:26 +0000 Subject: [PATCH 08/10] fix format after codegen --- packages/tasks-gen/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/tasks-gen/package.json b/packages/tasks-gen/package.json index 969bfd45c9..1339f3baf9 100644 --- a/packages/tasks-gen/package.json +++ b/packages/tasks-gen/package.json @@ -14,9 +14,9 @@ "format:check": "oxfmt --check .", "check": "tsc", "generate-snippets-fixtures": "tsx scripts/generate-snippets-fixtures.ts", - "inference-codegen": "tsx scripts/inference-codegen.ts && oxfmt ../tasks/src/tasks/*/inference.ts", - "inference-tgi-import": "tsx scripts/inference-tgi-import.ts && oxfmt ../tasks/src/tasks/text-generation/spec/*.json && oxfmt ../tasks/src/tasks/chat-completion/spec/*.json", - "inference-tei-import": "tsx scripts/inference-tei-import.ts && oxfmt ../tasks/src/tasks/feature-extraction/spec/*.json", + "inference-codegen": "tsx scripts/inference-codegen.ts && pnpm --filter tasks format", + "inference-tgi-import": "tsx scripts/inference-tgi-import.ts && pnpm --filter tasks format", + "inference-tei-import": "tsx scripts/inference-tei-import.ts && pnpm --filter tasks format", "test": "vitest run" }, "dependencies": { From 53e554c5315472ec6d101bc4b9e4bb22d2795c0d Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 20 Jan 2026 11:43:18 +0000 Subject: [PATCH 09/10] editor config again --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index baa6575ec1..b722685134 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -[js,json,jsonc,ts,tsx] +[*.{js,json,jsonc,ts,tsx}] max_line_length = 120 indent_style = tab indent_size = 2 From 2166d776b92a88ef5b3dbbfa8fc1d12dd46279d1 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 20 Jan 2026 11:50:23 +0000 Subject: [PATCH 10/10] add comment --- .oxfmtrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.oxfmtrc.json b/.oxfmtrc.json index d0dae2ef23..024e469e7b 100644 --- a/.oxfmtrc.json +++ b/.oxfmtrc.json @@ -3,5 +3,6 @@ "ignorePatterns": [], "useTabs": true, "printWidth": 120, + // Because tshy modifies the package.json file, the "exports" subprop "experimentalSortPackageJson": false }