@nodetool-ai/huggingface-nodes 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/huggingface-base.d.ts +140 -0
- package/dist/huggingface-base.d.ts.map +1 -0
- package/dist/huggingface-base.js +279 -0
- package/dist/huggingface-base.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/audio.d.ts +46 -0
- package/dist/nodes/audio.d.ts.map +1 -0
- package/dist/nodes/audio.js +132 -0
- package/dist/nodes/audio.js.map +1 -0
- package/dist/nodes/image.d.ts +126 -0
- package/dist/nodes/image.d.ts.map +1 -0
- package/dist/nodes/image.js +382 -0
- package/dist/nodes/image.js.map +1 -0
- package/dist/nodes/text.d.ts +227 -0
- package/dist/nodes/text.d.ts.map +1 -0
- package/dist/nodes/text.js +702 -0
- package/dist/nodes/text.js.map +1 -0
- package/dist/nodes/video.d.ts +34 -0
- package/dist/nodes/video.d.ts.map +1 -0
- package/dist/nodes/video.js +112 -0
- package/dist/nodes/video.js.map +1 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @nodetool-ai/huggingface-nodes
|
|
2
|
+
|
|
3
|
+
Workflow nodes for the [Hugging Face Inference Providers](https://huggingface.co/docs/inference-providers/tasks/index)
|
|
4
|
+
API — one node per documented task modality.
|
|
5
|
+
|
|
6
|
+
All nodes call the unified router at `https://router.huggingface.co` and need a
|
|
7
|
+
Hugging Face access token with the **Inference Providers** permission, stored as
|
|
8
|
+
the `HF_TOKEN` secret (Settings → API Keys).
|
|
9
|
+
|
|
10
|
+
## Tasks
|
|
11
|
+
|
|
12
|
+
| Modality | Node | `nodeType` |
|
|
13
|
+
| --- | --- | --- |
|
|
14
|
+
| Text | Chat Completion | `huggingface.ChatCompletion` |
|
|
15
|
+
| Text | Text Generation | `huggingface.TextGeneration` |
|
|
16
|
+
| Text | Summarization | `huggingface.Summarization` |
|
|
17
|
+
| Text | Translation | `huggingface.Translation` |
|
|
18
|
+
| Text | Fill Mask | `huggingface.FillMask` |
|
|
19
|
+
| Text | Question Answering | `huggingface.QuestionAnswering` |
|
|
20
|
+
| Text | Table Question Answering | `huggingface.TableQuestionAnswering` |
|
|
21
|
+
| Text | Feature Extraction (embeddings) | `huggingface.FeatureExtraction` |
|
|
22
|
+
| Text | Text Classification | `huggingface.TextClassification` |
|
|
23
|
+
| Text | Token Classification (NER) | `huggingface.TokenClassification` |
|
|
24
|
+
| Text | Zero Shot Classification | `huggingface.ZeroShotClassification` |
|
|
25
|
+
| Image | Text to Image | `huggingface.TextToImage` |
|
|
26
|
+
| Image | Image to Image | `huggingface.ImageToImage` |
|
|
27
|
+
| Image | Image Classification | `huggingface.ImageClassification` |
|
|
28
|
+
| Image | Image Segmentation | `huggingface.ImageSegmentation` |
|
|
29
|
+
| Image | Object Detection | `huggingface.ObjectDetection` |
|
|
30
|
+
| Audio | Automatic Speech Recognition | `huggingface.AutomaticSpeechRecognition` |
|
|
31
|
+
| Audio | Audio Classification | `huggingface.AudioClassification` |
|
|
32
|
+
| Video | Text to Video | `huggingface.TextToVideo` |
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { registerHuggingFaceNodes } from "@nodetool-ai/huggingface-nodes";
|
|
38
|
+
|
|
39
|
+
registerHuggingFaceNodes(registry);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Each node exposes a `model` field defaulting to a recommended model for the task;
|
|
43
|
+
any warm model on the Hub for that pipeline can be used by entering its repo id.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2026-09-28T09:19:08.119Z
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for the Hugging Face Inference Providers nodes.
|
|
3
|
+
*
|
|
4
|
+
* All task nodes talk to the unified router at https://router.huggingface.co:
|
|
5
|
+
* - Chat completion uses the OpenAI-compatible `/v1/chat/completions` route.
|
|
6
|
+
* - Every other ("pipeline") task posts to
|
|
7
|
+
* `/hf-inference/models/{model}` with a `{ inputs, parameters }` body.
|
|
8
|
+
*
|
|
9
|
+
* Binary-input tasks (image/audio in) send the media as a base64 string in
|
|
10
|
+
* `inputs`; binary-output tasks (image/video out) return raw bytes that we wrap
|
|
11
|
+
* into the matching media ref. The only non-`fetch` dependency is
|
|
12
|
+
* `fetchExternalMedia`, the shared egress policy a caller-supplied media uri
|
|
13
|
+
* goes through (`docs/url-egress-inventory.md`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const HF_ROUTER = "https://router.huggingface.co";
|
|
16
|
+
export declare const HF_TOKEN_SETTING = "HF_TOKEN";
|
|
17
|
+
/** Resolve the Hugging Face access token from node secrets or the environment. */
|
|
18
|
+
export declare function getHfToken(secrets: Record<string, string> | undefined): string;
|
|
19
|
+
/** A JSON value — exactly what `JSON.parse` can produce. */
|
|
20
|
+
export type HfJsonValue = string | number | boolean | null | HfJsonValue[] | HfJsonObject;
|
|
21
|
+
/** A JSON object: string keys, JSON values. */
|
|
22
|
+
export interface HfJsonObject {
|
|
23
|
+
[key: string]: HfJsonValue;
|
|
24
|
+
}
|
|
25
|
+
/** The object at `value`, or an empty object when the payload is not one. */
|
|
26
|
+
export declare function jsonObject(value: HfJsonValue | undefined): HfJsonObject;
|
|
27
|
+
/** The array at `value`, or an empty array when the payload is not one. */
|
|
28
|
+
export declare function jsonArray(value: HfJsonValue | undefined): HfJsonValue[];
|
|
29
|
+
/** `value` rendered as a string; a missing or null value becomes `""`. */
|
|
30
|
+
export declare function jsonString(value: HfJsonValue | undefined): string;
|
|
31
|
+
/** `value` read as a number; a missing or null value becomes `0`. */
|
|
32
|
+
export declare function jsonNumber(value: HfJsonValue | undefined): number;
|
|
33
|
+
/**
|
|
34
|
+
* The first element of an array payload, or the payload itself.
|
|
35
|
+
*
|
|
36
|
+
* Pipeline tasks return either the result or a one-element list holding it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function jsonFirst(value: HfJsonValue | undefined): HfJsonValue;
|
|
39
|
+
/** A media reference (image/audio/video) as it arrives on a node property. */
|
|
40
|
+
export interface MediaRef {
|
|
41
|
+
type?: string;
|
|
42
|
+
uri?: string;
|
|
43
|
+
data?: string | Uint8Array | null;
|
|
44
|
+
asset_id?: string | null;
|
|
45
|
+
metadata?: HfJsonObject | null;
|
|
46
|
+
}
|
|
47
|
+
/** True when a media ref actually carries bytes or a URI to fetch. */
|
|
48
|
+
export declare function isRefSet(ref: MediaRef | undefined | null): ref is MediaRef;
|
|
49
|
+
/**
|
|
50
|
+
* Minimal structural view of the ProcessingContext that a node's `process()`
|
|
51
|
+
* receives. We only need `resolveAssetBytes` here, which resolves NodeTool's
|
|
52
|
+
* own reference schemes (`asset://<id>`, `package://<pkg>/<path>`, storage
|
|
53
|
+
* URIs). Typed structurally to keep this package free of a `@nodetool-ai/runtime`
|
|
54
|
+
* dependency.
|
|
55
|
+
*/
|
|
56
|
+
export type AssetResolveContext = {
|
|
57
|
+
resolveAssetBytes?: (uri: string) => Promise<{
|
|
58
|
+
bytes: Uint8Array | null;
|
|
59
|
+
}>;
|
|
60
|
+
} | undefined;
|
|
61
|
+
/** Read the raw bytes behind an image/audio/video ref (data URI, base64, or URL). */
|
|
62
|
+
export declare function refToBytes(ref: MediaRef, context?: AssetResolveContext): Promise<Uint8Array>;
|
|
63
|
+
/** Read a media ref as a base64 string (no `data:` prefix), as the API expects. */
|
|
64
|
+
export declare function refToBase64(ref: MediaRef, context?: AssetResolveContext): Promise<string>;
|
|
65
|
+
/** An image ref as a node emits it: raw base64 bytes plus their mime type. */
|
|
66
|
+
export interface ImageRefOutput {
|
|
67
|
+
type: "image";
|
|
68
|
+
data: string;
|
|
69
|
+
content_type: string;
|
|
70
|
+
}
|
|
71
|
+
/** A video ref as a node emits it: raw base64 bytes, mime type and container. */
|
|
72
|
+
export interface VideoRefOutput {
|
|
73
|
+
type: "video";
|
|
74
|
+
data: string;
|
|
75
|
+
content_type: string;
|
|
76
|
+
format: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Wrap generated image bytes into an ImageRef-shaped output.
|
|
80
|
+
*
|
|
81
|
+
* `data` is RAW base64 (no `data:` prefix); the MIME type goes in
|
|
82
|
+
* `content_type`. Asset-saving (`decodeAssetBytes`) and provider forwarding
|
|
83
|
+
* (`asUint8Array`) decode `data` directly with `Buffer.from(data, "base64")`,
|
|
84
|
+
* so a `data:` prefix would corrupt the bytes.
|
|
85
|
+
*/
|
|
86
|
+
export declare function imageRefFromBytes(bytes: Uint8Array, mimeType?: string): ImageRefOutput;
|
|
87
|
+
/** Wrap generated video bytes into a VideoRef-shaped output (raw base64 `data`). */
|
|
88
|
+
export declare function videoRefFromBytes(bytes: Uint8Array, mimeType?: string): VideoRefOutput;
|
|
89
|
+
/** Wrap a base64 PNG mask (as returned by segmentation) into an ImageRef. */
|
|
90
|
+
export declare function imageRefFromBase64(base64: string, mimeType?: string): ImageRefOutput;
|
|
91
|
+
/** Provider parameters for a pipeline task. Entries with no value are dropped. */
|
|
92
|
+
export interface HfParameters {
|
|
93
|
+
[key: string]: HfJsonValue | undefined;
|
|
94
|
+
}
|
|
95
|
+
/** Body of a pipeline request: the task `inputs` plus provider parameters. */
|
|
96
|
+
export interface HfPipelineRequest {
|
|
97
|
+
inputs: HfJsonValue;
|
|
98
|
+
parameters?: HfParameters;
|
|
99
|
+
options?: HfParameters;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* POST a pipeline task that returns JSON (classification, NLP, embeddings…).
|
|
103
|
+
*
|
|
104
|
+
* The payload is returned as the JSON value it is — read it with `jsonObject`,
|
|
105
|
+
* `jsonArray`, `jsonString` and `jsonNumber` rather than claiming a shape.
|
|
106
|
+
*/
|
|
107
|
+
export declare function hfPipelineJson(token: string, model: string, body: HfPipelineRequest): Promise<HfJsonValue>;
|
|
108
|
+
/** Result of a binary pipeline task (image/video generation). */
|
|
109
|
+
export interface HfBinaryResult {
|
|
110
|
+
bytes: Uint8Array;
|
|
111
|
+
mimeType: string;
|
|
112
|
+
}
|
|
113
|
+
/** POST a pipeline task that returns raw media bytes (text-to-image/video…). */
|
|
114
|
+
export declare function hfPipelineBinary(token: string, model: string, body: HfPipelineRequest): Promise<HfBinaryResult>;
|
|
115
|
+
/** OpenAI-compatible chat completion via the HF router. */
|
|
116
|
+
export interface HfChatMessage {
|
|
117
|
+
role: string;
|
|
118
|
+
content: string;
|
|
119
|
+
}
|
|
120
|
+
/** Body of a chat-completion request. */
|
|
121
|
+
export interface HfChatRequest {
|
|
122
|
+
model: string;
|
|
123
|
+
messages: HfChatMessage[];
|
|
124
|
+
max_tokens?: number;
|
|
125
|
+
temperature?: number;
|
|
126
|
+
top_p?: number;
|
|
127
|
+
}
|
|
128
|
+
export interface HfChatUsage {
|
|
129
|
+
prompt_tokens?: number;
|
|
130
|
+
completion_tokens?: number;
|
|
131
|
+
total_tokens?: number;
|
|
132
|
+
}
|
|
133
|
+
export interface HfChatResult {
|
|
134
|
+
content: string;
|
|
135
|
+
usage?: HfChatUsage;
|
|
136
|
+
}
|
|
137
|
+
export declare function hfChatCompletion(token: string, body: HfChatRequest): Promise<HfChatResult>;
|
|
138
|
+
/** Build a `parameters` object, dropping null/undefined/empty entries. */
|
|
139
|
+
export declare function cleanParams(params: HfParameters): HfParameters;
|
|
140
|
+
//# sourceMappingURL=huggingface-base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"huggingface-base.d.ts","sourceRoot":"","sources":["../src/huggingface-base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,eAAO,MAAM,SAAS,kCAAkC,CAAC;AAEzD,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,kFAAkF;AAClF,wBAAgB,UAAU,CACxB,OAA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
3
|
+
*
|
|
4
|
+
* All task nodes talk to the unified router at https://router.huggingface.co:
|
|
5
|
+
* - Chat completion uses the OpenAI-compatible `/v1/chat/completions` route.
|
|
6
|
+
* - Every other ("pipeline") task posts to
|
|
7
|
+
* `/hf-inference/models/{model}` with a `{ inputs, parameters }` body.
|
|
8
|
+
*
|
|
9
|
+
* Binary-input tasks (image/audio in) send the media as a base64 string in
|
|
10
|
+
* `inputs`; binary-output tasks (image/video out) return raw bytes that we wrap
|
|
11
|
+
* into the matching media ref. The only non-`fetch` dependency is
|
|
12
|
+
* `fetchExternalMedia`, the shared egress policy a caller-supplied media uri
|
|
13
|
+
* goes through (`docs/url-egress-inventory.md`).
|
|
14
|
+
*/
|
|
15
|
+
import { fetchExternalMedia } from "@nodetool-ai/runtime";
|
|
16
|
+
export const HF_ROUTER = "https://router.huggingface.co";
|
|
17
|
+
export const HF_TOKEN_SETTING = "HF_TOKEN";
|
|
18
|
+
/** Resolve the Hugging Face access token from node secrets or the environment. */
|
|
19
|
+
export function getHfToken(secrets) {
|
|
20
|
+
const key = secrets?.HF_TOKEN ||
|
|
21
|
+
secrets?.HUGGINGFACE_API_KEY ||
|
|
22
|
+
process.env.HF_TOKEN ||
|
|
23
|
+
process.env.HUGGINGFACE_API_KEY ||
|
|
24
|
+
"";
|
|
25
|
+
if (!key) {
|
|
26
|
+
throw new Error("HF_TOKEN is not configured. Add a Hugging Face access token with " +
|
|
27
|
+
"'Inference Providers' permission in Settings → Models & Providers.");
|
|
28
|
+
}
|
|
29
|
+
return key;
|
|
30
|
+
}
|
|
31
|
+
function isJsonObject(value) {
|
|
32
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
function isJsonString(value) {
|
|
35
|
+
return typeof value === "string";
|
|
36
|
+
}
|
|
37
|
+
/** The object at `value`, or an empty object when the payload is not one. */
|
|
38
|
+
export function jsonObject(value) {
|
|
39
|
+
return isJsonObject(value) ? value : {};
|
|
40
|
+
}
|
|
41
|
+
/** The array at `value`, or an empty array when the payload is not one. */
|
|
42
|
+
export function jsonArray(value) {
|
|
43
|
+
return Array.isArray(value) ? value : [];
|
|
44
|
+
}
|
|
45
|
+
/** `value` rendered as a string; a missing or null value becomes `""`. */
|
|
46
|
+
export function jsonString(value) {
|
|
47
|
+
return value === null || value === undefined ? "" : String(value);
|
|
48
|
+
}
|
|
49
|
+
/** `value` read as a number; a missing or null value becomes `0`. */
|
|
50
|
+
export function jsonNumber(value) {
|
|
51
|
+
return value === null || value === undefined ? 0 : Number(value);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The first element of an array payload, or the payload itself.
|
|
55
|
+
*
|
|
56
|
+
* Pipeline tasks return either the result or a one-element list holding it.
|
|
57
|
+
*/
|
|
58
|
+
export function jsonFirst(value) {
|
|
59
|
+
return Array.isArray(value) ? (value[0] ?? null) : (value ?? null);
|
|
60
|
+
}
|
|
61
|
+
/** True when a media ref actually carries bytes or a URI to fetch. */
|
|
62
|
+
export function isRefSet(ref) {
|
|
63
|
+
return !!ref && (!!ref.uri || !!ref.data);
|
|
64
|
+
}
|
|
65
|
+
/** Read the raw bytes behind an image/audio/video ref (data URI, base64, or URL). */
|
|
66
|
+
export async function refToBytes(ref, context) {
|
|
67
|
+
const data = ref.data;
|
|
68
|
+
if (data instanceof Uint8Array) {
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
if (data != null && data.length > 0) {
|
|
72
|
+
const base64 = data.startsWith("data:")
|
|
73
|
+
? data.slice(data.indexOf(",") + 1)
|
|
74
|
+
: data;
|
|
75
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
76
|
+
}
|
|
77
|
+
const uri = ref.uri;
|
|
78
|
+
if (uri != null && uri.length > 0) {
|
|
79
|
+
if (uri.startsWith("data:")) {
|
|
80
|
+
const base64 = uri.slice(uri.indexOf(",") + 1);
|
|
81
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
82
|
+
}
|
|
83
|
+
const isHttp = uri.startsWith("http://") || uri.startsWith("https://");
|
|
84
|
+
// NodeTool reference schemes (asset://, package://) and storage URIs are
|
|
85
|
+
// not fetchable directly — resolve them through the ProcessingContext.
|
|
86
|
+
if (!isHttp && context?.resolveAssetBytes) {
|
|
87
|
+
const { bytes } = await context.resolveAssetBytes(uri);
|
|
88
|
+
if (bytes) {
|
|
89
|
+
return bytes;
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`Failed to resolve media from ${uri}`);
|
|
92
|
+
}
|
|
93
|
+
if (isHttp) {
|
|
94
|
+
// Caller-supplied media uri — the media-ref egress policy decides.
|
|
95
|
+
const res = await fetchExternalMedia(uri);
|
|
96
|
+
if (!res.ok) {
|
|
97
|
+
throw new Error(`Failed to fetch media from ${uri}: ${res.status}`);
|
|
98
|
+
}
|
|
99
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
throw new Error("Media input is empty — provide an image/audio/video.");
|
|
103
|
+
}
|
|
104
|
+
/** Read a media ref as a base64 string (no `data:` prefix), as the API expects. */
|
|
105
|
+
export async function refToBase64(ref, context) {
|
|
106
|
+
const bytes = await refToBytes(ref, context);
|
|
107
|
+
return Buffer.from(bytes).toString("base64");
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Wrap generated image bytes into an ImageRef-shaped output.
|
|
111
|
+
*
|
|
112
|
+
* `data` is RAW base64 (no `data:` prefix); the MIME type goes in
|
|
113
|
+
* `content_type`. Asset-saving (`decodeAssetBytes`) and provider forwarding
|
|
114
|
+
* (`asUint8Array`) decode `data` directly with `Buffer.from(data, "base64")`,
|
|
115
|
+
* so a `data:` prefix would corrupt the bytes.
|
|
116
|
+
*/
|
|
117
|
+
export function imageRefFromBytes(bytes, mimeType = "image/png") {
|
|
118
|
+
return {
|
|
119
|
+
type: "image",
|
|
120
|
+
data: Buffer.from(bytes).toString("base64"),
|
|
121
|
+
content_type: mimeType
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** Wrap generated video bytes into a VideoRef-shaped output (raw base64 `data`). */
|
|
125
|
+
export function videoRefFromBytes(bytes, mimeType = "video/mp4") {
|
|
126
|
+
return {
|
|
127
|
+
type: "video",
|
|
128
|
+
data: Buffer.from(bytes).toString("base64"),
|
|
129
|
+
content_type: mimeType,
|
|
130
|
+
format: mimeType.split("/")[1] ?? "mp4"
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** Wrap a base64 PNG mask (as returned by segmentation) into an ImageRef. */
|
|
134
|
+
export function imageRefFromBase64(base64, mimeType = "image/png") {
|
|
135
|
+
const clean = base64.startsWith("data:")
|
|
136
|
+
? base64.slice(base64.indexOf(",") + 1)
|
|
137
|
+
: base64;
|
|
138
|
+
return { type: "image", data: clean, content_type: mimeType };
|
|
139
|
+
}
|
|
140
|
+
function authHeaders(token) {
|
|
141
|
+
return { Authorization: `Bearer ${token}` };
|
|
142
|
+
}
|
|
143
|
+
/** Extract a useful error message from a failed HF response. */
|
|
144
|
+
async function hfError(res, model) {
|
|
145
|
+
let detail = "";
|
|
146
|
+
try {
|
|
147
|
+
detail = await res.text();
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
/* response body already consumed or unavailable */
|
|
151
|
+
}
|
|
152
|
+
return new Error(`Hugging Face inference failed for "${model}" (${res.status}): ${detail || res.statusText}`);
|
|
153
|
+
}
|
|
154
|
+
/** Read a response body as JSON. */
|
|
155
|
+
async function readJson(res) {
|
|
156
|
+
// SAFETY: `Response.json()` resolves to the value `JSON.parse` produced, and
|
|
157
|
+
// that value domain is exactly HfJsonValue — string, number, boolean, null,
|
|
158
|
+
// array, or object of those. No shape beyond that is claimed here.
|
|
159
|
+
return (await res.json());
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* POST a pipeline task that returns JSON (classification, NLP, embeddings…).
|
|
163
|
+
*
|
|
164
|
+
* The payload is returned as the JSON value it is — read it with `jsonObject`,
|
|
165
|
+
* `jsonArray`, `jsonString` and `jsonNumber` rather than claiming a shape.
|
|
166
|
+
*/
|
|
167
|
+
export async function hfPipelineJson(token, model, body) {
|
|
168
|
+
const res = await fetch(`${HF_ROUTER}/hf-inference/models/${model}`, {
|
|
169
|
+
method: "POST",
|
|
170
|
+
headers: { ...authHeaders(token), "Content-Type": "application/json" },
|
|
171
|
+
body: JSON.stringify(body)
|
|
172
|
+
});
|
|
173
|
+
if (!res.ok) {
|
|
174
|
+
throw await hfError(res, model);
|
|
175
|
+
}
|
|
176
|
+
return readJson(res);
|
|
177
|
+
}
|
|
178
|
+
/** POST a pipeline task that returns raw media bytes (text-to-image/video…). */
|
|
179
|
+
export async function hfPipelineBinary(token, model, body) {
|
|
180
|
+
const res = await fetch(`${HF_ROUTER}/hf-inference/models/${model}`, {
|
|
181
|
+
method: "POST",
|
|
182
|
+
headers: {
|
|
183
|
+
...authHeaders(token),
|
|
184
|
+
"Content-Type": "application/json",
|
|
185
|
+
Accept: "image/png, video/mp4, application/octet-stream"
|
|
186
|
+
},
|
|
187
|
+
body: JSON.stringify(body)
|
|
188
|
+
});
|
|
189
|
+
if (!res.ok) {
|
|
190
|
+
throw await hfError(res, model);
|
|
191
|
+
}
|
|
192
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
193
|
+
// Some providers return a JSON envelope with a base64 payload instead of raw
|
|
194
|
+
// bytes. Handle both so the caller always gets decoded media.
|
|
195
|
+
if (contentType.includes("application/json")) {
|
|
196
|
+
const json = await readJson(res);
|
|
197
|
+
const base64 = extractBase64(json);
|
|
198
|
+
if (!base64) {
|
|
199
|
+
throw new Error(`Hugging Face returned JSON without media for "${model}": ${JSON.stringify(json).slice(0, 200)}`);
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
bytes: new Uint8Array(Buffer.from(base64, "base64")),
|
|
203
|
+
mimeType: guessMimeFromJson(json) ?? "image/png"
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
bytes: new Uint8Array(await res.arrayBuffer()),
|
|
208
|
+
mimeType: contentType || "application/octet-stream"
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function extractBase64(json) {
|
|
212
|
+
if (isJsonString(json))
|
|
213
|
+
return json;
|
|
214
|
+
if (Array.isArray(json) && json.length > 0) {
|
|
215
|
+
return extractBase64(json[0] ?? null);
|
|
216
|
+
}
|
|
217
|
+
if (isJsonObject(json)) {
|
|
218
|
+
for (const key of [
|
|
219
|
+
"image",
|
|
220
|
+
"video",
|
|
221
|
+
"audio",
|
|
222
|
+
"data",
|
|
223
|
+
"b64_json",
|
|
224
|
+
"generated_image"
|
|
225
|
+
]) {
|
|
226
|
+
const value = json[key];
|
|
227
|
+
if (isJsonString(value))
|
|
228
|
+
return value.replace(/^data:[^,]+,/, "");
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
function guessMimeFromJson(json) {
|
|
234
|
+
if (isJsonObject(json)) {
|
|
235
|
+
if (isJsonString(json["video"]))
|
|
236
|
+
return "video/mp4";
|
|
237
|
+
if (isJsonString(json["audio"]))
|
|
238
|
+
return "audio/flac";
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
function optionalNumber(value) {
|
|
243
|
+
return value === null || value === undefined ? undefined : Number(value);
|
|
244
|
+
}
|
|
245
|
+
export async function hfChatCompletion(token, body) {
|
|
246
|
+
const res = await fetch(`${HF_ROUTER}/v1/chat/completions`, {
|
|
247
|
+
method: "POST",
|
|
248
|
+
headers: { ...authHeaders(token), "Content-Type": "application/json" },
|
|
249
|
+
body: JSON.stringify(body)
|
|
250
|
+
});
|
|
251
|
+
if (!res.ok) {
|
|
252
|
+
throw await hfError(res, body.model || "chat");
|
|
253
|
+
}
|
|
254
|
+
const json = jsonObject(await readJson(res));
|
|
255
|
+
const choice = jsonObject(jsonArray(json["choices"])[0]);
|
|
256
|
+
const result = {
|
|
257
|
+
content: jsonString(jsonObject(choice["message"])["content"])
|
|
258
|
+
};
|
|
259
|
+
const usage = json["usage"];
|
|
260
|
+
if (isJsonObject(usage)) {
|
|
261
|
+
result.usage = {
|
|
262
|
+
prompt_tokens: optionalNumber(usage["prompt_tokens"]),
|
|
263
|
+
completion_tokens: optionalNumber(usage["completion_tokens"]),
|
|
264
|
+
total_tokens: optionalNumber(usage["total_tokens"])
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
/** Build a `parameters` object, dropping null/undefined/empty entries. */
|
|
270
|
+
export function cleanParams(params) {
|
|
271
|
+
const out = {};
|
|
272
|
+
for (const [key, value] of Object.entries(params)) {
|
|
273
|
+
if (value !== null && value !== undefined && value !== "") {
|
|
274
|
+
out[key] = value;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return out;
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=huggingface-base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"huggingface-base.js","sourceRoot":"","sources":["../src/huggingface-base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,SAAS,GAAG,+BAA+B,CAAC;AAEzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAE3C,kFAAkF;AAClF,MAAM,UAAU,UAAU,CACxB,OAA2C;IAE3C,MAAM,GAAG,GACP,OAAO,EAAE,QAAQ;QACjB,OAAO,EAAE,mBAAmB;QAC5B,OAAO,CAAC,GAAG,CAAC,QAAQ;QACpB,OAAO,CAAC,GAAG,CAAC,mBAAmB;QAC/B,EAAE,CAAC;IACL,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,mEAAmE;YACjE,oEAAoE,CACvE,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;A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M,MAAM,GAAiB;QAC3B,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;KAC9D,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,CAAC,KAAK,GAAG;YACb,aAAa,EAAE,cAAc,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACrD,iBAAiB,EAAE,cAAc,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAC7D,YAAY,EAAE,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;SACpD,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC9C,MAAM,GAAG,GAAiB,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;YAC1D,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { NodeClass } from "@nodetool-ai/node-sdk";
|
|
2
|
+
export * from "./huggingface-base.js";
|
|
3
|
+
export * from "./nodes/text.js";
|
|
4
|
+
export * from "./nodes/image.js";
|
|
5
|
+
export * from "./nodes/audio.js";
|
|
6
|
+
export * from "./nodes/video.js";
|
|
7
|
+
/**
|
|
8
|
+
* Every Hugging Face Inference Providers node, across all task modalities.
|
|
9
|
+
*
|
|
10
|
+
* Nodes whose primary output is displayable (generated media, or the text a
|
|
11
|
+
* generator/captioner/transcriber returns) render a content card; the ones
|
|
12
|
+
* that return scores or bounding boxes keep the generic body.
|
|
13
|
+
*/
|
|
14
|
+
export declare const HUGGINGFACE_NODES: readonly NodeClass[];
|
|
15
|
+
export declare function registerHuggingFaceNodes(registry: {
|
|
16
|
+
register: (nodeClass: NodeClass) => void;
|
|
17
|
+
}): void;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAMvD,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AAEjC;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAAS,SAAS,EAKhD,CAAC;AAEH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE;IACjD,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;CAC1C,GAAG,IAAI,CAIP"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { tagContentCardBodies } from "@nodetool-ai/node-sdk";
|
|
2
|
+
import { HUGGINGFACE_TEXT_NODES } from "./nodes/text.js";
|
|
3
|
+
import { HUGGINGFACE_IMAGE_NODES } from "./nodes/image.js";
|
|
4
|
+
import { HUGGINGFACE_AUDIO_NODES } from "./nodes/audio.js";
|
|
5
|
+
import { HUGGINGFACE_VIDEO_NODES } from "./nodes/video.js";
|
|
6
|
+
export * from "./huggingface-base.js";
|
|
7
|
+
export * from "./nodes/text.js";
|
|
8
|
+
export * from "./nodes/image.js";
|
|
9
|
+
export * from "./nodes/audio.js";
|
|
10
|
+
export * from "./nodes/video.js";
|
|
11
|
+
/**
|
|
12
|
+
* Every Hugging Face Inference Providers node, across all task modalities.
|
|
13
|
+
*
|
|
14
|
+
* Nodes whose primary output is displayable (generated media, or the text a
|
|
15
|
+
* generator/captioner/transcriber returns) render a content card; the ones
|
|
16
|
+
* that return scores or bounding boxes keep the generic body.
|
|
17
|
+
*/
|
|
18
|
+
export const HUGGINGFACE_NODES = tagContentCardBodies([
|
|
19
|
+
...HUGGINGFACE_TEXT_NODES,
|
|
20
|
+
...HUGGINGFACE_IMAGE_NODES,
|
|
21
|
+
...HUGGINGFACE_AUDIO_NODES,
|
|
22
|
+
...HUGGINGFACE_VIDEO_NODES
|
|
23
|
+
]);
|
|
24
|
+
export function registerHuggingFaceNodes(registry) {
|
|
25
|
+
for (const nodeClass of HUGGINGFACE_NODES) {
|
|
26
|
+
registry.register(nodeClass);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AAEjC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAyB,oBAAoB,CAAC;IAC1E,GAAG,sBAAsB;IACzB,GAAG,uBAAuB;IAC1B,GAAG,uBAAuB;IAC1B,GAAG,uBAAuB;CAC3B,CAAC,CAAC;AAEH,MAAM,UAAU,wBAAwB,CAAC,QAExC;IACC,KAAK,MAAM,SAAS,IAAI,iBAAiB,EAAE,CAAC;QAC1C,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BaseNode } from "@nodetool-ai/node-sdk";
|
|
2
|
+
import type { NodeClass } from "@nodetool-ai/node-sdk";
|
|
3
|
+
import { type HfJsonValue, type MediaRef } from "../huggingface-base.js";
|
|
4
|
+
/** Output handles AutomaticSpeechRecognitionNode.process() emits. */
|
|
5
|
+
type AutomaticSpeechRecognitionNodeOutputs = {
|
|
6
|
+
output: string;
|
|
7
|
+
chunks: HfJsonValue[];
|
|
8
|
+
};
|
|
9
|
+
export declare class AutomaticSpeechRecognitionNode extends BaseNode {
|
|
10
|
+
static readonly nodeType = "huggingface.AutomaticSpeechRecognition";
|
|
11
|
+
static readonly title = "Automatic Speech Recognition";
|
|
12
|
+
static readonly description: string;
|
|
13
|
+
static readonly inputFields: string[];
|
|
14
|
+
static readonly requiredSettings: string[];
|
|
15
|
+
static readonly metadataOutputTypes: {
|
|
16
|
+
output: string;
|
|
17
|
+
chunks: string;
|
|
18
|
+
};
|
|
19
|
+
model: string;
|
|
20
|
+
audio: MediaRef;
|
|
21
|
+
return_timestamps: boolean;
|
|
22
|
+
process(context?: Parameters<BaseNode["process"]>[0]): Promise<AutomaticSpeechRecognitionNodeOutputs>;
|
|
23
|
+
}
|
|
24
|
+
/** Output handles AudioClassificationNode.process() emits. */
|
|
25
|
+
type AudioClassificationNodeOutputs = {
|
|
26
|
+
output: string;
|
|
27
|
+
scores: HfJsonValue[];
|
|
28
|
+
};
|
|
29
|
+
export declare class AudioClassificationNode extends BaseNode {
|
|
30
|
+
static readonly nodeType = "huggingface.AudioClassification";
|
|
31
|
+
static readonly title = "Audio Classification";
|
|
32
|
+
static readonly description: string;
|
|
33
|
+
static readonly inputFields: string[];
|
|
34
|
+
static readonly requiredSettings: string[];
|
|
35
|
+
static readonly metadataOutputTypes: {
|
|
36
|
+
output: string;
|
|
37
|
+
scores: string;
|
|
38
|
+
};
|
|
39
|
+
model: string;
|
|
40
|
+
audio: MediaRef;
|
|
41
|
+
top_k: number;
|
|
42
|
+
process(context?: Parameters<BaseNode["process"]>[0]): Promise<AudioClassificationNodeOutputs>;
|
|
43
|
+
}
|
|
44
|
+
export declare const HUGGINGFACE_AUDIO_NODES: readonly NodeClass[];
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=audio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../src/nodes/audio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAOL,KAAK,WAAW,EAChB,KAAK,QAAQ,EACd,MAAM,wBAAwB,CAAC;AAwBhC,qEAAqE;AACrE,KAAK,qCAAqC,GAAG;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB,CAAC;AAEF,qBAAa,8BAA+B,SAAQ,QAAQ;IAC1D,MAAM,CAAC,QAAQ,CAAC,QAAQ,4CAA4C;IACpE,MAAM,CAAC,QAAQ,CAAC,KAAK,kCAAkC;IACvD,MAAM,CAAC,QAAQ,CAAC,WAAW,SAME;IAC7B,MAAM,CAAC,QAAQ,CAAC,WAAW,WAAa;IACxC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,WAAgB;IAChD,MAAM,CAAC,QAAQ,CAAC,mBAAmB;QAAK,MAAM;QAAS,MAAM;MAAW;IAQhE,KAAK,EAAE,MAAM,CAAC;IAQd,KAAK,EAAE,QAAQ,CAAC;IAQhB,iBAAiB,EAAE,OAAO,CAAC;IAE7B,OAAO,CACX,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