Skip to content

Commit e8d8e57

Browse files
authored
Merge branch 'main' into add-magi-1
2 parents fbdb6f3 + 905181b commit e8d8e57

File tree

44 files changed

+1670
-54
lines changed

Some content is hidden

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

44 files changed

+1670
-54
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: MCP Client - Version and Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
newversion:
7+
type: choice
8+
description: "Semantic Version Bump Type"
9+
default: patch
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
concurrency:
16+
group: "push-to-main"
17+
18+
defaults:
19+
run:
20+
working-directory: packages/mcp-client
21+
22+
jobs:
23+
version_and_release:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
with:
28+
token: ${{ secrets.BOT_ACCESS_TOKEN }}
29+
- run: npm install -g corepack@latest && corepack enable
30+
- uses: actions/setup-node@v3
31+
with:
32+
node-version: "20"
33+
cache: "pnpm"
34+
cache-dependency-path: |
35+
packages/mcp-client/pnpm-lock.yaml
36+
packages/doc-internal/pnpm-lock.yaml
37+
registry-url: "https://registry.npmjs.org"
38+
- run: pnpm install
39+
- run: git config --global user.name machineuser
40+
- run: git config --global user.email [email protected]
41+
- run: |
42+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
43+
BUMPED_VERSION=$(node -p "require('semver').inc('$PACKAGE_VERSION', '${{ github.event.inputs.newversion }}')")
44+
# Update package.json with the new version
45+
node -e "const fs = require('fs'); const package = JSON.parse(fs.readFileSync('./package.json')); package.version = '$BUMPED_VERSION'; fs.writeFileSync('./package.json', JSON.stringify(package, null, '\t') + '\n');"
46+
pnpm --filter doc-internal run fix-cdn-versions
47+
git add ../..
48+
git commit -m "🔖 @huggingface/mcp-client $BUMPED_VERSION"
49+
git tag "mcp-client-v$BUMPED_VERSION"
50+
51+
# Add checks for dependencies if needed, similar to hub-publish.yml
52+
- name: "Check Deps are published before publishing this package"
53+
run: pnpm -w check-deps inference && pnpm -w check-deps tasks
54+
55+
- run: pnpm publish --no-git-checks .
56+
env:
57+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
58+
- run: git pull --rebase && git push --follow-tags
59+
# hack - reuse actions/setup-node@v3 just to set a new registry
60+
- uses: actions/setup-node@v3
61+
with:
62+
node-version: "20"
63+
registry-url: "https://npm.pkg.github.com"
64+
# Disable for now, until github supports PATs for writing github packages (https://github.com/github/roadmap/issues/558)
65+
# - run: pnpm publish --no-git-checks .
66+
# env:
67+
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
- name: "Update Doc"
69+
uses: peter-evans/repository-dispatch@v2
70+
with:
71+
event-type: doc-build
72+
token: ${{ secrets.BOT_ACCESS_TOKEN }}

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/[email protected].1/+esm';
100+
import { InferenceClient } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected].2/+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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
title: Interact with the Hub
1515
- local: hub/modules
1616
title: API Reference
17+
- title: "@huggingface/mcp-client"
18+
isExpanded: true
19+
sections:
20+
- local: mcp-client/README
21+
title: Simple MCP Client and smol Agent built on top of Inference Client
1722
- title: "@huggingface/agent"
1823
isExpanded: true
1924
sections:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"check-deps": "tsx scripts/check-deps.ts"
1212
},
1313
"devDependencies": {
14+
"@types/node": "^22.14.1",
1415
"@typescript-eslint/eslint-plugin": "^7.2.0",
1516
"@typescript-eslint/parser": "^7.2.0",
16-
"@types/node": "^18.16.1",
1717
"@vitest/browser": "^0.34.6",
1818
"eslint": "^8.57.0",
1919
"eslint-config-prettier": "^9.0.0",

packages/doc-internal/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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 && 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-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",
99
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
1010
"lint:check": "eslint --ext .cjs,.ts .",
1111
"format": "prettier --write .",
@@ -14,6 +14,7 @@
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",
1515
"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",
1616
"doc-gguf": "mkdir -p ../../docs/gguf && cp ../../packages/gguf/README.md ../../docs/gguf/README.md",
17+
"doc-mcp-client": "mkdir -p ../../docs/mcp-client && cp ../../packages/mcp-client/README.md ../../docs/mcp-client/README.md",
1718
"doc-space-header": "mkdir -p ../../docs/space-header && cp ../../packages/space-header/README.md ../../docs/space-header/README.md",
1819
"update-toc": "tsx update-toc.ts",
1920
"fix-cdn-versions": "tsx fix-cdn-versions.ts",

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.9.1",
3+
"version": "3.9.2",
44
"packageManager": "[email protected]",
55
"license": "MIT",
66
"author": "Hugging Face and Tim Mikeladze <[email protected]>",

packages/inference/src/lib/getInferenceProviderMapping.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { typedInclude } from "../utils/typedInclude";
88
export const inferenceProviderMappingCache = new Map<ModelId, InferenceProviderMapping>();
99

1010
export type InferenceProviderMapping = Partial<
11-
Record<InferenceProvider, Omit<InferenceProviderModelMapping, "hfModelId" | "adapterWeightsPath">>
11+
Record<InferenceProvider, Omit<InferenceProviderModelMapping, "hfModelId">>
1212
>;
1313

1414
export interface InferenceProviderModelMapping {
@@ -74,22 +74,6 @@ export async function getInferenceProviderMapping(
7474
`Model ${params.modelId} is in staging mode for provider ${params.provider}. Meant for test purposes only.`
7575
);
7676
}
77-
if (providerMapping.adapter === "lora") {
78-
const treeResp = await (options?.fetch ?? fetch)(`${HF_HUB_URL}/api/models/${params.modelId}/tree/main`);
79-
if (!treeResp.ok) {
80-
throw new Error(`Unable to fetch the model tree for ${params.modelId}.`);
81-
}
82-
const tree: Array<{ type: "file" | "directory"; path: string }> = await treeResp.json();
83-
const adapterWeightsPath = tree.find(({ type, path }) => type === "file" && path.endsWith(".safetensors"))?.path;
84-
if (!adapterWeightsPath) {
85-
throw new Error(`No .safetensors file found in the model tree for ${params.modelId}.`);
86-
}
87-
return {
88-
...providerMapping,
89-
hfModelId: params.modelId,
90-
adapterWeightsPath,
91-
};
92-
}
9377
return { ...providerMapping, hfModelId: params.modelId };
9478
}
9579
return null;

