Skip to content

Commit 3d866cc

Browse files
authored
Merge branch 'main' into add-chatterbox-snippet
2 parents fee2e65 + 017cf3a commit 3d866cc

Some content is hidden

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

52 files changed

+1083
-327
lines changed

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- "README.md"
1212
- "packages/hub/README.md"
1313
- "packages/inference/README.md"
14-
- "packages/agents/README.md"
14+
- "packages/tiny-agents/README.md"
1515
- ".github/workflows/documentation.yml"
1616

1717
jobs:

.github/workflows/pr-documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- "packages/hub/README.md"
99
- "packages/doc-internal/**"
1010
- "packages/inference/README.md"
11-
- "packages/agents/README.md"
11+
- "packages/tiny-agents/README.md"
1212

1313
concurrency:
1414
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

README.md

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

9898
```html
9999
<script type="module">
100-
import { InferenceClient } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@3.13.2/+esm';
100+
import { InferenceClient } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@4.0.0/+esm';
101101
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
102102
</script>
103103
```

docs/_toctree.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
isExpanded: true
1919
sections:
2020
- local: mcp-client/README
21-
title: Simple MCP Client and smol Agent built on top of Inference Client
22-
- title: "@huggingface/agent"
21+
title: Simple MCP Client built on top of Inference Client
22+
- title: "@huggingface/tiny-agents"
2323
isExpanded: true
2424
sections:
25-
- local: agents/README
26-
title: Use Agents to run multi-modal workflows from a natural language API
27-
- local: agents/modules
28-
title: API Reference
25+
- local: tiny-agents/README
26+
title: A lightweight MCP-powered Agent built on top of Inference Client
2927
- title: "@huggingface/space-header"
3028
isExpanded: true
3129
sections:

