@nodetool-ai/transformers-js-nodes 0.7.0-rc.11
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/dist/cache-scan.d.ts +26 -0
- package/dist/cache-scan.d.ts.map +1 -0
- package/dist/cache-scan.js +112 -0
- package/dist/cache-scan.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/audio-classification.d.ts +22 -0
- package/dist/nodes/audio-classification.d.ts.map +1 -0
- package/dist/nodes/audio-classification.js +102 -0
- package/dist/nodes/audio-classification.js.map +1 -0
- package/dist/nodes/automatic-speech-recognition.d.ts +22 -0
- package/dist/nodes/automatic-speech-recognition.d.ts.map +1 -0
- package/dist/nodes/automatic-speech-recognition.js +129 -0
- package/dist/nodes/automatic-speech-recognition.js.map +1 -0
- package/dist/nodes/feature-extraction.d.ts +20 -0
- package/dist/nodes/feature-extraction.d.ts.map +1 -0
- package/dist/nodes/feature-extraction.js +153 -0
- package/dist/nodes/feature-extraction.js.map +1 -0
- package/dist/nodes/fill-mask.d.ts +19 -0
- package/dist/nodes/fill-mask.d.ts.map +1 -0
- package/dist/nodes/fill-mask.js +87 -0
- package/dist/nodes/fill-mask.js.map +1 -0
- package/dist/nodes/image-classification.d.ts +21 -0
- package/dist/nodes/image-classification.d.ts.map +1 -0
- package/dist/nodes/image-classification.js +90 -0
- package/dist/nodes/image-classification.js.map +1 -0
- package/dist/nodes/image-to-text.d.ts +19 -0
- package/dist/nodes/image-to-text.d.ts.map +1 -0
- package/dist/nodes/image-to-text.js +81 -0
- package/dist/nodes/image-to-text.js.map +1 -0
- package/dist/nodes/object-detection.d.ts +20 -0
- package/dist/nodes/object-detection.d.ts.map +1 -0
- package/dist/nodes/object-detection.js +93 -0
- package/dist/nodes/object-detection.js.map +1 -0
- package/dist/nodes/question-answering.d.ts +23 -0
- package/dist/nodes/question-answering.d.ts.map +1 -0
- package/dist/nodes/question-answering.js +108 -0
- package/dist/nodes/question-answering.js.map +1 -0
- package/dist/nodes/summarization.d.ts +20 -0
- package/dist/nodes/summarization.d.ts.map +1 -0
- package/dist/nodes/summarization.js +103 -0
- package/dist/nodes/summarization.js.map +1 -0
- package/dist/nodes/text-classification.d.ts +20 -0
- package/dist/nodes/text-classification.d.ts.map +1 -0
- package/dist/nodes/text-classification.js +93 -0
- package/dist/nodes/text-classification.js.map +1 -0
- package/dist/nodes/text-generation.d.ts +23 -0
- package/dist/nodes/text-generation.d.ts.map +1 -0
- package/dist/nodes/text-generation.js +150 -0
- package/dist/nodes/text-generation.js.map +1 -0
- package/dist/nodes/text-to-speech.d.ts +20 -0
- package/dist/nodes/text-to-speech.d.ts.map +1 -0
- package/dist/nodes/text-to-speech.js +122 -0
- package/dist/nodes/text-to-speech.js.map +1 -0
- package/dist/nodes/token-classification.d.ts +18 -0
- package/dist/nodes/token-classification.d.ts.map +1 -0
- package/dist/nodes/token-classification.js +88 -0
- package/dist/nodes/token-classification.js.map +1 -0
- package/dist/nodes/translation.d.ts +20 -0
- package/dist/nodes/translation.d.ts.map +1 -0
- package/dist/nodes/translation.js +106 -0
- package/dist/nodes/translation.js.map +1 -0
- package/dist/nodes/zero-shot-classification.d.ts +23 -0
- package/dist/nodes/zero-shot-classification.d.ts.map +1 -0
- package/dist/nodes/zero-shot-classification.js +128 -0
- package/dist/nodes/zero-shot-classification.js.map +1 -0
- package/dist/nodes/zero-shot-image-classification.d.ts +21 -0
- package/dist/nodes/zero-shot-image-classification.d.ts.map +1 -0
- package/dist/nodes/zero-shot-image-classification.js +101 -0
- package/dist/nodes/zero-shot-image-classification.js.map +1 -0
- package/dist/recommended-models.d.ts +32 -0
- package/dist/recommended-models.d.ts.map +1 -0
- package/dist/recommended-models.js +140 -0
- package/dist/recommended-models.js.map +1 -0
- package/dist/tjs-downloader.d.ts +44 -0
- package/dist/tjs-downloader.d.ts.map +1 -0
- package/dist/tjs-downloader.js +84 -0
- package/dist/tjs-downloader.js.map +1 -0
- package/dist/transformers-base.d.ts +156 -0
- package/dist/transformers-base.d.ts.map +1 -0
- package/dist/transformers-base.js +435 -0
- package/dist/transformers-base.js.map +1 -0
- package/dist/tts-shared.d.ts +16 -0
- package/dist/tts-shared.d.ts.map +1 -0
- package/dist/tts-shared.js +51 -0
- package/dist/tts-shared.js.map +1 -0
- package/dist/wav.d.ts +23 -0
- package/dist/wav.d.ts.map +1 -0
- package/dist/wav.js +115 -0
- package/dist/wav.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseNode } from "@nodetool-ai/node-sdk";
|
|
2
|
+
import type { NodeClass } from "@nodetool-ai/node-sdk";
|
|
3
|
+
export declare class QuestionAnsweringNode extends BaseNode {
|
|
4
|
+
static readonly nodeType = "transformers.QuestionAnswering";
|
|
5
|
+
static readonly title = "Question Answering";
|
|
6
|
+
static readonly description: string;
|
|
7
|
+
static readonly metadataOutputTypes: {
|
|
8
|
+
answer: string;
|
|
9
|
+
score: string;
|
|
10
|
+
start: string;
|
|
11
|
+
end: string;
|
|
12
|
+
results: string;
|
|
13
|
+
};
|
|
14
|
+
question: any;
|
|
15
|
+
context: any;
|
|
16
|
+
model: any;
|
|
17
|
+
top_k: any;
|
|
18
|
+
dtype: any;
|
|
19
|
+
device: any;
|
|
20
|
+
process(): Promise<Record<string, unknown>>;
|
|
21
|
+
}
|
|
22
|
+
export declare const QUESTION_ANSWERING_NODES: readonly NodeClass[];
|
|
23
|
+
//# sourceMappingURL=question-answering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question-answering.d.ts","sourceRoot":"","sources":["../../src/nodes/question-answering.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAuBvD,qBAAa,qBAAsB,SAAQ,QAAQ;IACjD,MAAM,CAAC,QAAQ,CAAC,QAAQ,oCAAoC;IAC5D,MAAM,CAAC,QAAQ,CAAC,KAAK,wBAAwB;IAC7C,MAAM,CAAC,QAAQ,CAAC,WAAW,SAMgB;IAC3C,MAAM,CAAC,QAAQ,CAAC,mBAAmB;;;;;;MAMjC;IAQM,QAAQ,EAAE,GAAG,CAAC;IAQd,OAAO,EAAE,GAAG,CAAC;IAQb,KAAK,EAAE,GAAG,CAAC;IAUX,KAAK,EAAE,GAAG,CAAC;IASX,KAAK,EAAE,GAAG,CAAC;IASX,MAAM,EAAE,GAAG,CAAC;IAEd,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CA8BlD;AAED,eAAO,MAAM,wBAAwB,EAAE,SAAS,SAAS,EAExD,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
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 { DEVICE_VALUES, DTYPE_VALUES, asNumber, asString, ensureArray, extractRepoId, getPipeline, tjsModelDefault, normalizeOption } from "../transformers-base.js";
|
|
9
|
+
import { defaultRepoFor } from "../recommended-models.js";
|
|
10
|
+
const TJS_TYPE = "tjs.question_answering";
|
|
11
|
+
export class QuestionAnsweringNode extends BaseNode {
|
|
12
|
+
static nodeType = "transformers.QuestionAnswering";
|
|
13
|
+
static title = "Question Answering";
|
|
14
|
+
static description = "Extract an answer span from a context paragraph using a Transformers.js question-answering pipeline.\n" +
|
|
15
|
+
"nlp, qa, transformers, huggingface\n\n" +
|
|
16
|
+
"Use cases:\n" +
|
|
17
|
+
"- Answer FAQs from documentation\n" +
|
|
18
|
+
"- Extract facts from long passages\n" +
|
|
19
|
+
"- Build retrieval-augmented chat tools";
|
|
20
|
+
static metadataOutputTypes = {
|
|
21
|
+
answer: "str",
|
|
22
|
+
score: "float",
|
|
23
|
+
start: "int",
|
|
24
|
+
end: "int",
|
|
25
|
+
results: "list"
|
|
26
|
+
};
|
|
27
|
+
async process() {
|
|
28
|
+
const question = asString(this.question);
|
|
29
|
+
const context = asString(this.context);
|
|
30
|
+
if (!question)
|
|
31
|
+
throw new Error("Question is required");
|
|
32
|
+
if (!context)
|
|
33
|
+
throw new Error("Context is required");
|
|
34
|
+
const pipeline = (await getPipeline({
|
|
35
|
+
task: "question-answering",
|
|
36
|
+
model: extractRepoId(this.model) || undefined,
|
|
37
|
+
dtype: normalizeOption(this.dtype),
|
|
38
|
+
device: normalizeOption(this.device)
|
|
39
|
+
}));
|
|
40
|
+
const topK = asNumber(this.top_k, 1);
|
|
41
|
+
const raw = await pipeline(question, context, { top_k: topK });
|
|
42
|
+
const results = ensureArray(raw);
|
|
43
|
+
const top = results[0] ?? { answer: "", score: 0 };
|
|
44
|
+
return {
|
|
45
|
+
answer: top.answer,
|
|
46
|
+
score: top.score,
|
|
47
|
+
start: top.start ?? 0,
|
|
48
|
+
end: top.end ?? 0,
|
|
49
|
+
results
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
__decorate([
|
|
54
|
+
prop({
|
|
55
|
+
type: "str",
|
|
56
|
+
default: "What is the capital of France?",
|
|
57
|
+
title: "Question",
|
|
58
|
+
description: "The question to answer."
|
|
59
|
+
})
|
|
60
|
+
], QuestionAnsweringNode.prototype, "question", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
prop({
|
|
63
|
+
type: "str",
|
|
64
|
+
default: "Paris is the capital and most populous city of France.",
|
|
65
|
+
title: "Context",
|
|
66
|
+
description: "The passage that contains the answer."
|
|
67
|
+
})
|
|
68
|
+
], QuestionAnsweringNode.prototype, "context", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
prop({
|
|
71
|
+
type: TJS_TYPE,
|
|
72
|
+
default: tjsModelDefault(TJS_TYPE, defaultRepoFor(TJS_TYPE)),
|
|
73
|
+
title: "Model",
|
|
74
|
+
description: "Transformers.js model (ONNX-compatible)."
|
|
75
|
+
})
|
|
76
|
+
], QuestionAnsweringNode.prototype, "model", void 0);
|
|
77
|
+
__decorate([
|
|
78
|
+
prop({
|
|
79
|
+
type: "int",
|
|
80
|
+
default: 1,
|
|
81
|
+
title: "Top K",
|
|
82
|
+
description: "Number of candidate answers to return.",
|
|
83
|
+
min: 1,
|
|
84
|
+
max: 20
|
|
85
|
+
})
|
|
86
|
+
], QuestionAnsweringNode.prototype, "top_k", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
prop({
|
|
89
|
+
type: "enum",
|
|
90
|
+
default: "auto",
|
|
91
|
+
title: "Quantization",
|
|
92
|
+
description: "Model dtype / quantization level.",
|
|
93
|
+
values: DTYPE_VALUES
|
|
94
|
+
})
|
|
95
|
+
], QuestionAnsweringNode.prototype, "dtype", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
prop({
|
|
98
|
+
type: "enum",
|
|
99
|
+
default: "auto",
|
|
100
|
+
title: "Device",
|
|
101
|
+
description: "Inference device.",
|
|
102
|
+
values: DEVICE_VALUES
|
|
103
|
+
})
|
|
104
|
+
], QuestionAnsweringNode.prototype, "device", void 0);
|
|
105
|
+
export const QUESTION_ANSWERING_NODES = [
|
|
106
|
+
QuestionAnsweringNode
|
|
107
|
+
];
|
|
108
|
+
//# sourceMappingURL=question-answering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question-answering.js","sourceR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,CAAC;QACV,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,wCAAwC;QACrD,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAE;KACR,CAAC;oDACiB;AASX;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,mCAAmC;QAChD,MAAM,EAAE,YAAY;KACrB,CAAC;oDACiB;AASX;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,mBAAmB;QAChC,MAAM,EAAE,aAAa;KACtB,CAAC;qDACkB;AAkCtB,MAAM,CAAC,MAAM,wBAAwB,GAAyB;IAC5D,qBAAqB;CACtB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseNode } from "@nodetool-ai/node-sdk";
|
|
2
|
+
import type { NodeClass } from "@nodetool-ai/node-sdk";
|
|
3
|
+
export declare class SummarizationNode extends BaseNode {
|
|
4
|
+
static readonly nodeType = "transformers.Summarization";
|
|
5
|
+
static readonly title = "Summarization";
|
|
6
|
+
static readonly description: string;
|
|
7
|
+
static readonly metadataOutputTypes: {
|
|
8
|
+
summary: string;
|
|
9
|
+
};
|
|
10
|
+
text: any;
|
|
11
|
+
model: any;
|
|
12
|
+
max_length: any;
|
|
13
|
+
min_length: any;
|
|
14
|
+
do_sample: any;
|
|
15
|
+
dtype: any;
|
|
16
|
+
device: any;
|
|
17
|
+
process(): Promise<Record<string, unknown>>;
|
|
18
|
+
}
|
|
19
|
+
export declare const SUMMARIZATION_NODES: readonly NodeClass[];
|
|
20
|
+
//# sourceMappingURL=summarization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summarization.d.ts","sourceRoot":"","sources":["../../src/nodes/summarization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAkBvD,qBAAa,iBAAkB,SAAQ,QAAQ;IAC7C,MAAM,CAAC,QAAQ,CAAC,QAAQ,gCAAgC;IACxD,MAAM,CAAC,QAAQ,CAAC,KAAK,mBAAmB;IACxC,MAAM,CAAC,QAAQ,CAAC,WAAW,SAMqB;IAChD,MAAM,CAAC,QAAQ,CAAC,mBAAmB;;MAAsB;IAQjD,IAAI,EAAE,GAAG,CAAC;IAQV,KAAK,EAAE,GAAG,CAAC;IAUX,UAAU,EAAE,GAAG,CAAC;IAUhB,UAAU,EAAE,GAAG,CAAC;IAQhB,SAAS,EAAE,GAAG,CAAC;IASf,KAAK,EAAE,GAAG,CAAC;IASX,MAAM,EAAE,GAAG,CAAC;IAEd,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAuBlD;AAED,eAAO,MAAM,mBAAmB,EAAE,SAAS,SAAS,EAAwB,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
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 { DEVICE_VALUES, DTYPE_VALUES, asNumber, asString, ensureArray, extractRepoId, getPipeline, tjsModelDefault, normalizeOption } from "../transformers-base.js";
|
|
9
|
+
import { defaultRepoFor } from "../recommended-models.js";
|
|
10
|
+
const TJS_TYPE = "tjs.summarization";
|
|
11
|
+
export class SummarizationNode extends BaseNode {
|
|
12
|
+
static nodeType = "transformers.Summarization";
|
|
13
|
+
static title = "Summarization";
|
|
14
|
+
static description = "Summarize long text using a Transformers.js summarization pipeline.\n" +
|
|
15
|
+
"nlp, summary, transformers, huggingface\n\n" +
|
|
16
|
+
"Use cases:\n" +
|
|
17
|
+
"- Condense articles or meeting notes\n" +
|
|
18
|
+
"- Generate TL;DR previews\n" +
|
|
19
|
+
"- Pre-process documents for downstream LLMs";
|
|
20
|
+
static metadataOutputTypes = { summary: "str" };
|
|
21
|
+
async process() {
|
|
22
|
+
const text = asString(this.text);
|
|
23
|
+
if (!text)
|
|
24
|
+
throw new Error("Text is required");
|
|
25
|
+
const pipeline = (await getPipeline({
|
|
26
|
+
task: "summarization",
|
|
27
|
+
model: extractRepoId(this.model) || undefined,
|
|
28
|
+
dtype: normalizeOption(this.dtype),
|
|
29
|
+
device: normalizeOption(this.device)
|
|
30
|
+
}));
|
|
31
|
+
const raw = await pipeline(text, {
|
|
32
|
+
max_length: asNumber(this.max_length, 130),
|
|
33
|
+
min_length: asNumber(this.min_length, 30),
|
|
34
|
+
do_sample: Boolean(this.do_sample)
|
|
35
|
+
});
|
|
36
|
+
const first = ensureArray(raw)[0];
|
|
37
|
+
return { summary: first?.summary_text ?? "" };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
__decorate([
|
|
41
|
+
prop({
|
|
42
|
+
type: "str",
|
|
43
|
+
default: "",
|
|
44
|
+
title: "Text",
|
|
45
|
+
description: "The text to summarize."
|
|
46
|
+
})
|
|
47
|
+
], SummarizationNode.prototype, "text", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
prop({
|
|
50
|
+
type: TJS_TYPE,
|
|
51
|
+
default: tjsModelDefault(TJS_TYPE, defaultRepoFor(TJS_TYPE)),
|
|
52
|
+
title: "Model",
|
|
53
|
+
description: "Transformers.js model (ONNX-compatible)."
|
|
54
|
+
})
|
|
55
|
+
], SummarizationNode.prototype, "model", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
prop({
|
|
58
|
+
type: "int",
|
|
59
|
+
default: 130,
|
|
60
|
+
title: "Max Length",
|
|
61
|
+
description: "Maximum number of tokens in the generated summary.",
|
|
62
|
+
min: 1,
|
|
63
|
+
max: 4096
|
|
64
|
+
})
|
|
65
|
+
], SummarizationNode.prototype, "max_length", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
prop({
|
|
68
|
+
type: "int",
|
|
69
|
+
default: 30,
|
|
70
|
+
title: "Min Length",
|
|
71
|
+
description: "Minimum number of tokens in the generated summary.",
|
|
72
|
+
min: 0,
|
|
73
|
+
max: 4096
|
|
74
|
+
})
|
|
75
|
+
], SummarizationNode.prototype, "min_length", void 0);
|
|
76
|
+
__decorate([
|
|
77
|
+
prop({
|
|
78
|
+
type: "bool",
|
|
79
|
+
default: false,
|
|
80
|
+
title: "Do Sample",
|
|
81
|
+
description: "Sample tokens instead of greedy decoding."
|
|
82
|
+
})
|
|
83
|
+
], SummarizationNode.prototype, "do_sample", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
prop({
|
|
86
|
+
type: "enum",
|
|
87
|
+
default: "auto",
|
|
88
|
+
title: "Quantization",
|
|
89
|
+
description: "Model dtype / quantization level.",
|
|
90
|
+
values: DTYPE_VALUES
|
|
91
|
+
})
|
|
92
|
+
], SummarizationNode.prototype, "dtype", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
prop({
|
|
95
|
+
type: "enum",
|
|
96
|
+
default: "auto",
|
|
97
|
+
title: "Device",
|
|
98
|
+
description: "Inference device.",
|
|
99
|
+
values: DEVICE_VALUES
|
|
100
|
+
})
|
|
101
|
+
], SummarizationNode.prototype, "device", void 0);
|
|
102
|
+
export const SUMMARIZATION_NODES = [SummarizationNode];
|
|
103
|
+
//# sourceMappingURL=summarization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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ACf,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,mCAAmC;QAChD,MAAM,EAAE,YAAY;KACrB,CAAC;gDACiB;AASX;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,mBAAmB;QAChC,MAAM,EAAE,aAAa;KACtB,CAAC;iDACkB;AA2BtB,MAAM,CAAC,MAAM,mBAAmB,GAAyB,CAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseNode } from "@nodetool-ai/node-sdk";
|
|
2
|
+
import type { NodeClass } from "@nodetool-ai/node-sdk";
|
|
3
|
+
export declare class TextClassificationNode extends BaseNode {
|
|
4
|
+
static readonly nodeType = "transformers.TextClassification";
|
|
5
|
+
static readonly title = "Text Classification";
|
|
6
|
+
static readonly description: string;
|
|
7
|
+
static readonly metadataOutputTypes: {
|
|
8
|
+
label: string;
|
|
9
|
+
score: string;
|
|
10
|
+
results: string;
|
|
11
|
+
};
|
|
12
|
+
text: any;
|
|
13
|
+
model: any;
|
|
14
|
+
top_k: any;
|
|
15
|
+
dtype: any;
|
|
16
|
+
device: any;
|
|
17
|
+
process(): Promise<Record<string, unknown>>;
|
|
18
|
+
}
|
|
19
|
+
export declare const TEXT_CLASSIFICATION_NODES: readonly NodeClass[];
|
|
20
|
+
//# sourceMappingURL=text-classification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-classification.d.ts","sourceRoot":"","sources":["../../src/nodes/text-classification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAkBvD,qBAAa,sBAAuB,SAAQ,QAAQ;IAClD,MAAM,CAAC,QAAQ,CAAC,QAAQ,qCAAqC;IAC7D,MAAM,CAAC,QAAQ,CAAC,KAAK,yBAAyB;IAC9C,MAAM,CAAC,QAAQ,CAAC,WAAW,SAMQ;IACnC,MAAM,CAAC,QAAQ,CAAC,mBAAmB;;;;MAIjC;IAQM,IAAI,EAAE,GAAG,CAAC;IAQV,KAAK,EAAE,GAAG,CAAC;IAUX,KAAK,EAAE,GAAG,CAAC;IASX,KAAK,EAAE,GAAG,CAAC;IASX,MAAM,EAAE,GAAG,CAAC;IAEd,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAyBlD;AAED,eAAO,MAAM,yBAAyB,EAAE,SAAS,SAAS,EAEzD,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
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 { DEVICE_VALUES, DTYPE_VALUES, asNumber, asString, ensureArray, extractRepoId, getPipeline, tjsModelDefault, normalizeOption } from "../transformers-base.js";
|
|
9
|
+
import { defaultRepoFor } from "../recommended-models.js";
|
|
10
|
+
const TJS_TYPE = "tjs.text_classification";
|
|
11
|
+
export class TextClassificationNode extends BaseNode {
|
|
12
|
+
static nodeType = "transformers.TextClassification";
|
|
13
|
+
static title = "Text Classification";
|
|
14
|
+
static description = "Classify text using a Transformers.js text-classification pipeline (e.g. sentiment analysis).\n" +
|
|
15
|
+
"nlp, classification, sentiment, transformers, huggingface\n\n" +
|
|
16
|
+
"Use cases:\n" +
|
|
17
|
+
"- Detect sentiment of reviews or chats\n" +
|
|
18
|
+
"- Triage support tickets\n" +
|
|
19
|
+
"- Filter toxic or spam content";
|
|
20
|
+
static metadataOutputTypes = {
|
|
21
|
+
label: "str",
|
|
22
|
+
score: "float",
|
|
23
|
+
results: "list"
|
|
24
|
+
};
|
|
25
|
+
async process() {
|
|
26
|
+
const text = asString(this.text);
|
|
27
|
+
if (!text)
|
|
28
|
+
throw new Error("Text is required");
|
|
29
|
+
const topK = asNumber(this.top_k, 1);
|
|
30
|
+
const pipeline = (await getPipeline({
|
|
31
|
+
task: "text-classification",
|
|
32
|
+
model: extractRepoId(this.model) || undefined,
|
|
33
|
+
dtype: normalizeOption(this.dtype),
|
|
34
|
+
device: normalizeOption(this.device)
|
|
35
|
+
}));
|
|
36
|
+
const raw = await pipeline(text, { top_k: topK });
|
|
37
|
+
const results = ensureArray(raw);
|
|
38
|
+
const top = results[0] ?? { label: "", score: 0 };
|
|
39
|
+
return {
|
|
40
|
+
label: top.label,
|
|
41
|
+
score: top.score,
|
|
42
|
+
results
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
__decorate([
|
|
47
|
+
prop({
|
|
48
|
+
type: "str",
|
|
49
|
+
default: "I love this product!",
|
|
50
|
+
title: "Text",
|
|
51
|
+
description: "The text to classify."
|
|
52
|
+
})
|
|
53
|
+
], TextClassificationNode.prototype, "text", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
prop({
|
|
56
|
+
type: TJS_TYPE,
|
|
57
|
+
default: tjsModelDefault(TJS_TYPE, defaultRepoFor(TJS_TYPE)),
|
|
58
|
+
title: "Model",
|
|
59
|
+
description: "Transformers.js model (ONNX-compatible)."
|
|
60
|
+
})
|
|
61
|
+
], TextClassificationNode.prototype, "model", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
prop({
|
|
64
|
+
type: "int",
|
|
65
|
+
default: 1,
|
|
66
|
+
title: "Top K",
|
|
67
|
+
description: "Number of top labels to return (1 returns the best label).",
|
|
68
|
+
min: 1,
|
|
69
|
+
max: 100
|
|
70
|
+
})
|
|
71
|
+
], TextClassificationNode.prototype, "top_k", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
prop({
|
|
74
|
+
type: "enum",
|
|
75
|
+
default: "auto",
|
|
76
|
+
title: "Quantization",
|
|
77
|
+
description: "Model dtype / quantization level.",
|
|
78
|
+
values: DTYPE_VALUES
|
|
79
|
+
})
|
|
80
|
+
], TextClassificationNode.prototype, "dtype", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
prop({
|
|
83
|
+
type: "enum",
|
|
84
|
+
default: "auto",
|
|
85
|
+
title: "Device",
|
|
86
|
+
description: "Inference device.",
|
|
87
|
+
values: DEVICE_VALUES
|
|
88
|
+
})
|
|
89
|
+
], TextClassificationNode.prototype, "device", void 0);
|
|
90
|
+
export const TEXT_CLASSIFICATION_NODES = [
|
|
91
|
+
TextClassificationNode
|
|
92
|
+
];
|
|
93
|
+
//# sourceMappingURL=text-classification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-classification.js","sourceRoot":"","sources":["../../src/nodes/text-classification.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,eAAe,EAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,QAAQ,GAAG,yBAAyB,CAAC;AAI3C,MAAM,OAAO,sBAAuB,SAAQ,QAAQ;IAClD,MAAM,CAAU,QAAQ,GAAG,iCAAiC,CAAC;IAC7D,MAAM,CAAU,KAAK,GAAG,qBAAqB,CAAC;IAC9C,MAAM,CAAU,WAA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EAAE,uBAAuB;KACrC,CAAC;oDACgB;AAQV;IANP,IAAI,CAAC;QACJ,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC5D,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,0CAA0C;KACxD,CAAC;qDACiB;AAUX;IARP,IAAI,CAAC;QACJ,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,4DAA4D;QACzE,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,GAAG;KACT,CAAC;qDACiB;AASX;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,mCAAmC;QAChD,MAAM,EAAE,YAAY;KACrB,CAAC;qDACiB;AASX;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,mBAAmB;QAChC,MAAM,EAAE,aAAa;KACtB,CAAC;sDACkB;AA6BtB,MAAM,CAAC,MAAM,yBAAyB,GAAyB;IAC7D,sBAAsB;CACvB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseNode } from "@nodetool-ai/node-sdk";
|
|
2
|
+
import type { NodeClass } from "@nodetool-ai/node-sdk";
|
|
3
|
+
export declare class TextGenerationNode extends BaseNode {
|
|
4
|
+
static readonly nodeType = "transformers.TextGeneration";
|
|
5
|
+
static readonly title = "Text Generation";
|
|
6
|
+
static readonly description: string;
|
|
7
|
+
static readonly metadataOutputTypes: {
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
10
|
+
prompt: any;
|
|
11
|
+
model: any;
|
|
12
|
+
max_new_tokens: any;
|
|
13
|
+
temperature: any;
|
|
14
|
+
top_p: any;
|
|
15
|
+
top_k: any;
|
|
16
|
+
do_sample: any;
|
|
17
|
+
repetition_penalty: any;
|
|
18
|
+
dtype: any;
|
|
19
|
+
device: any;
|
|
20
|
+
process(): Promise<Record<string, unknown>>;
|
|
21
|
+
}
|
|
22
|
+
export declare const TEXT_GENERATION_NODES: readonly NodeClass[];
|
|
23
|
+
//# sourceMappingURL=text-generation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-generation.d.ts","sourceRoot":"","sources":["../../src/nodes/text-generation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AA2BvD,qBAAa,kBAAmB,SAAQ,QAAQ;IAC9C,MAAM,CAAC,QAAQ,CAAC,QAAQ,iCAAiC;IACzD,MAAM,CAAC,QAAQ,CAAC,KAAK,qBAAqB;IAC1C,MAAM,CAAC,QAAQ,CAAC,WAAW,SAMyB;IACpD,MAAM,CAAC,QAAQ,CAAC,mBAAmB;;MAAmB;IAQ9C,MAAM,EAAE,GAAG,CAAC;IAQZ,KAAK,EAAE,GAAG,CAAC;IAUX,cAAc,EAAE,GAAG,CAAC;IAUpB,WAAW,EAAE,GAAG,CAAC;IAUjB,KAAK,EAAE,GAAG,CAAC;IAUX,KAAK,EAAE,GAAG,CAAC;IAQX,SAAS,EAAE,GAAG,CAAC;IAUf,kBAAkB,EAAE,GAAG,CAAC;IASxB,KAAK,EAAE,GAAG,CAAC;IASX,MAAM,EAAE,GAAG,CAAC;IAEd,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CA6BlD;AAED,eAAO,MAAM,qBAAqB,EAAE,SAAS,SAAS,EAAyB,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
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 { DEVICE_VALUES, DTYPE_VALUES, asNumber, asString, ensureArray, extractRepoId, getPipeline, tjsModelDefault, normalizeOption } from "../transformers-base.js";
|
|
9
|
+
import { defaultRepoFor } from "../recommended-models.js";
|
|
10
|
+
const TJS_TYPE = "tjs.text_generation";
|
|
11
|
+
function extractText(value) {
|
|
12
|
+
if (typeof value === "string")
|
|
13
|
+
return value;
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
const last = value[value.length - 1];
|
|
16
|
+
if (last && typeof last.content === "string")
|
|
17
|
+
return last.content;
|
|
18
|
+
}
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
export class TextGenerationNode extends BaseNode {
|
|
22
|
+
static nodeType = "transformers.TextGeneration";
|
|
23
|
+
static title = "Text Generation";
|
|
24
|
+
static description = "Generate text completions using a Transformers.js text-generation pipeline.\n" +
|
|
25
|
+
"nlp, generation, llm, transformers, huggingface\n\n" +
|
|
26
|
+
"Use cases:\n" +
|
|
27
|
+
"- Run small open-source LLMs offline\n" +
|
|
28
|
+
"- Prototype completions without an API key\n" +
|
|
29
|
+
"- Generate text in environments with no network";
|
|
30
|
+
static metadataOutputTypes = { text: "str" };
|
|
31
|
+
async process() {
|
|
32
|
+
const prompt = asString(this.prompt);
|
|
33
|
+
if (!prompt)
|
|
34
|
+
throw new Error("Prompt is required");
|
|
35
|
+
const pipeline = (await getPipeline({
|
|
36
|
+
task: "text-generation",
|
|
37
|
+
model: extractRepoId(this.model) || undefined,
|
|
38
|
+
dtype: normalizeOption(this.dtype),
|
|
39
|
+
device: normalizeOption(this.device)
|
|
40
|
+
}));
|
|
41
|
+
const opts = {
|
|
42
|
+
max_new_tokens: asNumber(this.max_new_tokens, 128),
|
|
43
|
+
temperature: asNumber(this.temperature, 1.0),
|
|
44
|
+
top_p: asNumber(this.top_p, 1.0),
|
|
45
|
+
do_sample: Boolean(this.do_sample),
|
|
46
|
+
repetition_penalty: asNumber(this.repetition_penalty, 1.0),
|
|
47
|
+
return_full_text: false
|
|
48
|
+
};
|
|
49
|
+
const topK = asNumber(this.top_k, 50);
|
|
50
|
+
if (topK > 0)
|
|
51
|
+
opts.top_k = topK;
|
|
52
|
+
const raw = await pipeline(prompt, opts);
|
|
53
|
+
const first = ensureArray(raw)[0];
|
|
54
|
+
return { text: extractText(first?.generated_text) };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__decorate([
|
|
58
|
+
prop({
|
|
59
|
+
type: "str",
|
|
60
|
+
default: "Once upon a time",
|
|
61
|
+
title: "Prompt",
|
|
62
|
+
description: "Prompt for the language model."
|
|
63
|
+
})
|
|
64
|
+
], TextGenerationNode.prototype, "prompt", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
prop({
|
|
67
|
+
type: TJS_TYPE,
|
|
68
|
+
default: tjsModelDefault(TJS_TYPE, defaultRepoFor(TJS_TYPE)),
|
|
69
|
+
title: "Model",
|
|
70
|
+
description: "Transformers.js model (ONNX-compatible)."
|
|
71
|
+
})
|
|
72
|
+
], TextGenerationNode.prototype, "model", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
prop({
|
|
75
|
+
type: "int",
|
|
76
|
+
default: 128,
|
|
77
|
+
title: "Max New Tokens",
|
|
78
|
+
description: "Maximum number of tokens to generate after the prompt.",
|
|
79
|
+
min: 1,
|
|
80
|
+
max: 4096
|
|
81
|
+
})
|
|
82
|
+
], TextGenerationNode.prototype, "max_new_tokens", void 0);
|
|
83
|
+
__decorate([
|
|
84
|
+
prop({
|
|
85
|
+
type: "float",
|
|
86
|
+
default: 1.0,
|
|
87
|
+
title: "Temperature",
|
|
88
|
+
description: "Sampling temperature (1.0 = neutral).",
|
|
89
|
+
min: 0.0,
|
|
90
|
+
max: 5.0
|
|
91
|
+
})
|
|
92
|
+
], TextGenerationNode.prototype, "temperature", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
prop({
|
|
95
|
+
type: "float",
|
|
96
|
+
default: 1.0,
|
|
97
|
+
title: "Top P",
|
|
98
|
+
description: "Nucleus sampling probability mass (1.0 = disabled).",
|
|
99
|
+
min: 0.0,
|
|
100
|
+
max: 1.0
|
|
101
|
+
})
|
|
102
|
+
], TextGenerationNode.prototype, "top_p", void 0);
|
|
103
|
+
__decorate([
|
|
104
|
+
prop({
|
|
105
|
+
type: "int",
|
|
106
|
+
default: 50,
|
|
107
|
+
title: "Top K",
|
|
108
|
+
description: "Limit sampling to the K most likely tokens.",
|
|
109
|
+
min: 0,
|
|
110
|
+
max: 1000
|
|
111
|
+
})
|
|
112
|
+
], TextGenerationNode.prototype, "top_k", void 0);
|
|
113
|
+
__decorate([
|
|
114
|
+
prop({
|
|
115
|
+
type: "bool",
|
|
116
|
+
default: true,
|
|
117
|
+
title: "Do Sample",
|
|
118
|
+
description: "Sample tokens instead of greedy decoding."
|
|
119
|
+
})
|
|
120
|
+
], TextGenerationNode.prototype, "do_sample", void 0);
|
|
121
|
+
__decorate([
|
|
122
|
+
prop({
|
|
123
|
+
type: "float",
|
|
124
|
+
default: 1.0,
|
|
125
|
+
title: "Repetition Penalty",
|
|
126
|
+
description: "Penalty applied to repeated tokens (>1 discourages repetition).",
|
|
127
|
+
min: 0.5,
|
|
128
|
+
max: 5.0
|
|
129
|
+
})
|
|
130
|
+
], TextGenerationNode.prototype, "repetition_penalty", void 0);
|
|
131
|
+
__decorate([
|
|
132
|
+
prop({
|
|
133
|
+
type: "enum",
|
|
134
|
+
default: "auto",
|
|
135
|
+
title: "Quantization",
|
|
136
|
+
description: "Model dtype / quantization level.",
|
|
137
|
+
values: DTYPE_VALUES
|
|
138
|
+
})
|
|
139
|
+
], TextGenerationNode.prototype, "dtype", void 0);
|
|
140
|
+
__decorate([
|
|
141
|
+
prop({
|
|
142
|
+
type: "enum",
|
|
143
|
+
default: "auto",
|
|
144
|
+
title: "Device",
|
|
145
|
+
description: "Inference device.",
|
|
146
|
+
values: DEVICE_VALUES
|
|
147
|
+
})
|
|
148
|
+
], TextGenerationNode.prototype, "device", void 0);
|
|
149
|
+
export const TEXT_GENERATION_NODES = [TextGenerationNode];
|
|
150
|
+
//# sourceMappingURL=text-generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-generation.js","sourceRoot":"","sources":["../../src/nodes/text-generation.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,eAAe,EAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AAIvC,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAwC,CAAC;QAC5E,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC;IACpE,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,OAAO,kBAAmB,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AK;QACX,OAAO,EAAE,EAAE;QACX,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,6CAA6C;QAC1D,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,IAAI;KACV,CAAC;iDACiB;AAQX;IANP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,WAAW;QAClB,WAAW,EAAE,2CAA2C;KACzD,CAAC;qDACqB;AAUf;IARP,IAAI,CAAC;QACJ,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,GAAG;QACZ,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EAAE,iEAAiE;QAC9E,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;KACT,CAAC;8DAC8B;AASxB;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,mCAAmC;QAChD,MAAM,EAAE,YAAY;KACrB,CAAC;iDACiB;AASX;IAPP,IAAI,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,mBAAmB;QAChC,MAAM,EAAE,aAAa;KACtB,CAAC;kDACkB;AAiCtB,MAAM,CAAC,MAAM,qBAAqB,GAAyB,CAAC,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseNode } from "@nodetool-ai/node-sdk";
|
|
2
|
+
import type { NodeClass } from "@nodetool-ai/node-sdk";
|
|
3
|
+
export declare class TextToSpeechNode extends BaseNode {
|
|
4
|
+
static readonly nodeType = "transformers.TextToSpeech";
|
|
5
|
+
static readonly title = "Text to Speech";
|
|
6
|
+
static readonly description: string;
|
|
7
|
+
static readonly metadataOutputTypes: {
|
|
8
|
+
output: string;
|
|
9
|
+
};
|
|
10
|
+
static readonly autoSaveAsset = true;
|
|
11
|
+
text: any;
|
|
12
|
+
model: any;
|
|
13
|
+
speaker_embeddings: any;
|
|
14
|
+
voice: any;
|
|
15
|
+
dtype: any;
|
|
16
|
+
device: any;
|
|
17
|
+
process(): Promise<Record<string, unknown>>;
|
|
18
|
+
}
|
|
19
|
+
export declare const TEXT_TO_SPEECH_NODES: readonly NodeClass[];
|
|
20
|
+
//# sourceMappingURL=text-to-speech.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-to-speech.d.ts","sourceRoot":"","sources":["../../src/nodes/text-to-speech.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AA0BvD,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,MAAM,CAAC,QAAQ,CAAC,QAAQ,+BAA+B;IACvD,MAAM,CAAC,QAAQ,CAAC,KAAK,oBAAoB;IACzC,MAAM,CAAC,QAAQ,CAAC,WAAW,SAMO;IAClC,MAAM,CAAC,QAAQ,CAAC,mBAAmB;;MAAuB;IAC1D,MAAM,CAAC,QAAQ,CAAC,aAAa,QAAQ;IAQ7B,IAAI,EAAE,GAAG,CAAC;IAQV,KAAK,EAAE,GAAG,CAAC;IAUX,kBAAkB,EAAE,GAAG,CAAC;IAUxB,KAAK,EAAE,GAAG,CAAC;IASX,KAAK,EAAE,GAAG,CAAC;IASX,MAAM,EAAE,GAAG,CAAC;IAEd,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAoDlD;AAED,eAAO,MAAM,oBAAoB,EAAE,SAAS,SAAS,EAAuB,CAAC"}
|