@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,101 @@
|
|
|
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, ensureArray, extractRepoId, getPipeline, tjsModelDefault, loadRawImage, normalizeOption } from "../transformers-base.js";
|
|
9
|
+
import { defaultRepoFor } from "../recommended-models.js";
|
|
10
|
+
const TJS_TYPE = "tjs.zero_shot_image_classification";
|
|
11
|
+
function parseLabels(value) {
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
return value.map((v) => String(v).trim()).filter(Boolean);
|
|
14
|
+
}
|
|
15
|
+
return String(value ?? "")
|
|
16
|
+
.split(",")
|
|
17
|
+
.map((s) => s.trim())
|
|
18
|
+
.filter(Boolean);
|
|
19
|
+
}
|
|
20
|
+
export class ZeroShotImageClassificationNode extends BaseNode {
|
|
21
|
+
static nodeType = "transformers.ZeroShotImageClassification";
|
|
22
|
+
static title = "Zero-Shot Image Classification";
|
|
23
|
+
static description = "Score arbitrary user-supplied labels for an image using a CLIP-style Transformers.js pipeline.\n" +
|
|
24
|
+
"vision, zero-shot, classification, clip, transformers, huggingface\n\n" +
|
|
25
|
+
"Use cases:\n" +
|
|
26
|
+
"- Tag images with custom categories\n" +
|
|
27
|
+
"- Build moderation or NSFW filters\n" +
|
|
28
|
+
"- Search images by free-form descriptions";
|
|
29
|
+
static metadataOutputTypes = {
|
|
30
|
+
label: "str",
|
|
31
|
+
score: "float",
|
|
32
|
+
results: "list"
|
|
33
|
+
};
|
|
34
|
+
async process(context) {
|
|
35
|
+
const rawImage = await loadRawImage(this.image, context);
|
|
36
|
+
const labels = parseLabels(this.candidate_labels);
|
|
37
|
+
if (labels.length === 0) {
|
|
38
|
+
throw new Error("At least one candidate label is required");
|
|
39
|
+
}
|
|
40
|
+
const pipeline = (await getPipeline({
|
|
41
|
+
task: "zero-shot-image-classification",
|
|
42
|
+
model: extractRepoId(this.model) || undefined,
|
|
43
|
+
dtype: normalizeOption(this.dtype),
|
|
44
|
+
device: normalizeOption(this.device)
|
|
45
|
+
}));
|
|
46
|
+
const raw = await pipeline(rawImage, labels);
|
|
47
|
+
const results = ensureArray(raw);
|
|
48
|
+
const top = results[0] ?? { label: "", score: 0 };
|
|
49
|
+
return {
|
|
50
|
+
label: top.label,
|
|
51
|
+
score: top.score,
|
|
52
|
+
results
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
__decorate([
|
|
57
|
+
prop({
|
|
58
|
+
type: "image",
|
|
59
|
+
default: { type: "image" },
|
|
60
|
+
title: "Image",
|
|
61
|
+
description: "Image to classify."
|
|
62
|
+
})
|
|
63
|
+
], ZeroShotImageClassificationNode.prototype, "image", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
prop({
|
|
66
|
+
type: "str",
|
|
67
|
+
default: "a photo of a cat, a photo of a dog, a photo of a bird",
|
|
68
|
+
title: "Candidate Labels",
|
|
69
|
+
description: "Comma-separated list of candidate labels."
|
|
70
|
+
})
|
|
71
|
+
], ZeroShotImageClassificationNode.prototype, "candidate_labels", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
prop({
|
|
74
|
+
type: TJS_TYPE,
|
|
75
|
+
default: tjsModelDefault(TJS_TYPE, defaultRepoFor(TJS_TYPE)),
|
|
76
|
+
title: "Model",
|
|
77
|
+
description: "Transformers.js model (ONNX-compatible)."
|
|
78
|
+
})
|
|
79
|
+
], ZeroShotImageClassificationNode.prototype, "model", void 0);
|
|
80
|
+
__decorate([
|
|
81
|
+
prop({
|
|
82
|
+
type: "enum",
|
|
83
|
+
default: "auto",
|
|
84
|
+
title: "Quantization",
|
|
85
|
+
description: "Model dtype / quantization level.",
|
|
86
|
+
values: DTYPE_VALUES
|
|
87
|
+
})
|
|
88
|
+
], ZeroShotImageClassificationNode.prototype, "dtype", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
prop({
|
|
91
|
+
type: "enum",
|
|
92
|
+
default: "auto",
|
|
93
|
+
title: "Device",
|
|
94
|
+
description: "Inference device.",
|
|
95
|
+
values: DEVICE_VALUES
|
|
96
|
+
})
|
|
97
|
+
], ZeroShotImageClassificationNode.prototype, "device", void 0);
|
|
98
|
+
export const ZERO_SHOT_IMAGE_CLASSIFICATION_NODES = [
|
|
99
|
+
ZeroShotImageClassificationNode
|
|
100
|
+
];
|
|
101
|
+
//# sourceMappingURL=zero-shot-image-classification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zero-shot-image-classification.js","sourceRoot":"","sources":["../../src/nodes/zero-shot-image-classification.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,WAAW,EACX,aAAa,EACb,WAAW,E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AAM;QACZ,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,mCAAmC;QAChD,MAAM,EAAE,YAAY;KACrB,CAAC;8DACiB;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;+DACkB;AAkCtB,MAAM,CAAC,MAAM,oCAAoC,GAAyB;IACxE,+BAA+B;CAChC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curated recommended-model lists for each `tjs.*` task type.
|
|
3
|
+
*
|
|
4
|
+
* Transformers.js requires ONNX-exported repos (the `Xenova/*` and
|
|
5
|
+
* `onnx-community/*` mirrors are the canonical sources). The Python-side
|
|
6
|
+
* `nodetool-huggingface` recommended lists are mostly PyTorch-only and would
|
|
7
|
+
* fail to load here, so we maintain a parallel ONNX-compatible registry.
|
|
8
|
+
*
|
|
9
|
+
* This registry is the single source of truth for:
|
|
10
|
+
* 1. The default `repo_id` baked into each node's `model` prop default.
|
|
11
|
+
* 2. The "recommended" entries returned by the
|
|
12
|
+
* `models.transformersJs.byType` tRPC endpoint.
|
|
13
|
+
*/
|
|
14
|
+
export interface TjsModelRef {
|
|
15
|
+
/** HuggingFace repo id, e.g. `Xenova/whisper-tiny.en`. */
|
|
16
|
+
repo_id: string;
|
|
17
|
+
/** Optional sub-path / file selector (rare for Transformers.js). */
|
|
18
|
+
path?: string | null;
|
|
19
|
+
}
|
|
20
|
+
/** All known `tjs.*` model types. */
|
|
21
|
+
export declare const TJS_MODEL_TYPES: readonly string[];
|
|
22
|
+
/** Recommended models for a given `tjs.*` type, or empty if unknown. */
|
|
23
|
+
export declare function recommendedFor(modelType: string): readonly TjsModelRef[];
|
|
24
|
+
/**
|
|
25
|
+
* Default repo id for a `tjs.*` type (the first recommendation). Used as the
|
|
26
|
+
* baked-in default value for each node's `model` prop so the prop default and
|
|
27
|
+
* the picker's "recommended" entries can never drift.
|
|
28
|
+
*
|
|
29
|
+
* Throws if `modelType` is not registered — this is a programming error.
|
|
30
|
+
*/
|
|
31
|
+
export declare function defaultRepoFor(modelType: string): string;
|
|
32
|
+
//# sourceMappingURL=recommended-models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recommended-models.d.ts","sourceRoot":"","sources":["../src/recommended-models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,WAAW;IAC1B,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AA2HD,qCAAqC;AACrC,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAAwB,CAAC;AAEtE,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,WAAW,EAAE,CAExE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CASxD"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curated recommended-model lists for each `tjs.*` task type.
|
|
3
|
+
*
|
|
4
|
+
* Transformers.js requires ONNX-exported repos (the `Xenova/*` and
|
|
5
|
+
* `onnx-community/*` mirrors are the canonical sources). The Python-side
|
|
6
|
+
* `nodetool-huggingface` recommended lists are mostly PyTorch-only and would
|
|
7
|
+
* fail to load here, so we maintain a parallel ONNX-compatible registry.
|
|
8
|
+
*
|
|
9
|
+
* This registry is the single source of truth for:
|
|
10
|
+
* 1. The default `repo_id` baked into each node's `model` prop default.
|
|
11
|
+
* 2. The "recommended" entries returned by the
|
|
12
|
+
* `models.transformersJs.byType` tRPC endpoint.
|
|
13
|
+
*/
|
|
14
|
+
const MODELS = {
|
|
15
|
+
"tjs.text_classification": [
|
|
16
|
+
{ repo_id: "Xenova/distilbert-base-uncased-finetuned-sst-2-english" },
|
|
17
|
+
{ repo_id: "Xenova/twitter-roberta-base-sentiment-latest" },
|
|
18
|
+
{ repo_id: "Xenova/bert-base-multilingual-uncased-sentiment" },
|
|
19
|
+
{ repo_id: "Xenova/toxic-bert" }
|
|
20
|
+
],
|
|
21
|
+
"tjs.token_classification": [
|
|
22
|
+
{ repo_id: "Xenova/bert-base-multilingual-cased-ner-hrl" },
|
|
23
|
+
{ repo_id: "Xenova/bert-base-NER" },
|
|
24
|
+
{ repo_id: "Xenova/distilbert-base-multilingual-cased-ner-hrl" }
|
|
25
|
+
],
|
|
26
|
+
"tjs.question_answering": [
|
|
27
|
+
{ repo_id: "Xenova/distilbert-base-uncased-distilled-squad" },
|
|
28
|
+
{ repo_id: "Xenova/distilbert-base-cased-distilled-squad" },
|
|
29
|
+
{ repo_id: "Xenova/bert-large-uncased-whole-word-masking-finetuned-squad" }
|
|
30
|
+
],
|
|
31
|
+
"tjs.summarization": [
|
|
32
|
+
{ repo_id: "Xenova/distilbart-cnn-6-6" },
|
|
33
|
+
{ repo_id: "Xenova/distilbart-cnn-12-6" },
|
|
34
|
+
{ repo_id: "Xenova/bart-large-cnn" },
|
|
35
|
+
{ repo_id: "Xenova/t5-small" }
|
|
36
|
+
],
|
|
37
|
+
"tjs.translation": [
|
|
38
|
+
{ repo_id: "Xenova/nllb-200-distilled-600M" },
|
|
39
|
+
{ repo_id: "Xenova/m2m100_418M" },
|
|
40
|
+
{ repo_id: "Xenova/opus-mt-en-de" },
|
|
41
|
+
{ repo_id: "Xenova/opus-mt-en-fr" },
|
|
42
|
+
{ repo_id: "Xenova/t5-base" }
|
|
43
|
+
],
|
|
44
|
+
"tjs.text_generation": [
|
|
45
|
+
{ repo_id: "onnx-community/Qwen3.5-2B-ONNX" },
|
|
46
|
+
{ repo_id: "onnx-community/Qwen3.5-4B-ONNX" },
|
|
47
|
+
{ repo_id: "onnx-community/gemma-4-E2B-it-ONNX" },
|
|
48
|
+
{ repo_id: "onnx-community/gemma-4-E4B-it-ONNX" },
|
|
49
|
+
{ repo_id: "HuggingFaceTB/SmolLM3-3B-ONNX" }
|
|
50
|
+
],
|
|
51
|
+
"tjs.fill_mask": [
|
|
52
|
+
{ repo_id: "Xenova/bert-base-uncased" },
|
|
53
|
+
{ repo_id: "Xenova/distilbert-base-uncased" },
|
|
54
|
+
{ repo_id: "Xenova/roberta-base" }
|
|
55
|
+
],
|
|
56
|
+
"tjs.feature_extraction": [
|
|
57
|
+
{ repo_id: "Xenova/all-MiniLM-L6-v2" },
|
|
58
|
+
{ repo_id: "nomic-ai/nomic-embed-text-v1.5" },
|
|
59
|
+
{ repo_id: "Snowflake/snowflake-arctic-embed-m" },
|
|
60
|
+
{ repo_id: "mixedbread-ai/mxbai-embed-xsmall-v1" },
|
|
61
|
+
{ repo_id: "Xenova/bge-base-en-v1.5" },
|
|
62
|
+
{ repo_id: "Xenova/all-mpnet-base-v2" }
|
|
63
|
+
],
|
|
64
|
+
"tjs.zero_shot_classification": [
|
|
65
|
+
{ repo_id: "Xenova/distilbert-base-uncased-mnli" },
|
|
66
|
+
{ repo_id: "Xenova/bart-large-mnli" },
|
|
67
|
+
{ repo_id: "Xenova/mDeBERTa-v3-base-mnli-xnli" },
|
|
68
|
+
{ repo_id: "Xenova/nli-deberta-v3-base" }
|
|
69
|
+
],
|
|
70
|
+
"tjs.image_classification": [
|
|
71
|
+
{ repo_id: "Xenova/vit-base-patch16-224" },
|
|
72
|
+
{ repo_id: "Xenova/resnet-50" },
|
|
73
|
+
{ repo_id: "Xenova/mobilevit-small" },
|
|
74
|
+
{ repo_id: "Xenova/swin-tiny-patch4-window7-224" },
|
|
75
|
+
{ repo_id: "Xenova/nsfw_image_detection" }
|
|
76
|
+
],
|
|
77
|
+
"tjs.object_detection": [
|
|
78
|
+
{ repo_id: "Xenova/detr-resnet-50" },
|
|
79
|
+
{ repo_id: "Xenova/detr-resnet-101" },
|
|
80
|
+
{ repo_id: "Xenova/yolos-tiny" },
|
|
81
|
+
{ repo_id: "Xenova/yolos-small" },
|
|
82
|
+
{ repo_id: "Xenova/table-transformer-detection" }
|
|
83
|
+
],
|
|
84
|
+
"tjs.image_to_text": [
|
|
85
|
+
{ repo_id: "onnx-community/Florence-2-base-ft" },
|
|
86
|
+
{ repo_id: "onnx-community/Florence-2-large-ft" },
|
|
87
|
+
{ repo_id: "Xenova/blip-image-captioning-base" },
|
|
88
|
+
{ repo_id: "Xenova/blip-image-captioning-large" },
|
|
89
|
+
{ repo_id: "Xenova/trocr-small-printed" }
|
|
90
|
+
],
|
|
91
|
+
"tjs.zero_shot_image_classification": [
|
|
92
|
+
{ repo_id: "onnx-community/siglip2-base-patch16-256-ONNX" },
|
|
93
|
+
{ repo_id: "onnx-community/siglip2-base-patch16-384-ONNX" },
|
|
94
|
+
{ repo_id: "onnx-community/siglip2-large-patch16-384-ONNX" },
|
|
95
|
+
{ repo_id: "Xenova/clip-vit-base-patch32" },
|
|
96
|
+
{ repo_id: "Xenova/clip-vit-large-patch14" }
|
|
97
|
+
],
|
|
98
|
+
"tjs.automatic_speech_recognition": [
|
|
99
|
+
{ repo_id: "onnx-community/whisper-large-v3-turbo" },
|
|
100
|
+
{ repo_id: "onnx-community/moonshine-base-ONNX" },
|
|
101
|
+
{ repo_id: "onnx-community/moonshine-tiny-ONNX" },
|
|
102
|
+
{ repo_id: "Xenova/whisper-base" },
|
|
103
|
+
{ repo_id: "Xenova/whisper-tiny.en" },
|
|
104
|
+
{ repo_id: "Xenova/whisper-small.en" }
|
|
105
|
+
],
|
|
106
|
+
"tjs.audio_classification": [
|
|
107
|
+
{ repo_id: "Xenova/wav2vec2-base-superb-er" },
|
|
108
|
+
{ repo_id: "Xenova/wav2vec2-base-superb-ks" },
|
|
109
|
+
{ repo_id: "Xenova/ast-finetuned-audioset-10-10-0.4593" }
|
|
110
|
+
],
|
|
111
|
+
"tjs.text_to_speech": [
|
|
112
|
+
{ repo_id: "onnx-community/Kokoro-82M-v1.0-ONNX" },
|
|
113
|
+
{ repo_id: "Xenova/speecht5_tts" },
|
|
114
|
+
{ repo_id: "Xenova/mms-tts-eng" },
|
|
115
|
+
{ repo_id: "Xenova/mms-tts-fra" },
|
|
116
|
+
{ repo_id: "Xenova/mms-tts-deu" }
|
|
117
|
+
]
|
|
118
|
+
};
|
|
119
|
+
/** All known `tjs.*` model types. */
|
|
120
|
+
export const TJS_MODEL_TYPES = Object.keys(MODELS);
|
|
121
|
+
/** Recommended models for a given `tjs.*` type, or empty if unknown. */
|
|
122
|
+
export function recommendedFor(modelType) {
|
|
123
|
+
return MODELS[modelType] ?? [];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Default repo id for a `tjs.*` type (the first recommendation). Used as the
|
|
127
|
+
* baked-in default value for each node's `model` prop so the prop default and
|
|
128
|
+
* the picker's "recommended" entries can never drift.
|
|
129
|
+
*
|
|
130
|
+
* Throws if `modelType` is not registered — this is a programming error.
|
|
131
|
+
*/
|
|
132
|
+
export function defaultRepoFor(modelType) {
|
|
133
|
+
const list = MODELS[modelType];
|
|
134
|
+
if (!list || list.length === 0) {
|
|
135
|
+
throw new Error(`defaultRepoFor: no recommended models registered for "${modelType}". ` +
|
|
136
|
+
`Add an entry to recommended-models.ts.`);
|
|
137
|
+
}
|
|
138
|
+
return list[0].repo_id;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=recommended-models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recommended-models.js","sourceRoot":"","sources":["../src/recommended-models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH,MAAM,MAAM,GAA2C;IACrD,yBAAyB,EAAE;QACzB,EAAE,OAAO,EAAE,wDAAwD,EAAE;QACrE,EAAE,OAAO,EAAE,8CAA8C,EAAE;QAC3D,EAAE,OAAO,EAAE,iDAAiD,EAAE;QAC9D,EAAE,OAAO,EAAE,mBAAmB,EAAE;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C,EAAE;QACjD,EAAE,OAAO,EAAE,oCAAoC,EAAE;QACjD,EAAE,OAAO,EAAE,qBAAqB,EAAE;QAClC,EAAE,OAAO,EAAE,wBAAwB,EAAE;QACrC,EAAE,OAAO,EAAE,yBAAyB,EAAE;KACvC;IAED,0BAA0B,EAAE;QAC1B,EAAE,OAAO,EAAE,gCAAgC,EAAE;QAC7C,EAAE,OAAO,EAAE,gCAAgC,EAAE;QAC7C,EAAE,OAAO,EAAE,4CAA4C,EAAE;KAC1D;IAED,oBAAoB,EAAE;QACpB,EAAE,OAAO,EAAE,qCAAqC,EAAE;QAClD,EAAE,OAAO,EAAE,qBAAqB,EAAE;QAClC,EAAE,OAAO,EAAE,oBAAoB,EAAE;QACjC,EAAE,OAAO,EAAE,oBAAoB,EAAE;QACjC,EAAE,OAAO,EAAE,oBAAoB,EAAE;KAClC;CACF,CAAC;AAEF,qCAAqC;AACrC,MAAM,CAAC,MAAM,eAAe,GAAsB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEtE,wEAAwE;AACxE,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC9C,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAC/B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,yDAAyD,SAAS,KAAK;YACrE,wCAAwC,CAC3C,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Download a Transformers.js model into the TJS flat cache layout.
|
|
3
|
+
*
|
|
4
|
+
* Transformers.js itself decides which files (and which quantization variant)
|
|
5
|
+
* a given task needs. We piggy-back on its loader: instantiating the pipeline
|
|
6
|
+
* once writes every required file to `env.cacheDir` in the flat
|
|
7
|
+
* `{cacheDir}/{org}/{repo}/...` layout, after which subsequent inference runs
|
|
8
|
+
* can load the model offline.
|
|
9
|
+
*
|
|
10
|
+
* Progress is forwarded via `@huggingface/transformers`'s `progress_callback`.
|
|
11
|
+
*/
|
|
12
|
+
import { getPipeline } from "./transformers-base.js";
|
|
13
|
+
/** Map a `tjs.<task>` model type to the Transformers.js pipeline task name. */
|
|
14
|
+
export declare function tjsTypeToPipelineTask(modelType: string): string | null;
|
|
15
|
+
export interface TjsDownloadProgress {
|
|
16
|
+
/** "initiate" | "download" | "progress" | "done" | "ready" — passed straight through from TJS. */
|
|
17
|
+
status: string;
|
|
18
|
+
file?: string;
|
|
19
|
+
/** Cumulative bytes downloaded for `file`, when known. */
|
|
20
|
+
loaded?: number;
|
|
21
|
+
/** Total bytes for `file`, when known. */
|
|
22
|
+
total?: number;
|
|
23
|
+
/** Progress percent (0..100) for `file`, when known. */
|
|
24
|
+
progress?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface TjsDownloadOptions {
|
|
27
|
+
/** Pipeline task hint. Required if `modelType` is not a `tjs.*` type. */
|
|
28
|
+
task?: string;
|
|
29
|
+
/** `tjs.<task>` model type. Used when `task` is not provided. */
|
|
30
|
+
modelType?: string;
|
|
31
|
+
/** Quantization preference forwarded to TJS (e.g. `"q4"`, `"fp16"`). */
|
|
32
|
+
dtype?: string;
|
|
33
|
+
onProgress?: (update: TjsDownloadProgress) => void;
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Materialize a Transformers.js model in the cache.
|
|
38
|
+
*
|
|
39
|
+
* Resolves once the underlying `pipeline()` call completes — which means every
|
|
40
|
+
* file the runtime needed has been fetched and written to disk.
|
|
41
|
+
*/
|
|
42
|
+
export declare function downloadTransformersJsModel(repoId: string, opts?: TjsDownloadOptions): Promise<void>;
|
|
43
|
+
export { getPipeline };
|
|
44
|
+
//# sourceMappingURL=tjs-downloader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tjs-downloader.d.ts","sourceRoot":"","sources":["../src/tjs-downloader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,WAAW,EAAoB,MAAM,wBAAwB,CAAC;AAEvE,+EAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKtE;AAED,MAAM,WAAW,mBAAmB;IAClC,kGAAkG;IAClG,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACnD,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,kBAAuB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA2Df;AAID,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Download a Transformers.js model into the TJS flat cache layout.
|
|
3
|
+
*
|
|
4
|
+
* Transformers.js itself decides which files (and which quantization variant)
|
|
5
|
+
* a given task needs. We piggy-back on its loader: instantiating the pipeline
|
|
6
|
+
* once writes every required file to `env.cacheDir` in the flat
|
|
7
|
+
* `{cacheDir}/{org}/{repo}/...` layout, after which subsequent inference runs
|
|
8
|
+
* can load the model offline.
|
|
9
|
+
*
|
|
10
|
+
* Progress is forwarded via `@huggingface/transformers`'s `progress_callback`.
|
|
11
|
+
*/
|
|
12
|
+
import { getPipeline, loadTransformers } from "./transformers-base.js";
|
|
13
|
+
/** Map a `tjs.<task>` model type to the Transformers.js pipeline task name. */
|
|
14
|
+
export function tjsTypeToPipelineTask(modelType) {
|
|
15
|
+
if (!modelType.startsWith("tjs."))
|
|
16
|
+
return null;
|
|
17
|
+
const rest = modelType.slice(4);
|
|
18
|
+
if (!rest)
|
|
19
|
+
return null;
|
|
20
|
+
return rest.replace(/_/g, "-");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Materialize a Transformers.js model in the cache.
|
|
24
|
+
*
|
|
25
|
+
* Resolves once the underlying `pipeline()` call completes — which means every
|
|
26
|
+
* file the runtime needed has been fetched and written to disk.
|
|
27
|
+
*/
|
|
28
|
+
export async function downloadTransformersJsModel(repoId, opts = {}) {
|
|
29
|
+
if (!repoId) {
|
|
30
|
+
throw new Error("repoId is required");
|
|
31
|
+
}
|
|
32
|
+
const task = opts.task ?? (opts.modelType ? tjsTypeToPipelineTask(opts.modelType) : null);
|
|
33
|
+
if (!task) {
|
|
34
|
+
throw new Error(`Cannot determine pipeline task for repoId="${repoId}" (modelType="${opts.modelType ?? ""}")`);
|
|
35
|
+
}
|
|
36
|
+
if (opts.signal?.aborted) {
|
|
37
|
+
throw new DOMException("Aborted", "AbortError");
|
|
38
|
+
}
|
|
39
|
+
const onProgress = opts.onProgress;
|
|
40
|
+
const wrappedProgress = onProgress
|
|
41
|
+
? (info) => {
|
|
42
|
+
onProgress({
|
|
43
|
+
status: typeof info.status === "string" ? info.status : "progress",
|
|
44
|
+
file: typeof info.file === "string" ? info.file : undefined,
|
|
45
|
+
loaded: typeof info.loaded === "number" ? info.loaded : undefined,
|
|
46
|
+
total: typeof info.total === "number" ? info.total : undefined,
|
|
47
|
+
progress: typeof info.progress === "number" ? info.progress : undefined
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
: undefined;
|
|
51
|
+
// We intentionally bypass `getPipeline`'s internal caching by instantiating
|
|
52
|
+
// through the underlying transformers module directly — we want a fresh
|
|
53
|
+
// load that exposes its progress_callback, even if a pipeline for the same
|
|
54
|
+
// (task, model) already exists in the cache.
|
|
55
|
+
const transformers = await loadTransformers();
|
|
56
|
+
const pipelineOptions = {};
|
|
57
|
+
if (opts.dtype)
|
|
58
|
+
pipelineOptions.dtype = opts.dtype;
|
|
59
|
+
if (wrappedProgress)
|
|
60
|
+
pipelineOptions.progress_callback = wrappedProgress;
|
|
61
|
+
// Cooperate with cancellation: poll the signal between awaits.
|
|
62
|
+
const abortPromise = opts.signal
|
|
63
|
+
? new Promise((_, reject) => {
|
|
64
|
+
const onAbort = () => reject(new DOMException("Aborted", "AbortError"));
|
|
65
|
+
if (opts.signal.aborted) {
|
|
66
|
+
onAbort();
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
opts.signal.addEventListener("abort", onAbort, { once: true });
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
: null;
|
|
73
|
+
const loadPromise = transformers.pipeline(task, repoId, pipelineOptions);
|
|
74
|
+
if (abortPromise) {
|
|
75
|
+
await Promise.race([loadPromise, abortPromise]);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
await loadPromise;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Re-export to make `getPipeline` reachable for downstream code that might
|
|
82
|
+
// want to "warm" the cache by invoking it directly.
|
|
83
|
+
export { getPipeline };
|
|
84
|
+
//# sourceMappingURL=tjs-downloader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tjs-downloader.js","sourceRoot":"","sources":["../src/tjs-downloader.ts"],"names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AC;iBAAM,CAAC;gBACN,IAAI,CAAC,MAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAClE,CAAC;QACH,CAAC,CAAC;QACJ,CAAC,CAAC,IAAI,CAAC;IAET,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;IAEzE,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;IAClD,CAAC;SAAM,CAAC;QACN,MAAM,WAAW,CAAC;IACpB,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,oDAAoD;AACpD,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { ProcessingContext } from "@nodetool-ai/runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Shared helpers for Transformers.js nodes.
|
|
4
|
+
*
|
|
5
|
+
* The `@huggingface/transformers` package is loaded lazily so the rest of the
|
|
6
|
+
* package can be imported, type-checked and registered even when the optional
|
|
7
|
+
* runtime dependency is not installed (the `pipeline()` call will throw a
|
|
8
|
+
* descriptive error at execution time instead).
|
|
9
|
+
*/
|
|
10
|
+
type PipelineFn = (task: string, model?: string, options?: Record<string, unknown>) => Promise<unknown>;
|
|
11
|
+
type TransformersEnv = {
|
|
12
|
+
cacheDir?: string;
|
|
13
|
+
allowRemoteModels?: boolean;
|
|
14
|
+
allowLocalModels?: boolean;
|
|
15
|
+
};
|
|
16
|
+
type TransformersModule = {
|
|
17
|
+
pipeline: PipelineFn;
|
|
18
|
+
env?: TransformersEnv;
|
|
19
|
+
RawImage?: {
|
|
20
|
+
fromBlob(blob: Blob): Promise<unknown>;
|
|
21
|
+
fromURL(url: string): Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
TextStreamer?: new (tokenizer: unknown, options?: {
|
|
24
|
+
skip_prompt?: boolean;
|
|
25
|
+
skip_special_tokens?: boolean;
|
|
26
|
+
callback_function?: (text: string) => void;
|
|
27
|
+
token_callback_function?: (tokens: unknown) => void;
|
|
28
|
+
}) => unknown;
|
|
29
|
+
InterruptableStoppingCriteria?: new () => {
|
|
30
|
+
interrupt(): void;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Override the Transformers.js cache directory at runtime. Pass `null` to
|
|
35
|
+
* revert to the default resolved by `getDefaultTransformersJsCacheDir()`.
|
|
36
|
+
*
|
|
37
|
+
* Must be called before the first `loadTransformers()` to take effect, since
|
|
38
|
+
* `env.cacheDir` is set on the singleton module on first import.
|
|
39
|
+
*/
|
|
40
|
+
export declare function setTransformersJsCacheDir(dir: string | null): void;
|
|
41
|
+
/** Resolve the cache directory: explicit override → env var → data-dir default. */
|
|
42
|
+
export declare function getTransformersJsCacheDir(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Lazily import `@huggingface/transformers`. Cached after first load.
|
|
45
|
+
*
|
|
46
|
+
* On first load we point `env.cacheDir` at the resolved Nodetool cache
|
|
47
|
+
* directory (default: `<data-dir>/transformers-js-cache`) and ensure the
|
|
48
|
+
* directory exists. This keeps downloaded ONNX models in a predictable,
|
|
49
|
+
* persistent location instead of a transient `./.cache` next to cwd.
|
|
50
|
+
*
|
|
51
|
+
* Throws a clear error if the package is not installed.
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadTransformers(): Promise<TransformersModule>;
|
|
54
|
+
/**
|
|
55
|
+
* Override the loaded transformers module. Intended for tests so they can
|
|
56
|
+
* stub `pipeline` and `RawImage` without installing the
|
|
57
|
+
* heavyweight optional dependency.
|
|
58
|
+
*/
|
|
59
|
+
export declare function __setTransformersModuleForTesting(fake: TransformersModule | null): void;
|
|
60
|
+
export interface PipelineOptions {
|
|
61
|
+
task: string;
|
|
62
|
+
model?: string;
|
|
63
|
+
dtype?: string;
|
|
64
|
+
device?: string;
|
|
65
|
+
revision?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build (or reuse) a Transformers.js pipeline for the given task/model.
|
|
69
|
+
*
|
|
70
|
+
* Pipelines are cached globally by their (task, model, dtype, device, revision)
|
|
71
|
+
* tuple. Loading large models is expensive, so reusing pipelines across
|
|
72
|
+
* invocations is essential for sensible performance.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getPipeline(options: PipelineOptions): Promise<unknown>;
|
|
75
|
+
/** Reset the pipeline cache. Intended for tests. */
|
|
76
|
+
export declare function clearPipelineCache(): void;
|
|
77
|
+
export declare const DTYPE_VALUES: string[];
|
|
78
|
+
export declare const DEVICE_VALUES: string[];
|
|
79
|
+
/**
|
|
80
|
+
* Translate the user-facing "auto" placeholder into `undefined` so we keep
|
|
81
|
+
* Transformers.js' own default selection logic.
|
|
82
|
+
*/
|
|
83
|
+
export declare function normalizeOption(value: unknown): string | undefined;
|
|
84
|
+
export type ImageRefLike = {
|
|
85
|
+
uri?: string;
|
|
86
|
+
data?: Uint8Array | string;
|
|
87
|
+
mimeType?: string;
|
|
88
|
+
};
|
|
89
|
+
export type AudioRefLike = {
|
|
90
|
+
uri?: string;
|
|
91
|
+
data?: Uint8Array | string;
|
|
92
|
+
mimeType?: string;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Resolve a media ref to raw bytes, consulting (in order):
|
|
96
|
+
* 1. inline `data` (base64 string or Uint8Array)
|
|
97
|
+
* 2. `context.storage` for opaque URIs managed by the runtime
|
|
98
|
+
* 3. `file://` URIs read from disk
|
|
99
|
+
* 4. `http(s)://` URIs fetched over the network
|
|
100
|
+
* 5. `data:` URIs (base64 inline)
|
|
101
|
+
*/
|
|
102
|
+
export declare function loadMediaBytes(ref: ImageRefLike | AudioRefLike | undefined, context?: ProcessingContext): Promise<Uint8Array>;
|
|
103
|
+
/** Convert raw image bytes into a Transformers.js RawImage instance. */
|
|
104
|
+
export declare function bytesToRawImage(bytes: Uint8Array, mimeType?: string): Promise<unknown>;
|
|
105
|
+
/** Resolve an image ref into a RawImage suitable for pipelines. */
|
|
106
|
+
export declare function loadRawImage(ref: ImageRefLike | undefined, context?: ProcessingContext): Promise<unknown>;
|
|
107
|
+
/**
|
|
108
|
+
* Resolve an audio ref into a mono Float32Array sampled at the requested
|
|
109
|
+
* rate.
|
|
110
|
+
*
|
|
111
|
+
* Transformers.js's own `read_audio()` helper requires the browser
|
|
112
|
+
* `AudioContext` API and does not work in Node, even when passed an
|
|
113
|
+
* ArrayBuffer (it ends up calling `decodeAudioData`). The official guidance
|
|
114
|
+
* is to decode audio externally and feed the pipeline a Float32Array
|
|
115
|
+
* directly:
|
|
116
|
+
* https://huggingface.co/docs/transformers.js/guides/node-audio-processing
|
|
117
|
+
*
|
|
118
|
+
* Decode strategy:
|
|
119
|
+
* 1. Fast path — if the bytes are already a WAV (PCM 8/16-bit), parse
|
|
120
|
+
* them in-process. No subprocess overhead.
|
|
121
|
+
* 2. Fallback — for any other format (mp3 / m4a / flac / ogg / etc.)
|
|
122
|
+
* shell out to ffmpeg to convert to mono 16-bit WAV at the target
|
|
123
|
+
* rate, then parse the result. Letting ffmpeg do the resampling
|
|
124
|
+
* avoids a second pass and gives much better quality than the linear
|
|
125
|
+
* resampler used for the in-process WAV path.
|
|
126
|
+
*/
|
|
127
|
+
export declare function loadAudioSamples(ref: AudioRefLike | undefined, samplingRate: number, context?: ProcessingContext): Promise<Float32Array>;
|
|
128
|
+
export declare function ensureArray<T>(value: T | T[] | undefined | null): T[];
|
|
129
|
+
export declare function asNumber(value: unknown, fallback: number): number;
|
|
130
|
+
export declare function asString(value: unknown, fallback?: string): string;
|
|
131
|
+
/**
|
|
132
|
+
* Shape of an `hf.*` typed model value as produced by the web Hugging Face
|
|
133
|
+
* model picker. The picker emits an object; legacy graphs may still hold a
|
|
134
|
+
* plain string repo id, so we accept both.
|
|
135
|
+
*/
|
|
136
|
+
export type HfModelRef = {
|
|
137
|
+
type?: string;
|
|
138
|
+
repo_id?: string;
|
|
139
|
+
path?: string | null;
|
|
140
|
+
variant?: string | null;
|
|
141
|
+
allow_patterns?: string[] | null;
|
|
142
|
+
ignore_patterns?: string[] | null;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Extract a Hugging Face repo id from a property value. Accepts either the
|
|
146
|
+
* object emitted by the model picker (`{ repo_id, ... }`) or a bare string
|
|
147
|
+
* for backwards compatibility with graphs that predate the picker.
|
|
148
|
+
*/
|
|
149
|
+
export declare function extractRepoId(value: unknown): string;
|
|
150
|
+
/**
|
|
151
|
+
* Build a default value for a `tjs.<task>` typed `model` prop. The web UI
|
|
152
|
+
* uses the `type` discriminator to render the matching model picker.
|
|
153
|
+
*/
|
|
154
|
+
export declare function tjsModelDefault(type: string, repoId: string): Required<Pick<HfModelRef, "type" | "repo_id">> & Pick<HfModelRef, "path" | "variant" | "allow_patterns" | "ignore_patterns">;
|
|
155
|
+
export {};
|
|
156
|
+
//# sourceMappingURL=transformers-base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformers-base.d.ts","sourceRoot":"","sources":["../src/transformers-base.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D;;;;;;;GAOG;AAEH,KAAK,UAAU,GAAG,CAChB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,KAAK,eAAe,GAAG;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,UAAU,CAAC;IACrB,GAAG,CAAC,EAAE,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