packages/doc-internal/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
"description": "Package to generate doc for other @huggingface packages",
66
"private": true,
77
"scripts": {
8-
"start": "pnpm run fix-cdn-versions && pnpm run doc-hub && pnpm run doc-inference && pnpm run doc-agents && pnpm run doc-space-header && pnpm run doc-gguf && pnpm run doc-mcp-client && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
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",
99
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
1010
"lint:check": "eslint --ext .cjs,.ts .",
1111
"format": "prettier --write .",
1212
"format:check": "prettier --check .",
1313
"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",
1414
"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",
15-
"doc-agents": "typedoc --tsconfig ../agents/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/agents --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../agents/src/index.ts",
1615
"doc-gguf": "mkdir -p ../../docs/gguf && cp ../../packages/gguf/README.md ../../docs/gguf/README.md",
1716
"doc-mcp-client": "mkdir -p ../../docs/mcp-client && cp ../../packages/mcp-client/README.md ../../docs/mcp-client/README.md",
17+
"doc-tiny-agents": "mkdir -p ../../docs/tiny-agents && cp ../../packages/tiny-agents/README.md ../../docs/tiny-agents/README.md",
1818
"doc-space-header": "mkdir -p ../../docs/space-header && cp ../../packages/space-header/README.md ../../docs/space-header/README.md",
1919
"update-toc": "tsx update-toc.ts",
2020
"fix-cdn-versions": "tsx fix-cdn-versions.ts",

packages/hub/cli.ts

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { parseArgs } from "node:util";
44
import { typedEntries } from "./src/utils/typedEntries";
5-
import { createBranch, createRepo, deleteBranch, repoExists, uploadFilesWithProgress } from "./src";
5+
import { createBranch, createRepo, deleteBranch, deleteRepo, repoExists, uploadFilesWithProgress } from "./src";
66
import { pathToFileURL } from "node:url";
77
import { stat } from "node:fs/promises";
88
import { basename, join } from "node:path";
@@ -78,7 +78,6 @@ const commands = {
7878
{
7979
name: "repo-type" as const,
8080
enum: ["dataset", "model", "space"],
81-
default: "model",
8281
description:
8382
"The type of repo to upload to. Defaults to model. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
8483
},
@@ -126,9 +125,8 @@ const commands = {
126125
{
127126
name: "repo-type" as const,
128127
enum: ["dataset", "model", "space"],
129-
default: "model",
130128
description:
131-
"The type of repo to create. Defaults to model. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
129+
"The type of the repo to create the branch into. Defaults to model. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
132130
},
133131
{
134132
name: "revision" as const,
@@ -173,7 +171,6 @@ const commands = {
173171
{
174172
name: "repo-type" as const,
175173
enum: ["dataset", "model", "space"],
176-
default: "model",
177174
description:
178175
"The type of repo to delete the branch from. Defaults to model. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
179176
},
@@ -187,6 +184,35 @@ const commands = {
187184
},
188185
},
189186
} satisfies CommandGroup,
187+
repo: {
188+
description: "Manage repositories on the Hub",
189+
subcommands: {
190+
delete: {
191+
description: "Delete a repository from the Hub",
192+
args: [
193+
{
194+
name: "repo-name" as const,
195+
description:
196+
"The name of the repo to delete. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
197+
positional: true,
198+
required: true,
199+
},
200+
{
201+
name: "repo-type" as const,
202+
enum: ["dataset", "model", "space"],
203+
description:
204+
"The type of the repo to delete. Defaults to model. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
205+
},
206+
{
207+
name: "token" as const,
208+
description:
209+
"The access token to use for authentication. If not provided, the HF_TOKEN environment variable will be used.",
210+
default: process.env.HF_TOKEN,
211+
},
212+
] as const,
213+
},
214+
},
215+
} satisfies CommandGroup,
190216
version: {
191217
description: "Print the version of the CLI",
192218
args: [] as const,
@@ -389,6 +415,54 @@ async function run() {
389415
}
390416
break;
391417
}
418+
case "repo": {
419+
const repoCommandGroup = commands.repo;
420+
const currentSubCommandName = subCommandName as keyof typeof repoCommandGroup.subcommands | undefined;
421+
422+
if (cliArgs[0] === "--help" || cliArgs[0] === "-h") {
423+
if (currentSubCommandName && repoCommandGroup.subcommands[currentSubCommandName]) {
424+
console.log(detailedUsageForSubcommand("repo", currentSubCommandName));
425+
} else {
426+
console.log(listSubcommands("repo", repoCommandGroup));
427+
}
428+
break;
429+
}
430+
431+
if (!currentSubCommandName || !repoCommandGroup.subcommands[currentSubCommandName]) {
432+
console.error(`Error: Missing or invalid subcommand for 'repo'.`);
433+
console.log(listSubcommands("repo", repoCommandGroup));
434+
process.exitCode = 1;
435+
break;
436+
}
437+
438+
const subCmdDef = repoCommandGroup.subcommands[currentSubCommandName];
439+
440+
switch (currentSubCommandName) {
441+
case "delete": {
442+
const parsedArgs = advParseArgs(cliArgs, subCmdDef.args, `repo ${currentSubCommandName}`);
443+
const { repoName, repoType, token } = parsedArgs;
444+
445+
const repoDesignation: Parameters<typeof deleteRepo>[0]["repo"] = repoType
446+
? { type: repoType as "model" | "dataset" | "space", name: repoName }
447+
: repoName;
448+
449+
await deleteRepo({
450+
repo: repoDesignation,
451+
accessToken: token,
452+
hubUrl: process.env.HF_ENDPOINT ?? HUB_URL,
453+
});
454+
console.log(`Repository '${repoName}' deleted successfully.`);
455+
break;
456+
}
457+
default:
458+
// This case should ideally be caught by the check above
459+
console.error(`Error: Unknown subcommand '${currentSubCommandName}' for 'repo'.`);
460+
console.log(listSubcommands("repo", repoCommandGroup));
461+
process.exitCode = 1;
462+
break;
463+
}
464+
break;
465+
}
392466
case "version": {
393467
if (cliArgs[0] === "--help" || cliArgs[0] === "-h") {
394468
console.log(detailedUsageForCommand("version"));

packages/hub/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type {
1818
SpaceStage,
1919
} from "./types/public";
2020
export { HubApiError, InvalidApiResponseFormatError } from "./error";
21+
export { HUB_URL } from "./consts";
2122
/**
2223
* Only exported for E2Es convenience
2324
*/

packages/inference/README.md

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Currently, we support the following providers:
5353
- [HF Inference](https://huggingface.co/docs/inference-providers/providers/hf-inference)
5454
- [Hyperbolic](https://hyperbolic.xyz)
5555
- [Nebius](https://studio.nebius.ai)
56-
- [Novita](https://novita.ai/?utm_source=github_huggingface&utm_medium=github_readme&utm_campaign=link)
56+
- [Novita](https://novita.ai)
5757
- [Nscale](https://nscale.com)
5858
- [OVHcloud](https://endpoints.ai.cloud.ovh.net/)
5959
- [Replicate](https://replicate.com)
@@ -96,6 +96,7 @@ Only a subset of models are supported when requesting third-party providers. You
9696
- [Cohere supported models](https://huggingface.co/api/partners/cohere/models)
9797
- [Cerebras supported models](https://huggingface.co/api/partners/cerebras/models)
9898
- [Groq supported models](https://console.groq.com/docs/models)
99+
- [Novita AI supported models](https://huggingface.co/api/partners/novita/models)
99100

100101
**Important note:** To be compatible, the third-party API must adhere to the "standard" shape API we expect on HF model pages for each pipeline task type.
101102
This is not an issue for LLMs as everyone converged on the OpenAI API anyways, but can be more tricky for other tasks like "text-to-image" or "automatic-speech-recognition" where there exists no standard API. Let us know if any help is needed or if we can make things easier for you!
@@ -119,6 +120,108 @@ await textGeneration({
119120

120121
This will enable tree-shaking by your bundler.
121122

123+
### Error handling
124+
125+
The inference package provides specific error types to help you handle different error scenarios effectively.
126+
127+
#### Error Types
128+
129+
The package defines several error types that extend the base `Error` class:
130+
131+
- `InferenceClientError`: Base error class for all Hugging Face Inference errors
132+
- `InferenceClientInputError`: Thrown when there are issues with input parameters
133+
- `InferenceClientProviderApiError`: Thrown when there are API-level errors from providers
134+
- `InferenceClientHubApiError`: Thrown when there are API-levels errors from the Hugging Face Hub
135+
- `InferenceClientProviderOutputError`: Thrown when there are issues with providers' API responses format
136+
137+
### Example Usage
138+
139+
```typescript
140+
import { InferenceClient } from "@huggingface/inference";
141+
import {
142+
InferenceClientError,
143+
InferenceClientProviderApiError,
144+
InferenceClientProviderOutputError,
145+
InferenceClientHubApiError,
146+
} from "@huggingface/inference";
147+
148+
const client = new InferenceClient();
149+
150+
try {
151+
const result = await client.textGeneration({
152+
model: "gpt2",
153+
inputs: "Hello, I'm a language model",
154+
});
155+
} catch (error) {
156+
if (error instanceof InferenceClientProviderApiError) {
157+
// Handle API errors (e.g., rate limits, authentication issues)
158+
console.error("Provider API Error:", error.message);
159+
console.error("HTTP Request details:", error.request);
160+
console.error("HTTP Response details:", error.response);
161+
if (error instanceof InferenceClientHubApiError) {
162+
// Handle API errors (e.g., rate limits, authentication issues)
163+
console.error("Hub API Error:", error.message);
164+
console.error("HTTP Request details:", error.request);
165+
console.error("HTTP Response details:", error.response);
166+
} else if (error instanceof InferenceClientProviderOutputError) {
167+
// Handle malformed responses from providers
168+
console.error("Provider Output Error:", error.message);
169+
} else if (error instanceof InferenceClientInputError) {
170+
// Handle invalid input parameters
171+
console.error("Input Error:", error.message);
172+
} else {
173+
// Handle unexpected errors
174+
console.error("Unexpected error:", error);
175+
}
176+
}
177+
178+
/// Catch all errors from @huggingface/inference
179+
try {
180+
const result = await client.textGeneration({
181+
model: "gpt2",
182+
inputs: "Hello, I'm a language model",
183+
});
184+
} catch (error) {
185+
if (error instanceof InferenceClientError) {
186+
// Handle errors from @huggingface/inference
187+
console.error("Error from InferenceClient:", error);
188+
} else {
189+
// Handle unexpected errors
190+
console.error("Unexpected error:", error);
191+
}
192+
}
193+
```
194+
195+
### Error Details
196+
197+
#### InferenceClientProviderApiError
198+
199+
This error occurs when there are issues with the API request when performing inference at the selected provider.
200+
201+
It has several properties:
202+
- `message`: A descriptive error message
203+
- `request`: Details about the failed request (URL, method, headers)
204+
- `response`: Response details including status code and body
205+
206+
#### InferenceClientHubApiError
207+
208+
This error occurs when there are issues with the API request when requesting the Hugging Face Hub API.
209+
210+
It has several properties:
211+
- `message`: A descriptive error message
212+
- `request`: Details about the failed request (URL, method, headers)
213+
- `response`: Response details including status code and body
214+
215+
216+
#### InferenceClientProviderOutputError
217+
218+
This error occurs when a provider returns a response in an unexpected format.
219+
220+
#### InferenceClientInputError
221+
222+
This error occurs when input parameters are invalid or missing. The error message describes what's wrong with the input.
223+
224+
122225
### Natural Language Processing
123226
124227
#### Text Generation

packages/inference/package.json

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

0 commit comments

Comments
 (0)