@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
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BaseNode, prop } from "@nodetool-ai/node-sdk";
|
|
8
|
+
import { cleanParams, getHfToken, hfChatCompletion, hfPipelineJson, jsonArray, jsonFirst, jsonNumber, jsonObject, jsonString } from "../huggingface-base.js";
|
|
9
|
+
/** The embedding request body, with `normalize` sent only when it is on. */
|
|
10
|
+
function embedBody(inputs, normalize) {
|
|
11
|
+
const body = { inputs };
|
|
12
|
+
if (normalize) {
|
|
13
|
+
body.normalize = true;
|
|
14
|
+
}
|
|
15
|
+
return body;
|
|
16
|
+
}
|
|
17
|
+
/** The NER request body; `"none"` means send no aggregation strategy at all. */
|
|
18
|
+
function nerBody(inputs, strategy) {
|
|
19
|
+
const body = { inputs };
|
|
20
|
+
if (strategy !== "none") {
|
|
21
|
+
body.parameters = { aggregation_strategy: strategy };
|
|
22
|
+
}
|
|
23
|
+
return body;
|
|
24
|
+
}
|
|
25
|
+
export class ChatCompletionNode extends BaseNode {
|
|
26
|
+
static nodeType = "huggingface.ChatCompletion";
|
|
27
|
+
static title = "Chat Completion";
|
|
28
|
+
static description = "Generate a chat response from a conversational LLM via Hugging Face Inference Providers.\n" +
|
|
29
|
+
"text, chat, llm, completion, conversation, huggingface\n\n" +
|
|
30
|
+
"Use cases:\n" +
|
|
31
|
+
"- Answer questions with an open LLM\n" +
|
|
32
|
+
"- Build conversational assistants\n" +
|
|
33
|
+
"- Generate text with system instructions";
|
|
34
|
+
static inlineFields = ["prompt"];
|
|
35
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
36
|
+
static metadataOutputTypes = { output: "str" };
|
|
37
|
+
async process() {
|
|
38
|
+
const token = getHfToken(this._secrets);
|
|
39
|
+
const prompt = String(this.prompt ?? "");
|
|
40
|
+
if (!prompt)
|
|
41
|
+
throw new Error("Prompt cannot be empty");
|
|
42
|
+
const messages = [];
|
|
43
|
+
const system = String(this.system ?? "");
|
|
44
|
+
if (system)
|
|
45
|
+
messages.push({ role: "system", content: system });
|
|
46
|
+
messages.push({ role: "user", content: prompt });
|
|
47
|
+
const result = await hfChatCompletion(token, {
|
|
48
|
+
model: String(this.model ?? "meta-llama/Llama-3.1-8B-Instruct"),
|
|
49
|
+
messages,
|
|
50
|
+
max_tokens: Number(this.max_tokens ?? 512),
|
|
51
|
+
temperature: Number(this.temperature ?? 0.7),
|
|
52
|
+
top_p: Number(this.top_p ?? 1.0)
|
|
53
|
+
});
|
|
54
|
+
return { output: result.content };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__decorate([
|
|
58
|
+
prop({
|
|
59
|
+
type: "str",
|
|
60
|
+
default: "meta-llama/Llama-3.1-8B-Instruct",
|
|
61
|
+
title: "Model",
|
|
62
|
+
description: "Conversational model repo id (e.g. meta-llama/Llama-3.1-8B-Instruct, Qwen/Qwen2.5-7B-Instruct, openai/gpt-oss-120b)."
|
|
63
|
+
})
|
|
64
|
+
], ChatCompletionNode.prototype, "model", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
prop({
|
|
67
|
+
type: "str",
|
|
68
|
+
default: "",
|
|
69
|
+
title: "System",
|
|
70
|
+
description: "Optional system prompt setting the assistant's behavior."
|
|
71
|
+
})
|
|
72
|
+
], ChatCompletionNode.prototype, "system", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
prop({
|
|
75
|
+
type: "str",
|
|
76
|
+
default: "Hello!",
|
|
77
|
+
title: "Prompt",
|
|
78
|
+
description: "The user message to send to the model."
|
|
79
|
+
})
|
|
80
|
+
], ChatCompletionNode.prototype, "prompt", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
prop({
|
|
83
|
+
type: "int",
|
|
84
|
+
default: 512,
|
|
85
|
+
title: "Max Tokens",
|
|
86
|
+
description: "Maximum number of tokens to generate.",
|
|
87
|
+
min: 1,
|
|
88
|
+
max: 32768
|
|
89
|
+
})
|
|
90
|
+
], ChatCompletionNode.prototype, "max_tokens", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
prop({
|
|
93
|
+
type: "float",
|
|
94
|
+
default: 0.7,
|
|
95
|
+
title: "Temperature",
|
|
96
|
+
description: "Sampling temperature (0-2). Higher is more random.",
|
|
97
|
+
min: 0,
|
|
98
|
+
max: 2
|
|
99
|
+
})
|
|
100
|
+
], ChatCompletionNode.prototype, "temperature", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
prop({
|
|
103
|
+
type: "float",
|
|
104
|
+
default: 1.0,
|
|
105
|
+
title: "Top P",
|
|
106
|
+
description: "Nucleus sampling probability mass (0-1).",
|
|
107
|
+
min: 0,
|
|
108
|
+
max: 1
|
|
109
|
+
})
|
|
110
|
+
], ChatCompletionNode.prototype, "top_p", void 0);
|
|
111
|
+
export class TextGenerationNode extends BaseNode {
|
|
112
|
+
static nodeType = "huggingface.TextGeneration";
|
|
113
|
+
static title = "Text Generation";
|
|
114
|
+
static description = "Continue / complete text from a prompt using a Hugging Face text-generation model.\n" +
|
|
115
|
+
"text, generation, completion, llm, huggingface\n\n" +
|
|
116
|
+
"Use cases:\n" +
|
|
117
|
+
"- Continue a piece of writing\n" +
|
|
118
|
+
"- Generate creative text\n" +
|
|
119
|
+
"- Prototype with open models";
|
|
120
|
+
static inlineFields = ["prompt"];
|
|
121
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
122
|
+
static metadataOutputTypes = { output: "str" };
|
|
123
|
+
async process() {
|
|
124
|
+
const token = getHfToken(this._secrets);
|
|
125
|
+
const prompt = String(this.prompt ?? "");
|
|
126
|
+
if (!prompt)
|
|
127
|
+
throw new Error("Prompt cannot be empty");
|
|
128
|
+
const result = await hfPipelineJson(token, String(this.model ?? "HuggingFaceH4/zephyr-7b-beta"), {
|
|
129
|
+
inputs: prompt,
|
|
130
|
+
parameters: cleanParams({
|
|
131
|
+
max_new_tokens: Number(this.max_new_tokens ?? 256),
|
|
132
|
+
temperature: Number(this.temperature ?? 0.7),
|
|
133
|
+
return_full_text: Boolean(this.return_full_text ?? false)
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
const first = jsonObject(jsonFirst(result));
|
|
137
|
+
return { output: jsonString(first["generated_text"]) };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
__decorate([
|
|
141
|
+
prop({
|
|
142
|
+
type: "str",
|
|
143
|
+
default: "HuggingFaceH4/zephyr-7b-beta",
|
|
144
|
+
title: "Model",
|
|
145
|
+
description: "Text-generation model repo id."
|
|
146
|
+
})
|
|
147
|
+
], TextGenerationNode.prototype, "model", void 0);
|
|
148
|
+
__decorate([
|
|
149
|
+
prop({
|
|
150
|
+
type: "str",
|
|
151
|
+
default: "Once upon a time",
|
|
152
|
+
title: "Prompt",
|
|
153
|
+
description: "The text prompt to continue."
|
|
154
|
+
})
|
|
155
|
+
], TextGenerationNode.prototype, "prompt", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
prop({
|
|
158
|
+
type: "int",
|
|
159
|
+
default: 256,
|
|
160
|
+
title: "Max New Tokens",
|
|
161
|
+
description: "Maximum number of new tokens to generate.",
|
|
162
|
+
min: 1,
|
|
163
|
+
max: 8192
|
|
164
|
+
})
|
|
165
|
+
], TextGenerationNode.prototype, "max_new_tokens", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
prop({
|
|
168
|
+
type: "float",
|
|
169
|
+
default: 0.7,
|
|
170
|
+
title: "Temperature",
|
|
171
|
+
description: "Sampling temperature.",
|
|
172
|
+
min: 0,
|
|
173
|
+
max: 2
|
|
174
|
+
})
|
|
175
|
+
], TextGenerationNode.prototype, "temperature", void 0);
|
|
176
|
+
__decorate([
|
|
177
|
+
prop({
|
|
178
|
+
type: "bool",
|
|
179
|
+
default: false,
|
|
180
|
+
title: "Return Full Text",
|
|
181
|
+
description: "Include the prompt in the returned text."
|
|
182
|
+
})
|
|
183
|
+
], TextGenerationNode.prototype, "return_full_text", void 0);
|
|
184
|
+
export class SummarizationNode extends BaseNode {
|
|
185
|
+
static nodeType = "huggingface.Summarization";
|
|
186
|
+
static title = "Summarization";
|
|
187
|
+
static description = "Produce a shorter version of a document while preserving key information.\n" +
|
|
188
|
+
"text, summarization, summary, nlp, huggingface\n\n" +
|
|
189
|
+
"Use cases:\n" +
|
|
190
|
+
"- Summarize articles or reports\n" +
|
|
191
|
+
"- Create TL;DRs\n" +
|
|
192
|
+
"- Condense meeting notes";
|
|
193
|
+
static inlineFields = ["inputs"];
|
|
194
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
195
|
+
static metadataOutputTypes = { output: "str" };
|
|
196
|
+
async process() {
|
|
197
|
+
const token = getHfToken(this._secrets);
|
|
198
|
+
const text = String(this.inputs ?? "");
|
|
199
|
+
if (!text)
|
|
200
|
+
throw new Error("Text cannot be empty");
|
|
201
|
+
const maxLength = Number(this.max_length ?? 0);
|
|
202
|
+
const minLength = Number(this.min_length ?? 0);
|
|
203
|
+
const result = await hfPipelineJson(token, String(this.model ?? "facebook/bart-large-cnn"), {
|
|
204
|
+
inputs: text,
|
|
205
|
+
parameters: cleanParams({
|
|
206
|
+
max_length: maxLength > 0 ? maxLength : undefined,
|
|
207
|
+
min_length: minLength > 0 ? minLength : undefined
|
|
208
|
+
})
|
|
209
|
+
});
|
|
210
|
+
const first = jsonObject(jsonFirst(result));
|
|
211
|
+
return { output: jsonString(first["summary_text"]) };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
__decorate([
|
|
215
|
+
prop({
|
|
216
|
+
type: "str",
|
|
217
|
+
default: "facebook/bart-large-cnn",
|
|
218
|
+
title: "Model",
|
|
219
|
+
description: "Summarization model repo id."
|
|
220
|
+
})
|
|
221
|
+
], SummarizationNode.prototype, "model", void 0);
|
|
222
|
+
__decorate([
|
|
223
|
+
prop({
|
|
224
|
+
type: "str",
|
|
225
|
+
default: "",
|
|
226
|
+
title: "Text",
|
|
227
|
+
description: "The text to summarize."
|
|
228
|
+
})
|
|
229
|
+
], SummarizationNode.prototype, "inputs", void 0);
|
|
230
|
+
__decorate([
|
|
231
|
+
prop({
|
|
232
|
+
type: "int",
|
|
233
|
+
default: 0,
|
|
234
|
+
title: "Max Length",
|
|
235
|
+
description: "Maximum length of the summary in tokens (0 = model default).",
|
|
236
|
+
min: 0,
|
|
237
|
+
max: 2048
|
|
238
|
+
})
|
|
239
|
+
], SummarizationNode.prototype, "max_length", void 0);
|
|
240
|
+
__decorate([
|
|
241
|
+
prop({
|
|
242
|
+
type: "int",
|
|
243
|
+
default: 0,
|
|
244
|
+
title: "Min Length",
|
|
245
|
+
description: "Minimum length of the summary in tokens (0 = model default).",
|
|
246
|
+
min: 0,
|
|
247
|
+
max: 2048
|
|
248
|
+
})
|
|
249
|
+
], SummarizationNode.prototype, "min_length", void 0);
|
|
250
|
+
export class TranslationNode extends BaseNode {
|
|
251
|
+
static nodeType = "huggingface.Translation";
|
|
252
|
+
static title = "Translation";
|
|
253
|
+
static description = "Translate text from one language to another.\n" +
|
|
254
|
+
"text, translation, language, nlp, huggingface\n\n" +
|
|
255
|
+
"Use cases:\n" +
|
|
256
|
+
"- Translate documents\n" +
|
|
257
|
+
"- Localize content\n" +
|
|
258
|
+
"- Build multilingual apps";
|
|
259
|
+
static inlineFields = ["inputs"];
|
|
260
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
261
|
+
static metadataOutputTypes = { output: "str" };
|
|
262
|
+
async process() {
|
|
263
|
+
const token = getHfToken(this._secrets);
|
|
264
|
+
const text = String(this.inputs ?? "");
|
|
265
|
+
if (!text)
|
|
266
|
+
throw new Error("Text cannot be empty");
|
|
267
|
+
const result = await hfPipelineJson(token, String(this.model ?? "facebook/nllb-200-distilled-600M"), {
|
|
268
|
+
inputs: text,
|
|
269
|
+
parameters: cleanParams({
|
|
270
|
+
src_lang: String(this.src_lang ?? ""),
|
|
271
|
+
tgt_lang: String(this.tgt_lang ?? "")
|
|
272
|
+
})
|
|
273
|
+
});
|
|
274
|
+
const first = jsonObject(jsonFirst(result));
|
|
275
|
+
return { output: jsonString(first["translation_text"]) };
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
__decorate([
|
|
279
|
+
prop({
|
|
280
|
+
type: "str",
|
|
281
|
+
default: "facebook/nllb-200-distilled-600M",
|
|
282
|
+
title: "Model",
|
|
283
|
+
description: "Translation model repo id (e.g. facebook/nllb-200-distilled-600M, Helsinki-NLP/opus-mt-en-fr)."
|
|
284
|
+
})
|
|
285
|
+
], TranslationNode.prototype, "model", void 0);
|
|
286
|
+
__decorate([
|
|
287
|
+
prop({
|
|
288
|
+
type: "str",
|
|
289
|
+
default: "",
|
|
290
|
+
title: "Text",
|
|
291
|
+
description: "The text to translate."
|
|
292
|
+
})
|
|
293
|
+
], TranslationNode.prototype, "inputs", void 0);
|
|
294
|
+
__decorate([
|
|
295
|
+
prop({
|
|
296
|
+
type: "str",
|
|
297
|
+
default: "",
|
|
298
|
+
title: "Source Language",
|
|
299
|
+
description: "Optional source language code for multilingual models (e.g. eng_Latn)."
|
|
300
|
+
})
|
|
301
|
+
], TranslationNode.prototype, "src_lang", void 0);
|
|
302
|
+
__decorate([
|
|
303
|
+
prop({
|
|
304
|
+
type: "str",
|
|
305
|
+
default: "",
|
|
306
|
+
title: "Target Language",
|
|
307
|
+
description: "Optional target language code for multilingual models (e.g. fra_Latn)."
|
|
308
|
+
})
|
|
309
|
+
], TranslationNode.prototype, "tgt_lang", void 0);
|
|
310
|
+
export class FillMaskNode extends BaseNode {
|
|
311
|
+
static nodeType = "huggingface.FillMask";
|
|
312
|
+
static title = "Fill Mask";
|
|
313
|
+
static description = "Predict the masked token in a sequence.\n" +
|
|
314
|
+
"text, fill-mask, masked-language-model, nlp, huggingface\n\n" +
|
|
315
|
+
"Use cases:\n" +
|
|
316
|
+
"- Complete sentences with a missing word\n" +
|
|
317
|
+
"- Probe what a language model knows\n" +
|
|
318
|
+
"- Data augmentation";
|
|
319
|
+
static inlineFields = ["inputs"];
|
|
320
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
321
|
+
static metadataOutputTypes = { output: "str", predictions: "list" };
|
|
322
|
+
async process() {
|
|
323
|
+
const token = getHfToken(this._secrets);
|
|
324
|
+
const text = String(this.inputs ?? "");
|
|
325
|
+
if (!text)
|
|
326
|
+
throw new Error("Text cannot be empty");
|
|
327
|
+
const result = await hfPipelineJson(token, String(this.model ?? "bert-base-uncased"), { inputs: text });
|
|
328
|
+
const predictions = jsonArray(result);
|
|
329
|
+
return {
|
|
330
|
+
output: jsonString(jsonObject(predictions[0])["token_str"]).trim(),
|
|
331
|
+
predictions
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
__decorate([
|
|
336
|
+
prop({
|
|
337
|
+
type: "str",
|
|
338
|
+
default: "bert-base-uncased",
|
|
339
|
+
title: "Model",
|
|
340
|
+
description: "Fill-mask model repo id."
|
|
341
|
+
})
|
|
342
|
+
], FillMaskNode.prototype, "model", void 0);
|
|
343
|
+
__decorate([
|
|
344
|
+
prop({
|
|
345
|
+
type: "str",
|
|
346
|
+
default: "The capital of France is [MASK].",
|
|
347
|
+
title: "Text",
|
|
348
|
+
description: "Text containing a mask token (e.g. [MASK] for BERT, <mask> for RoBERTa)."
|
|
349
|
+
})
|
|
350
|
+
], FillMaskNode.prototype, "inputs", void 0);
|
|
351
|
+
export class QuestionAnsweringNode extends BaseNode {
|
|
352
|
+
static nodeType = "huggingface.QuestionAnswering";
|
|
353
|
+
static title = "Question Answering";
|
|
354
|
+
static description = "Retrieve the answer to a question from a given context passage.\n" +
|
|
355
|
+
"text, question-answering, qa, extractive, nlp, huggingface\n\n" +
|
|
356
|
+
"Use cases:\n" +
|
|
357
|
+
"- Answer questions over a document\n" +
|
|
358
|
+
"- Extract facts from text\n" +
|
|
359
|
+
"- Build search-over-document features";
|
|
360
|
+
static inlineFields = ["question"];
|
|
361
|
+
static inputFields = ["context"];
|
|
362
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
363
|
+
static metadataOutputTypes = { output: "str", score: "float" };
|
|
364
|
+
async process() {
|
|
365
|
+
const token = getHfToken(this._secrets);
|
|
366
|
+
const question = String(this.question ?? "");
|
|
367
|
+
const context = String(this.context ?? "");
|
|
368
|
+
if (!question)
|
|
369
|
+
throw new Error("Question cannot be empty");
|
|
370
|
+
if (!context)
|
|
371
|
+
throw new Error("Context cannot be empty");
|
|
372
|
+
const result = jsonObject(await hfPipelineJson(token, String(this.model ?? "deepset/roberta-base-squad2"), { inputs: { question, context } }));
|
|
373
|
+
return {
|
|
374
|
+
output: jsonString(result["answer"]),
|
|
375
|
+
score: jsonNumber(result["score"])
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
__decorate([
|
|
380
|
+
prop({
|
|
381
|
+
type: "str",
|
|
382
|
+
default: "deepset/roberta-base-squad2",
|
|
383
|
+
title: "Model",
|
|
384
|
+
description: "Question-answering model repo id."
|
|
385
|
+
})
|
|
386
|
+
], QuestionAnsweringNode.prototype, "model", void 0);
|
|
387
|
+
__decorate([
|
|
388
|
+
prop({
|
|
389
|
+
type: "str",
|
|
390
|
+
default: "",
|
|
391
|
+
title: "Question",
|
|
392
|
+
description: "The question to answer."
|
|
393
|
+
})
|
|
394
|
+
], QuestionAnsweringNode.prototype, "question", void 0);
|
|
395
|
+
__decorate([
|
|
396
|
+
prop({
|
|
397
|
+
type: "str",
|
|
398
|
+
default: "",
|
|
399
|
+
title: "Context",
|
|
400
|
+
description: "The passage that contains the answer."
|
|
401
|
+
})
|
|
402
|
+
], QuestionAnsweringNode.prototype, "context", void 0);
|
|
403
|
+
export class TableQuestionAnsweringNode extends BaseNode {
|
|
404
|
+
static nodeType = "huggingface.TableQuestionAnswering";
|
|
405
|
+
static title = "Table Question Answering";
|
|
406
|
+
static description = "Answer a question about the data in a table.\n" +
|
|
407
|
+
"text, table, question-answering, tabular, nlp, huggingface\n\n" +
|
|
408
|
+
"Use cases:\n" +
|
|
409
|
+
"- Query spreadsheets in natural language\n" +
|
|
410
|
+
"- Aggregate values from a table\n" +
|
|
411
|
+
"- Build conversational data tools";
|
|
412
|
+
static inlineFields = ["question"];
|
|
413
|
+
static inputFields = ["table"];
|
|
414
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
415
|
+
static metadataOutputTypes = {
|
|
416
|
+
output: "str",
|
|
417
|
+
cells: "list",
|
|
418
|
+
aggregator: "str"
|
|
419
|
+
};
|
|
420
|
+
async process() {
|
|
421
|
+
const token = getHfToken(this._secrets);
|
|
422
|
+
const question = String(this.question ?? "");
|
|
423
|
+
if (!question)
|
|
424
|
+
throw new Error("Question cannot be empty");
|
|
425
|
+
const rawTable = this.table ?? {};
|
|
426
|
+
// The API requires every cell to be a string.
|
|
427
|
+
const table = {};
|
|
428
|
+
for (const [col, values] of Object.entries(rawTable)) {
|
|
429
|
+
table[col] = (Array.isArray(values) ? values : [values]).map((v) => String(v));
|
|
430
|
+
}
|
|
431
|
+
if (Object.keys(table).length === 0) {
|
|
432
|
+
throw new Error("Table cannot be empty");
|
|
433
|
+
}
|
|
434
|
+
const result = jsonObject(await hfPipelineJson(token, String(this.model ?? "google/tapas-base-finetuned-wtq"), { inputs: { query: question, table } }));
|
|
435
|
+
return {
|
|
436
|
+
output: jsonString(result["answer"]),
|
|
437
|
+
cells: jsonArray(result["cells"]).map(jsonString),
|
|
438
|
+
aggregator: jsonString(result["aggregator"])
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
__decorate([
|
|
443
|
+
prop({
|
|
444
|
+
type: "str",
|
|
445
|
+
default: "google/tapas-base-finetuned-wtq",
|
|
446
|
+
title: "Model",
|
|
447
|
+
description: "Table-question-answering model repo id."
|
|
448
|
+
})
|
|
449
|
+
], TableQuestionAnsweringNode.prototype, "model", void 0);
|
|
450
|
+
__decorate([
|
|
451
|
+
prop({
|
|
452
|
+
type: "str",
|
|
453
|
+
default: "",
|
|
454
|
+
title: "Question",
|
|
455
|
+
description: "The question to ask about the table."
|
|
456
|
+
})
|
|
457
|
+
], TableQuestionAnsweringNode.prototype, "question", void 0);
|
|
458
|
+
__decorate([
|
|
459
|
+
prop({
|
|
460
|
+
type: "dict",
|
|
461
|
+
default: {},
|
|
462
|
+
title: "Table",
|
|
463
|
+
description: "The table as an object mapping each column name to an array of string cell values."
|
|
464
|
+
})
|
|
465
|
+
], TableQuestionAnsweringNode.prototype, "table", void 0);
|
|
466
|
+
export class FeatureExtractionNode extends BaseNode {
|
|
467
|
+
static nodeType = "huggingface.FeatureExtraction";
|
|
468
|
+
static title = "Feature Extraction";
|
|
469
|
+
static description = "Convert text into an embedding vector.\n" +
|
|
470
|
+
"text, embedding, feature-extraction, vector, rag, huggingface\n\n" +
|
|
471
|
+
"Use cases:\n" +
|
|
472
|
+
"- Build semantic search / RAG\n" +
|
|
473
|
+
"- Cluster or deduplicate documents\n" +
|
|
474
|
+
"- Compute sentence similarity";
|
|
475
|
+
static inlineFields = ["inputs"];
|
|
476
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
477
|
+
static metadataOutputTypes = { output: "list" };
|
|
478
|
+
async process() {
|
|
479
|
+
const token = getHfToken(this._secrets);
|
|
480
|
+
const text = String(this.inputs ?? "");
|
|
481
|
+
if (!text)
|
|
482
|
+
throw new Error("Text cannot be empty");
|
|
483
|
+
const result = await hfPipelineJson(token, String(this.model ?? "sentence-transformers/all-MiniLM-L6-v2"), embedBody(text, Boolean(this.normalize)));
|
|
484
|
+
return { output: result };
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
__decorate([
|
|
488
|
+
prop({
|
|
489
|
+
type: "str",
|
|
490
|
+
default: "sentence-transformers/all-MiniLM-L6-v2",
|
|
491
|
+
title: "Model",
|
|
492
|
+
description: "Feature-extraction / embedding model repo id."
|
|
493
|
+
})
|
|
494
|
+
], FeatureExtractionNode.prototype, "model", void 0);
|
|
495
|
+
__decorate([
|
|
496
|
+
prop({
|
|
497
|
+
type: "str",
|
|
498
|
+
default: "",
|
|
499
|
+
title: "Text",
|
|
500
|
+
description: "The text to embed."
|
|
501
|
+
})
|
|
502
|
+
], FeatureExtractionNode.prototype, "inputs", void 0);
|
|
503
|
+
__decorate([
|
|
504
|
+
prop({
|
|
505
|
+
type: "bool",
|
|
506
|
+
default: false,
|
|
507
|
+
title: "Normalize",
|
|
508
|
+
description: "L2-normalize the returned embedding."
|
|
509
|
+
})
|
|
510
|
+
], FeatureExtractionNode.prototype, "normalize", void 0);
|
|
511
|
+
export class TextClassificationNode extends BaseNode {
|
|
512
|
+
static nodeType = "huggingface.TextClassification";
|
|
513
|
+
static title = "Text Classification";
|
|
514
|
+
static description = "Assign a label / class to a piece of text (e.g. sentiment).\n" +
|
|
515
|
+
"text, classification, sentiment, nlp, huggingface\n\n" +
|
|
516
|
+
"Use cases:\n" +
|
|
517
|
+
"- Sentiment analysis\n" +
|
|
518
|
+
"- Topic / intent detection\n" +
|
|
519
|
+
"- Content moderation";
|
|
520
|
+
static inlineFields = ["inputs"];
|
|
521
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
522
|
+
static metadataOutputTypes = { output: "str", scores: "list" };
|
|
523
|
+
async process() {
|
|
524
|
+
const token = getHfToken(this._secrets);
|
|
525
|
+
const text = String(this.inputs ?? "");
|
|
526
|
+
if (!text)
|
|
527
|
+
throw new Error("Text cannot be empty");
|
|
528
|
+
const result = jsonArray(await hfPipelineJson(token, String(this.model ?? "distilbert-base-uncased-finetuned-sst-2-english"), { inputs: text }));
|
|
529
|
+
// The API may return a flat list or a list-of-lists (one per input).
|
|
530
|
+
const first = result[0];
|
|
531
|
+
const scores = Array.isArray(first) ? first : result;
|
|
532
|
+
return {
|
|
533
|
+
output: jsonString(jsonObject(scores[0])["label"]),
|
|
534
|
+
scores
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
__decorate([
|
|
539
|
+
prop({
|
|
540
|
+
type: "str",
|
|
541
|
+
default: "distilbert-base-uncased-finetuned-sst-2-english",
|
|
542
|
+
title: "Model",
|
|
543
|
+
description: "Text-classification model repo id."
|
|
544
|
+
})
|
|
545
|
+
], TextClassificationNode.prototype, "model", void 0);
|
|
546
|
+
__decorate([
|
|
547
|
+
prop({
|
|
548
|
+
type: "str",
|
|
549
|
+
default: "",
|
|
550
|
+
title: "Text",
|
|
551
|
+
description: "The text to classify."
|
|
552
|
+
})
|
|
553
|
+
], TextClassificationNode.prototype, "inputs", void 0);
|
|
554
|
+
export class TokenClassificationNode extends BaseNode {
|
|
555
|
+
static nodeType = "huggingface.TokenClassification";
|
|
556
|
+
static title = "Token Classification";
|
|
557
|
+
static description = "Assign a label to each token in a text (named-entity recognition).\n" +
|
|
558
|
+
"text, token-classification, ner, entities, nlp, huggingface\n\n" +
|
|
559
|
+
"Use cases:\n" +
|
|
560
|
+
"- Extract people, places, organizations\n" +
|
|
561
|
+
"- Detect PII\n" +
|
|
562
|
+
"- Part-of-speech tagging";
|
|
563
|
+
static inlineFields = ["inputs"];
|
|
564
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
565
|
+
static metadataOutputTypes = { output: "list" };
|
|
566
|
+
async process() {
|
|
567
|
+
const token = getHfToken(this._secrets);
|
|
568
|
+
const text = String(this.inputs ?? "");
|
|
569
|
+
if (!text)
|
|
570
|
+
throw new Error("Text cannot be empty");
|
|
571
|
+
const strategy = String(this.aggregation_strategy ?? "simple");
|
|
572
|
+
const result = await hfPipelineJson(token, String(this.model ?? "dslim/bert-base-NER"), nerBody(text, strategy));
|
|
573
|
+
return { output: jsonArray(result) };
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
__decorate([
|
|
577
|
+
prop({
|
|
578
|
+
type: "str",
|
|
579
|
+
default: "dslim/bert-base-NER",
|
|
580
|
+
title: "Model",
|
|
581
|
+
description: "Token-classification / NER model repo id."
|
|
582
|
+
})
|
|
583
|
+
], TokenClassificationNode.prototype, "model", void 0);
|
|
584
|
+
__decorate([
|
|
585
|
+
prop({
|
|
586
|
+
type: "str",
|
|
587
|
+
default: "",
|
|
588
|
+
title: "Text",
|
|
589
|
+
description: "The text to analyze."
|
|
590
|
+
})
|
|
591
|
+
], TokenClassificationNode.prototype, "inputs", void 0);
|
|
592
|
+
__decorate([
|
|
593
|
+
prop({
|
|
594
|
+
type: "enum",
|
|
595
|
+
default: "simple",
|
|
596
|
+
title: "Aggregation",
|
|
597
|
+
description: "How to group sub-word tokens into entities.",
|
|
598
|
+
values: ["none", "simple", "first", "average", "max"]
|
|
599
|
+
})
|
|
600
|
+
], TokenClassificationNode.prototype, "aggregation_strategy", void 0);
|
|
601
|
+
export class ZeroShotClassificationNode extends BaseNode {
|
|
602
|
+
static nodeType = "huggingface.ZeroShotClassification";
|
|
603
|
+
static title = "Zero Shot Classification";
|
|
604
|
+
static description = "Classify text into arbitrary labels without task-specific training.\n" +
|
|
605
|
+
"text, zero-shot, classification, nlp, huggingface\n\n" +
|
|
606
|
+
"Use cases:\n" +
|
|
607
|
+
"- Classify into custom categories on the fly\n" +
|
|
608
|
+
"- Intent detection without training data\n" +
|
|
609
|
+
"- Flexible content tagging";
|
|
610
|
+
static inlineFields = ["inputs"];
|
|
611
|
+
static requiredSettings = ["HF_TOKEN"];
|
|
612
|
+
static metadataOutputTypes = { output: "str", scores: "list" };
|
|
613
|
+
async process() {
|
|
614
|
+
const token = getHfToken(this._secrets);
|
|
615
|
+
const text = String(this.inputs ?? "");
|
|
616
|
+
if (!text)
|
|
617
|
+
throw new Error("Text cannot be empty");
|
|
618
|
+
const labels = String(this.candidate_labels ?? "")
|
|
619
|
+
.split(",")
|
|
620
|
+
.map((l) => l.trim())
|
|
621
|
+
.filter((l) => l.length > 0);
|
|
622
|
+
if (labels.length === 0) {
|
|
623
|
+
throw new Error("Provide at least one candidate label");
|
|
624
|
+
}
|
|
625
|
+
const result = await hfPipelineJson(token, String(this.model ?? "facebook/bart-large-mnli"), {
|
|
626
|
+
inputs: text,
|
|
627
|
+
parameters: {
|
|
628
|
+
candidate_labels: labels,
|
|
629
|
+
multi_label: Boolean(this.multi_label ?? false)
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
// Newer providers return [{label, score}], the classic API returns
|
|
633
|
+
// {labels, scores}. Normalize both into a sorted list.
|
|
634
|
+
let scores;
|
|
635
|
+
if (Array.isArray(result)) {
|
|
636
|
+
scores = result.map((entry) => {
|
|
637
|
+
const item = jsonObject(entry);
|
|
638
|
+
return {
|
|
639
|
+
label: jsonString(item["label"]),
|
|
640
|
+
score: jsonNumber(item["score"])
|
|
641
|
+
};
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
const envelope = jsonObject(result);
|
|
646
|
+
const ls = jsonArray(envelope["labels"]);
|
|
647
|
+
const ss = jsonArray(envelope["scores"]);
|
|
648
|
+
scores = ls.map((label, i) => ({
|
|
649
|
+
label: jsonString(label),
|
|
650
|
+
score: jsonNumber(ss[i])
|
|
651
|
+
}));
|
|
652
|
+
}
|
|
653
|
+
scores.sort((a, b) => b.score - a.score);
|
|
654
|
+
return { output: scores[0]?.label ?? "", scores };
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
__decorate([
|
|
658
|
+
prop({
|
|
659
|
+
type: "str",
|
|
660
|
+
default: "facebook/bart-large-mnli",
|
|
661
|
+
title: "Model",
|
|
662
|
+
description: "Zero-shot-classification model repo id."
|
|
663
|
+
})
|
|
664
|
+
], ZeroShotClassificationNode.prototype, "model", void 0);
|
|
665
|
+
__decorate([
|
|
666
|
+
prop({
|
|
667
|
+
type: "str",
|
|
668
|
+
default: "",
|
|
669
|
+
title: "Text",
|
|
670
|
+
description: "The text to classify."
|
|
671
|
+
})
|
|
672
|
+
], ZeroShotClassificationNode.prototype, "inputs", void 0);
|
|
673
|
+
__decorate([
|
|
674
|
+
prop({
|
|
675
|
+
type: "str",
|
|
676
|
+
default: "",
|
|
677
|
+
title: "Candidate Labels",
|
|
678
|
+
description: "Comma-separated list of candidate labels."
|
|
679
|
+
})
|
|
680
|
+
], ZeroShotClassificationNode.prototype, "candidate_labels", void 0);
|
|
681
|
+
__decorate([
|
|
682
|
+
prop({
|
|
683
|
+
type: "bool",
|
|
684
|
+
default: false,
|
|
685
|
+
title: "Multi Label",
|
|
686
|
+
description: "Allow multiple labels to be true at once."
|
|
687
|
+
})
|
|
688
|
+
], ZeroShotClassificationNode.prototype, "multi_label", void 0);
|
|
689
|
+
export const HUGGINGFACE_TEXT_NODES = [
|
|
690
|
+
ChatCompletionNode,
|
|
691
|
+
TextGenerationNode,
|
|
692
|
+
SummarizationNode,
|
|
693
|
+
TranslationNode,
|
|
694
|
+
FillMaskNode,
|
|
695
|
+
QuestionAnsweringNode,
|
|
696
|
+
TableQuestionAnsweringNode,
|
|
697
|
+
FeatureExtractionNode,
|
|
698
|
+
TextClassificationNode,
|
|
699
|
+
TokenClassificationNode,
|
|
700
|
+
ZeroShotClassificationNode
|
|
701
|
+
];
|
|
702
|
+
//# sourceMappingURL=text.js.map
|