@workglow/huggingface-transformers 0.2.36 → 0.3.0
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/ai/HuggingFaceTransformersProvider.d.ts +1 -1
- package/dist/ai/HuggingFaceTransformersProvider.d.ts.map +1 -1
- package/dist/ai/HuggingFaceTransformersQueuedProvider.d.ts +1 -1
- package/dist/ai/HuggingFaceTransformersQueuedProvider.d.ts.map +1 -1
- package/dist/ai/common/HFT_Chat.d.ts.map +1 -1
- package/dist/ai/common/HFT_ImageEmbedding.d.ts.map +1 -1
- package/dist/ai/common/HFT_ImageSegmentation.d.ts.map +1 -1
- package/dist/ai/registerHuggingFaceTransformersWorker.d.ts.map +1 -1
- package/dist/ai-runtime.js +47 -24
- package/dist/ai-runtime.js.map +15 -15
- package/dist/ai.js +46 -23
- package/dist/ai.js.map +14 -14
- package/package.json +11 -11
package/dist/ai.js
CHANGED
|
@@ -987,21 +987,6 @@ var HFT_BackgroundRemoval = async (input, model, signal, emit) => {
|
|
|
987
987
|
// src/ai/common/HFT_Chat.ts
|
|
988
988
|
init_HFT_Pipeline();
|
|
989
989
|
|
|
990
|
-
// src/ai/common/HFT_ToolCalling.ts
|
|
991
|
-
init_HFT_Pipeline();
|
|
992
|
-
import {
|
|
993
|
-
buildToolDescription,
|
|
994
|
-
filterValidToolCalls,
|
|
995
|
-
toTextFlatMessages
|
|
996
|
-
} from "@workglow/ai/worker";
|
|
997
|
-
import {
|
|
998
|
-
adaptParserResult,
|
|
999
|
-
forcedToolSelection,
|
|
1000
|
-
getAvailableParsers,
|
|
1001
|
-
getGenerationPrefix,
|
|
1002
|
-
parseToolCalls
|
|
1003
|
-
} from "@workglow/ai/provider-utils";
|
|
1004
|
-
|
|
1005
990
|
// src/ai/common/HFT_Streaming.ts
|
|
1006
991
|
function createStreamingTextStreamer(tokenizer, onText, textStreamer) {
|
|
1007
992
|
return new textStreamer(tokenizer, {
|
|
@@ -1025,6 +1010,19 @@ function createTextStreamer(tokenizer, updateProgress, textStreamer) {
|
|
|
1025
1010
|
}
|
|
1026
1011
|
|
|
1027
1012
|
// src/ai/common/HFT_ToolCalling.ts
|
|
1013
|
+
init_HFT_Pipeline();
|
|
1014
|
+
import {
|
|
1015
|
+
adaptParserResult,
|
|
1016
|
+
forcedToolSelection,
|
|
1017
|
+
getAvailableParsers,
|
|
1018
|
+
getGenerationPrefix,
|
|
1019
|
+
parseToolCalls
|
|
1020
|
+
} from "@workglow/ai/provider-utils";
|
|
1021
|
+
import {
|
|
1022
|
+
buildToolDescription,
|
|
1023
|
+
filterValidToolCalls,
|
|
1024
|
+
toTextFlatMessages
|
|
1025
|
+
} from "@workglow/ai/worker";
|
|
1028
1026
|
function getModelTextCandidates(model) {
|
|
1029
1027
|
return [model.model_id, model.title, model.description, model.provider_config.model_path].filter((value) => typeof value === "string" && value.length > 0).map((value) => value.toLowerCase());
|
|
1030
1028
|
}
|
|
@@ -1444,8 +1442,8 @@ var HFT_ImageClassification = async (input, model, signal, emit) => {
|
|
|
1444
1442
|
|
|
1445
1443
|
// src/ai/common/HFT_ImageEmbedding.ts
|
|
1446
1444
|
init_HFT_Pipeline();
|
|
1447
|
-
import { getLogger as getLogger3 } from "@workglow/util/worker";
|
|
1448
1445
|
import { imageValueToBlob as imageValueToBlob3 } from "@workglow/ai/provider-utils";
|
|
1446
|
+
import { getLogger as getLogger3 } from "@workglow/util/worker";
|
|
1449
1447
|
var HFT_ImageEmbedding = async (input, model, signal, emit) => {
|
|
1450
1448
|
const logger = getLogger3();
|
|
1451
1449
|
const timerLabel = `hft:ImageEmbedding:${model?.provider_config.model_path}`;
|
|
@@ -1477,6 +1475,29 @@ var HFT_ImageEmbedding = async (input, model, signal, emit) => {
|
|
|
1477
1475
|
// src/ai/common/HFT_ImageSegmentation.ts
|
|
1478
1476
|
init_HFT_Pipeline();
|
|
1479
1477
|
import { imageValueToBlob as imageValueToBlob4 } from "@workglow/ai/provider-utils";
|
|
1478
|
+
import { imageValueFromBuffer } from "@workglow/util/media";
|
|
1479
|
+
function rawImageToImageValue(image) {
|
|
1480
|
+
const raw = image;
|
|
1481
|
+
const pixelCount = raw.width * raw.height;
|
|
1482
|
+
const rgba = new Uint8Array(pixelCount * 4);
|
|
1483
|
+
for (let pixel = 0;pixel < pixelCount; pixel++) {
|
|
1484
|
+
const sourceOffset = pixel * raw.channels;
|
|
1485
|
+
const targetOffset = pixel * 4;
|
|
1486
|
+
if (raw.channels === 1) {
|
|
1487
|
+
const value = raw.data[sourceOffset] ?? 0;
|
|
1488
|
+
rgba[targetOffset] = value;
|
|
1489
|
+
rgba[targetOffset + 1] = value;
|
|
1490
|
+
rgba[targetOffset + 2] = value;
|
|
1491
|
+
rgba[targetOffset + 3] = 255;
|
|
1492
|
+
} else {
|
|
1493
|
+
rgba[targetOffset] = raw.data[sourceOffset] ?? 0;
|
|
1494
|
+
rgba[targetOffset + 1] = raw.data[sourceOffset + 1] ?? raw.data[sourceOffset] ?? 0;
|
|
1495
|
+
rgba[targetOffset + 2] = raw.data[sourceOffset + 2] ?? raw.data[sourceOffset] ?? 0;
|
|
1496
|
+
rgba[targetOffset + 3] = raw.channels >= 4 ? raw.data[sourceOffset + 3] ?? 255 : 255;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
return imageValueFromBuffer(Buffer.from(rgba), "raw-rgba", raw.width, raw.height);
|
|
1500
|
+
}
|
|
1480
1501
|
var HFT_ImageSegmentation = async (input, model, signal, emit) => {
|
|
1481
1502
|
const segmenter = await getPipeline(model, emit, {}, signal);
|
|
1482
1503
|
const imageArg = await imageValueToBlob4(input.image);
|
|
@@ -1485,11 +1506,13 @@ var HFT_ImageSegmentation = async (input, model, signal, emit) => {
|
|
|
1485
1506
|
mask_threshold: input.maskThreshold
|
|
1486
1507
|
});
|
|
1487
1508
|
const masks = Array.isArray(result) ? result : [result];
|
|
1488
|
-
const processedMasks =
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1509
|
+
const processedMasks = masks.map((mask) => {
|
|
1510
|
+
return {
|
|
1511
|
+
label: mask.label || "",
|
|
1512
|
+
score: mask.score || 0,
|
|
1513
|
+
mask: rawImageToImageValue(mask.mask)
|
|
1514
|
+
};
|
|
1515
|
+
});
|
|
1493
1516
|
emit({
|
|
1494
1517
|
type: "finish",
|
|
1495
1518
|
data: {
|
|
@@ -1616,7 +1639,7 @@ var HFT_ModelInfo = async (input, model, _signal, emit) => {
|
|
|
1616
1639
|
};
|
|
1617
1640
|
|
|
1618
1641
|
// src/ai/common/HFT_ModelSearch.ts
|
|
1619
|
-
import {
|
|
1642
|
+
import { mapHfModelResult, searchHfModels } from "@workglow/ai/provider-utils";
|
|
1620
1643
|
var HFT_ModelSearch = async (input, _model, signal, emit) => {
|
|
1621
1644
|
const entries = await searchHfModels(input.query?.trim() ?? "", { filter: "onnx" }, ["siblings"], signal);
|
|
1622
1645
|
const results = entries.map((entry) => {
|
|
@@ -2127,4 +2150,4 @@ export {
|
|
|
2127
2150
|
HF_TRANSFORMERS_ONNX
|
|
2128
2151
|
};
|
|
2129
2152
|
|
|
2130
|
-
//# debugId=
|
|
2153
|
+
//# debugId=F1F15E5800BCD03B64756E2164756E21
|