packages/inference/src/providers/fal-ai.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,6 @@ export class FalAITextToImageTask extends FalAITask implements TextToImageTaskHe
8686
...(params.args.parameters as Record<string, unknown>),
8787
sync_mode: true,
8888
prompt: params.args.inputs,
89-
...(params.mapping?.adapter === "lora" && params.mapping.adapterWeightsPath
90-
? {
91-
loras: [
92-
{
93-
path: buildLoraPath(params.mapping.hfModelId, params.mapping.adapterWeightsPath),
94-
scale: 1,
95-
},
96-
],
97-
}
98-
: undefined),
9989
};
10090

10191
if (params.mapping?.adapter === "lora" && params.mapping.adapterWeightsPath) {

packages/inference/src/snippets/getInferenceSnippets.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
} from "@huggingface/tasks";
99
import type { PipelineType, WidgetType } from "@huggingface/tasks/src/pipelines.js";
1010
import type { ChatCompletionInputMessage, GenerationParameters } from "@huggingface/tasks/src/tasks/index.js";
11+
import type { InferenceProviderModelMapping } from "../lib/getInferenceProviderMapping";
12+
import { getProviderHelper } from "../lib/getProviderHelper";
1113
import { makeRequestOptionsFromResolvedModel } from "../lib/makeRequestOptions";
1214
import type { InferenceProvider, InferenceTask, RequestArgs } from "../types";
1315
import { templates } from "./templates.exported";
14-
import type { InferenceProviderModelMapping } from "../lib/getInferenceProviderMapping";
15-
import { getProviderHelper } from "../lib/getProviderHelper";
1616

1717
export type InferenceSnippetOptions = { streaming?: boolean; billTo?: string } & Record<string, unknown>;
1818

@@ -112,6 +112,7 @@ const HF_JS_METHODS: Partial<Record<WidgetType, string>> = {
112112
"text-generation": "textGeneration",
113113
"text2text-generation": "textGeneration",
114114
"token-classification": "tokenClassification",
115+
"text-to-speech": "textToSpeech",
115116
translation: "translation",
116117
};
117118

@@ -310,7 +311,7 @@ const snippets: Partial<
310311
"text-generation": snippetGenerator("basic"),
311312
"text-to-audio": snippetGenerator("textToAudio"),
312313
"text-to-image": snippetGenerator("textToImage"),
313-
"text-to-speech": snippetGenerator("textToAudio"),
314+
"text-to-speech": snippetGenerator("textToSpeech"),
314315
"text-to-video": snippetGenerator("textToVideo"),
315316
"text2text-generation": snippetGenerator("basic"),
316317
"token-classification": snippetGenerator("basic"),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{% if model.library_name == "transformers" %}
2+
async function query(data) {
3+
const response = await fetch(
4+
"{{ fullUrl }}",
5+
{
6+
headers: {
7+
Authorization: "{{ authorizationHeader }}",
8+
"Content-Type": "application/json",
9+
{% if billTo %}
10+
"X-HF-Bill-To": "{{ billTo }}",
11+
{% endif %} },
12+
method: "POST",
13+
body: JSON.stringify(data),
14+
}
15+
);
16+
const result = await response.blob();
17+
return result;
18+
}
19+
20+
query({ text: {{ inputs.asObj.inputs }} }).then((response) => {
21+
// Returns a byte object of the Audio wavform. Use it directly!
22+
});
23+
{% else %}
24+
async function query(data) {
25+
const response = await fetch(
26+
"{{ fullUrl }}",
27+
{
28+
headers: {
29+
Authorization: "{{ authorizationHeader }}",
30+
"Content-Type": "application/json",
31+
},
32+
method: "POST",
33+
body: JSON.stringify(data),
34+
}
35+
);
36+
const result = await response.json();
37+
return result;
38+
}
39+
40+
query({ text: {{ inputs.asObj.inputs }} }).then((response) => {
41+
console.log(JSON.stringify(response));
42+
});
43+
{% endif %}

0 commit comments

Comments
 (0)