@workglow/ai-provider 0.0.115 → 0.0.117
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/{HFT_JobRunFns-zkv5fx65.js → HFT_JobRunFns-yx418d60.js} +7 -3
- package/dist/{HFT_JobRunFns-zkv5fx65.js.map → HFT_JobRunFns-yx418d60.js.map} +1 -1
- package/dist/anthropic/common/Anthropic_JobRunFns.d.ts.map +1 -1
- package/dist/anthropic/index.js +97 -17
- package/dist/anthropic/index.js.map +3 -3
- package/dist/google-gemini/common/Gemini_JobRunFns.d.ts.map +1 -1
- package/dist/google-gemini/index.js +106 -16
- package/dist/google-gemini/index.js.map +3 -3
- package/dist/hf-transformers/common/HFT_JobRunFns.d.ts +78 -3
- package/dist/hf-transformers/common/HFT_JobRunFns.d.ts.map +1 -1
- package/dist/hf-transformers/index.js +11 -7
- package/dist/hf-transformers/index.js.map +2 -2
- package/dist/index-m0r2hvfz.js +57 -0
- package/dist/index-m0r2hvfz.js.map +10 -0
- package/dist/{index-zqq3kw0n.js → index-qett8dfp.js} +58 -55
- package/dist/index-qett8dfp.js.map +11 -0
- package/dist/{index-8at2wpp1.js → index-tvb9nd5b.js} +128 -44
- package/dist/index-tvb9nd5b.js.map +10 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -6
- package/dist/index.js.map +7 -4
- package/dist/provider-hf-inference/common/HFI_JobRunFns.d.ts.map +1 -1
- package/dist/provider-hf-inference/index.js +15 -25
- package/dist/provider-hf-inference/index.js.map +3 -3
- package/dist/provider-llamacpp/common/LlamaCpp_JobRunFns.d.ts +3 -1
- package/dist/provider-llamacpp/common/LlamaCpp_JobRunFns.d.ts.map +1 -1
- package/dist/provider-llamacpp/index.js +158 -14
- package/dist/provider-llamacpp/index.js.map +3 -3
- package/dist/provider-ollama/common/Ollama_JobRunFns.browser.d.ts.map +1 -1
- package/dist/provider-ollama/common/Ollama_JobRunFns.d.ts.map +1 -1
- package/dist/provider-ollama/index.browser.js +6 -6
- package/dist/provider-ollama/index.browser.js.map +3 -3
- package/dist/provider-ollama/index.js +14 -21
- package/dist/provider-ollama/index.js.map +3 -3
- package/dist/provider-openai/common/OpenAI_JobRunFns.d.ts +0 -6
- package/dist/provider-openai/common/OpenAI_JobRunFns.d.ts.map +1 -1
- package/dist/provider-openai/index.js +20 -34
- package/dist/provider-openai/index.js.map +3 -3
- package/dist/web-browser/WebBrowserProvider.d.ts +40 -0
- package/dist/web-browser/WebBrowserProvider.d.ts.map +1 -0
- package/dist/web-browser/WebBrowser_Worker.d.ts +7 -0
- package/dist/web-browser/WebBrowser_Worker.d.ts.map +1 -0
- package/dist/web-browser/common/WebBrowser_Constants.d.ts +15 -0
- package/dist/web-browser/common/WebBrowser_Constants.d.ts.map +1 -0
- package/dist/web-browser/common/WebBrowser_JobRunFns.d.ts +20 -0
- package/dist/web-browser/common/WebBrowser_JobRunFns.d.ts.map +1 -0
- package/dist/web-browser/common/WebBrowser_ModelSchema.d.ts +185 -0
- package/dist/web-browser/common/WebBrowser_ModelSchema.d.ts.map +1 -0
- package/dist/web-browser/index.d.ts +11 -0
- package/dist/web-browser/index.d.ts.map +1 -0
- package/dist/web-browser/index.js +457 -0
- package/dist/web-browser/index.js.map +14 -0
- package/package.json +23 -19
- package/dist/index-8at2wpp1.js.map +0 -10
- package/dist/index-dvb390cv.js +0 -58
- package/dist/index-dvb390cv.js.map +0 -10
- package/dist/index-zqq3kw0n.js.map +0 -11
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/hf-transformers/common/HFT_Constants.ts
|
|
2
|
+
var HF_TRANSFORMERS_ONNX = "HF_TRANSFORMERS_ONNX";
|
|
3
|
+
var HTF_CACHE_NAME = "transformers-cache";
|
|
4
|
+
var QuantizationDataType = {
|
|
5
|
+
auto: "auto",
|
|
6
|
+
fp32: "fp32",
|
|
7
|
+
fp16: "fp16",
|
|
8
|
+
q8: "q8",
|
|
9
|
+
int8: "int8",
|
|
10
|
+
uint8: "uint8",
|
|
11
|
+
q4: "q4",
|
|
12
|
+
bnb4: "bnb4",
|
|
13
|
+
q4f16: "q4f16"
|
|
14
|
+
};
|
|
15
|
+
var TextPipelineUseCase = {
|
|
16
|
+
"fill-mask": "fill-mask",
|
|
17
|
+
"token-classification": "token-classification",
|
|
18
|
+
"text-generation": "text-generation",
|
|
19
|
+
"text2text-generation": "text2text-generation",
|
|
20
|
+
"text-classification": "text-classification",
|
|
21
|
+
summarization: "summarization",
|
|
22
|
+
translation: "translation",
|
|
23
|
+
"feature-extraction": "feature-extraction",
|
|
24
|
+
"zero-shot-classification": "zero-shot-classification",
|
|
25
|
+
"question-answering": "question-answering"
|
|
26
|
+
};
|
|
27
|
+
var VisionPipelineUseCase = {
|
|
28
|
+
"background-removal": "background-removal",
|
|
29
|
+
"image-segmentation": "image-segmentation",
|
|
30
|
+
"depth-estimation": "depth-estimation",
|
|
31
|
+
"image-classification": "image-classification",
|
|
32
|
+
"image-to-image": "image-to-image",
|
|
33
|
+
"object-detection": "object-detection",
|
|
34
|
+
"image-feature-extraction": "image-feature-extraction"
|
|
35
|
+
};
|
|
36
|
+
var AudioPipelineUseCase = {
|
|
37
|
+
"audio-classification": "audio-classification",
|
|
38
|
+
"automatic-speech-recognition": "automatic-speech-recognition",
|
|
39
|
+
"text-to-speech": "text-to-speech"
|
|
40
|
+
};
|
|
41
|
+
var MultimodalPipelineUseCase = {
|
|
42
|
+
"document-question-answering": "document-question-answering",
|
|
43
|
+
"image-to-text": "image-to-text",
|
|
44
|
+
"zero-shot-audio-classification": "zero-shot-audio-classification",
|
|
45
|
+
"zero-shot-image-classification": "zero-shot-image-classification",
|
|
46
|
+
"zero-shot-object-detection": "zero-shot-object-detection"
|
|
47
|
+
};
|
|
48
|
+
var PipelineUseCase = {
|
|
49
|
+
...TextPipelineUseCase,
|
|
50
|
+
...VisionPipelineUseCase,
|
|
51
|
+
...AudioPipelineUseCase,
|
|
52
|
+
...MultimodalPipelineUseCase
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { HF_TRANSFORMERS_ONNX, HTF_CACHE_NAME, QuantizationDataType, TextPipelineUseCase, VisionPipelineUseCase, AudioPipelineUseCase, MultimodalPipelineUseCase, PipelineUseCase };
|
|
56
|
+
|
|
57
|
+
//# debugId=297B2C0A21F958E264756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/hf-transformers/common/HFT_Constants.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport const HF_TRANSFORMERS_ONNX = \"HF_TRANSFORMERS_ONNX\";\nexport const HTF_CACHE_NAME = \"transformers-cache\";\n\nexport type QuantizationDataType =\n | \"auto\" // Auto-detect based on environment\n | \"fp32\"\n | \"fp16\"\n | \"q8\"\n | \"int8\"\n | \"uint8\"\n | \"q4\"\n | \"bnb4\"\n | \"q4f16\"; // fp16 model with int4 block weight quantization\n\nexport const QuantizationDataType = {\n auto: \"auto\",\n fp32: \"fp32\",\n fp16: \"fp16\",\n q8: \"q8\",\n int8: \"int8\",\n uint8: \"uint8\",\n q4: \"q4\",\n bnb4: \"bnb4\",\n q4f16: \"q4f16\",\n} as const satisfies Record<QuantizationDataType, QuantizationDataType>;\n\nexport type TextPipelineUseCase =\n | \"fill-mask\" // https://huggingface.co/tasks/fill-mask\n | \"token-classification\" // https://huggingface.co/tasks/token-classification\n | \"text-generation\" // https://huggingface.co/tasks/text-generation#completion-generation-models\n | \"text2text-generation\" // https://huggingface.co/tasks/text-generation#text-to-text-generation-models\n | \"text-classification\" // https://huggingface.co/tasks/text-classification\n | \"summarization\" // https://huggingface.co/tasks/sentence-similarity\n | \"translation\" // https://huggingface.co/tasks/translation\n | \"feature-extraction\" // https://huggingface.co/tasks/feature-extraction\n | \"zero-shot-classification\" // https://huggingface.co/tasks/zero-shot-classification\n | \"question-answering\"; // https://huggingface.co/tasks/question-answering\n\nexport const TextPipelineUseCase = {\n \"fill-mask\": \"fill-mask\",\n \"token-classification\": \"token-classification\",\n \"text-generation\": \"text-generation\",\n \"text2text-generation\": \"text2text-generation\",\n \"text-classification\": \"text-classification\",\n summarization: \"summarization\",\n translation: \"translation\",\n \"feature-extraction\": \"feature-extraction\",\n \"zero-shot-classification\": \"zero-shot-classification\",\n \"question-answering\": \"question-answering\",\n} as const satisfies Record<TextPipelineUseCase, TextPipelineUseCase>;\n\nexport type VisionPipelineUseCase =\n | \"background-removal\" // https://huggingface.co/tasks/image-segmentation#background-removal\n | \"image-segmentation\" // https://huggingface.co/tasks/image-segmentation\n | \"depth-estimation\" // https://huggingface.co/tasks/depth-estimation\n | \"image-classification\" // https://huggingface.co/tasks/image-classification\n | \"image-to-image\" // https://huggingface.co/tasks/image-to-image\n | \"object-detection\" // https://huggingface.co/tasks/object-detection\n | \"image-feature-extraction\"; // https://huggingface.co/tasks/image-feature-extraction\n\nexport const VisionPipelineUseCase = {\n \"background-removal\": \"background-removal\",\n \"image-segmentation\": \"image-segmentation\",\n \"depth-estimation\": \"depth-estimation\",\n \"image-classification\": \"image-classification\",\n \"image-to-image\": \"image-to-image\",\n \"object-detection\": \"object-detection\",\n \"image-feature-extraction\": \"image-feature-extraction\",\n} as const satisfies Record<VisionPipelineUseCase, VisionPipelineUseCase>;\n\nexport type AudioPipelineUseCase =\n | \"audio-classification\" // https://huggingface.co/tasks/audio-classification\n | \"automatic-speech-recognition\" // https://huggingface.co/tasks/automatic-speech-recognition\n | \"text-to-speech\"; // https://huggingface.co/tasks/text-to-speech\n\nexport const AudioPipelineUseCase = {\n \"audio-classification\": \"audio-classification\",\n \"automatic-speech-recognition\": \"automatic-speech-recognition\",\n \"text-to-speech\": \"text-to-speech\",\n} as const satisfies Record<AudioPipelineUseCase, AudioPipelineUseCase>;\n\nexport type MultimodalPipelineUseCase =\n | \"document-question-answering\" // https://huggingface.co/tasks/document-question-answering\n | \"image-to-text\" // https://huggingface.co/tasks/image-to-text\n | \"zero-shot-audio-classification\" // https://huggingface.co/tasks/zero-shot-audio-classification\n | \"zero-shot-image-classification\" // https://huggingface.co/tasks/zero-shot-image-classification\n | \"zero-shot-object-detection\"; // https://huggingface.co/tasks/zero-shot-object-detection\n\nexport const MultimodalPipelineUseCase = {\n \"document-question-answering\": \"document-question-answering\",\n \"image-to-text\": \"image-to-text\",\n \"zero-shot-audio-classification\": \"zero-shot-audio-classification\",\n \"zero-shot-image-classification\": \"zero-shot-image-classification\",\n \"zero-shot-object-detection\": \"zero-shot-object-detection\",\n} as const satisfies Record<MultimodalPipelineUseCase, MultimodalPipelineUseCase>;\n\nexport type PipelineUseCase =\n | TextPipelineUseCase\n | VisionPipelineUseCase\n | AudioPipelineUseCase\n | MultimodalPipelineUseCase;\n\nexport const PipelineUseCase = {\n ...TextPipelineUseCase,\n ...VisionPipelineUseCase,\n ...AudioPipelineUseCase,\n ...MultimodalPipelineUseCase,\n} as const satisfies Record<PipelineUseCase, PipelineUseCase>;\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAMO,IAAM,uBAAuB;AAC7B,IAAM,iBAAiB;AAavB,IAAM,uBAAuB;AAAA,EAClC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO;AACT;AAcO,IAAM,sBAAsB;AAAA,EACjC,aAAa;AAAA,EACb,wBAAwB;AAAA,EACxB,mBAAmB;AAAA,EACnB,wBAAwB;AAAA,EACxB,uBAAuB;AAAA,EACvB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,sBAAsB;AAAA,EACtB,4BAA4B;AAAA,EAC5B,sBAAsB;AACxB;AAWO,IAAM,wBAAwB;AAAA,EACnC,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,oBAAoB;AAAA,EACpB,wBAAwB;AAAA,EACxB,kBAAkB;AAAA,EAClB,oBAAoB;AAAA,EACpB,4BAA4B;AAC9B;AAOO,IAAM,uBAAuB;AAAA,EAClC,wBAAwB;AAAA,EACxB,gCAAgC;AAAA,EAChC,kBAAkB;AACpB;AASO,IAAM,4BAA4B;AAAA,EACvC,+BAA+B;AAAA,EAC/B,iBAAiB;AAAA,EACjB,kCAAkC;AAAA,EAClC,kCAAkC;AAAA,EAClC,8BAA8B;AAChC;AAQO,IAAM,kBAAkB;AAAA,KAC1B;AAAA,KACA;AAAA,KACA;AAAA,KACA;AACL;",
|
|
8
|
+
"debugId": "297B2C0A21F958E264756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -1,56 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
int8: "int8",
|
|
10
|
-
uint8: "uint8",
|
|
11
|
-
q4: "q4",
|
|
12
|
-
bnb4: "bnb4",
|
|
13
|
-
q4f16: "q4f16"
|
|
14
|
-
};
|
|
15
|
-
var TextPipelineUseCase = {
|
|
16
|
-
"fill-mask": "fill-mask",
|
|
17
|
-
"token-classification": "token-classification",
|
|
18
|
-
"text-generation": "text-generation",
|
|
19
|
-
"text2text-generation": "text2text-generation",
|
|
20
|
-
"text-classification": "text-classification",
|
|
21
|
-
summarization: "summarization",
|
|
22
|
-
translation: "translation",
|
|
23
|
-
"feature-extraction": "feature-extraction",
|
|
24
|
-
"zero-shot-classification": "zero-shot-classification",
|
|
25
|
-
"question-answering": "question-answering"
|
|
26
|
-
};
|
|
27
|
-
var VisionPipelineUseCase = {
|
|
28
|
-
"background-removal": "background-removal",
|
|
29
|
-
"image-segmentation": "image-segmentation",
|
|
30
|
-
"depth-estimation": "depth-estimation",
|
|
31
|
-
"image-classification": "image-classification",
|
|
32
|
-
"image-to-image": "image-to-image",
|
|
33
|
-
"object-detection": "object-detection",
|
|
34
|
-
"image-feature-extraction": "image-feature-extraction"
|
|
35
|
-
};
|
|
36
|
-
var AudioPipelineUseCase = {
|
|
37
|
-
"audio-classification": "audio-classification",
|
|
38
|
-
"automatic-speech-recognition": "automatic-speech-recognition",
|
|
39
|
-
"text-to-speech": "text-to-speech"
|
|
40
|
-
};
|
|
41
|
-
var MultimodalPipelineUseCase = {
|
|
42
|
-
"document-question-answering": "document-question-answering",
|
|
43
|
-
"image-to-text": "image-to-text",
|
|
44
|
-
"zero-shot-audio-classification": "zero-shot-audio-classification",
|
|
45
|
-
"zero-shot-image-classification": "zero-shot-image-classification",
|
|
46
|
-
"zero-shot-object-detection": "zero-shot-object-detection"
|
|
47
|
-
};
|
|
48
|
-
var PipelineUseCase = {
|
|
49
|
-
...TextPipelineUseCase,
|
|
50
|
-
...VisionPipelineUseCase,
|
|
51
|
-
...AudioPipelineUseCase,
|
|
52
|
-
...MultimodalPipelineUseCase
|
|
53
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
HF_TRANSFORMERS_ONNX,
|
|
3
|
+
PipelineUseCase,
|
|
4
|
+
QuantizationDataType
|
|
5
|
+
} from "./index-m0r2hvfz.js";
|
|
6
|
+
import {
|
|
7
|
+
__require
|
|
8
|
+
} from "./index-6j5pq722.js";
|
|
54
9
|
|
|
55
10
|
// src/hf-transformers/common/HFT_ModelSchema.ts
|
|
56
11
|
import { ModelConfigSchema, ModelRecordSchema } from "@workglow/ai";
|
|
@@ -166,6 +121,54 @@ var HfTransformersOnnxModelConfigSchema = {
|
|
|
166
121
|
additionalProperties: false
|
|
167
122
|
};
|
|
168
123
|
|
|
169
|
-
|
|
124
|
+
// src/hf-transformers/HuggingFaceTransformersProvider.ts
|
|
125
|
+
import {
|
|
126
|
+
AiProvider
|
|
127
|
+
} from "@workglow/ai";
|
|
128
|
+
class HuggingFaceTransformersProvider extends AiProvider {
|
|
129
|
+
name = HF_TRANSFORMERS_ONNX;
|
|
130
|
+
isLocal = true;
|
|
131
|
+
supportsBrowser = true;
|
|
132
|
+
taskTypes = [
|
|
133
|
+
"DownloadModelTask",
|
|
134
|
+
"UnloadModelTask",
|
|
135
|
+
"ModelInfoTask",
|
|
136
|
+
"CountTokensTask",
|
|
137
|
+
"TextEmbeddingTask",
|
|
138
|
+
"TextGenerationTask",
|
|
139
|
+
"TextQuestionAnswerTask",
|
|
140
|
+
"TextLanguageDetectionTask",
|
|
141
|
+
"TextClassificationTask",
|
|
142
|
+
"TextFillMaskTask",
|
|
143
|
+
"TextNamedEntityRecognitionTask",
|
|
144
|
+
"TextRewriterTask",
|
|
145
|
+
"TextSummaryTask",
|
|
146
|
+
"TextTranslationTask",
|
|
147
|
+
"ImageSegmentationTask",
|
|
148
|
+
"ImageToTextTask",
|
|
149
|
+
"BackgroundRemovalTask",
|
|
150
|
+
"ImageEmbeddingTask",
|
|
151
|
+
"ImageClassificationTask",
|
|
152
|
+
"ObjectDetectionTask",
|
|
153
|
+
"ToolCallingTask"
|
|
154
|
+
];
|
|
155
|
+
constructor(tasks, streamTasks, reactiveTasks) {
|
|
156
|
+
super(tasks, streamTasks, reactiveTasks);
|
|
157
|
+
}
|
|
158
|
+
async onInitialize(options) {
|
|
159
|
+
if (options.mode === "inline") {
|
|
160
|
+
const { env } = await import("@huggingface/transformers");
|
|
161
|
+
env.backends.onnx.wasm.proxy = true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async dispose() {
|
|
165
|
+
if (this.tasks) {
|
|
166
|
+
const { clearPipelineCache } = await import("./HFT_JobRunFns-yx418d60.js");
|
|
167
|
+
clearPipelineCache();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { HfTransformersOnnxModelSchema, HfTransformersOnnxModelRecordSchema, HfTransformersOnnxModelConfigSchema, HuggingFaceTransformersProvider };
|
|
170
173
|
|
|
171
|
-
//# debugId=
|
|
174
|
+
//# debugId=47194B552DCD4CBC64756E2164756E21
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/hf-transformers/common/HFT_ModelSchema.ts", "../src/hf-transformers/HuggingFaceTransformersProvider.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ModelConfigSchema, ModelRecordSchema } from \"@workglow/ai\";\nimport { DataPortSchemaObject, FromSchema } from \"@workglow/util\";\nimport { HF_TRANSFORMERS_ONNX, PipelineUseCase, QuantizationDataType } from \"./HFT_Constants\";\n\nexport const HfTransformersOnnxModelSchema = {\n type: \"object\",\n properties: {\n provider: {\n const: HF_TRANSFORMERS_ONNX,\n description: \"Discriminator: ONNX runtime backend.\",\n },\n provider_config: {\n type: \"object\",\n description: \"ONNX runtime-specific options.\",\n properties: {\n pipeline: {\n type: \"string\",\n enum: Object.values(PipelineUseCase),\n description: \"Pipeline type for the ONNX model.\",\n default: \"text-generation\",\n },\n model_path: {\n type: \"string\",\n description: \"Filesystem path or URI for the ONNX model.\",\n },\n dtype: {\n type: \"string\",\n enum: Object.values(QuantizationDataType),\n description: \"Data type for the ONNX model.\",\n default: \"auto\",\n },\n device: {\n type: \"string\",\n enum: [\"cpu\", \"gpu\", \"webgpu\", \"wasm\", \"metal\"],\n description: \"High-level device selection.\",\n default: \"webgpu\",\n },\n execution_providers: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Raw ONNX Runtime execution provider identifiers.\",\n \"x-ui-hidden\": true,\n },\n intra_op_num_threads: {\n type: \"integer\",\n minimum: 1,\n },\n inter_op_num_threads: {\n type: \"integer\",\n minimum: 1,\n },\n use_external_data_format: {\n type: \"boolean\",\n description: \"Whether the model uses external data format.\",\n },\n native_dimensions: {\n type: \"integer\",\n description: \"The native dimensions of the model.\",\n },\n pooling: {\n type: \"string\",\n enum: [\"mean\", \"last_token\", \"cls\"],\n description: \"The pooling strategy to use for the model.\",\n default: \"mean\",\n },\n normalize: {\n type: \"boolean\",\n description: \"Whether the model uses normalization.\",\n default: true,\n },\n language_style: {\n type: \"string\",\n description: \"The language style of the model.\",\n },\n mrl: {\n type: \"boolean\",\n description: \"Whether the model uses matryoshka.\",\n default: false,\n },\n },\n required: [\"model_path\", \"pipeline\"],\n additionalProperties: false,\n if: {\n properties: {\n pipeline: {\n const: \"feature-extraction\",\n },\n },\n },\n then: {\n required: [\"native_dimensions\"],\n },\n },\n },\n required: [\"provider\", \"provider_config\"],\n additionalProperties: true,\n} as const satisfies DataPortSchemaObject;\n\nexport const HfTransformersOnnxModelRecordSchema = {\n type: \"object\",\n properties: {\n ...ModelRecordSchema.properties,\n ...HfTransformersOnnxModelSchema.properties,\n },\n required: [...ModelRecordSchema.required, ...HfTransformersOnnxModelSchema.required],\n additionalProperties: false,\n} as const satisfies DataPortSchemaObject;\n\nexport type HfTransformersOnnxModelRecord = FromSchema<typeof HfTransformersOnnxModelRecordSchema>;\n\nexport const HfTransformersOnnxModelConfigSchema = {\n type: \"object\",\n properties: {\n ...ModelConfigSchema.properties,\n ...HfTransformersOnnxModelSchema.properties,\n },\n required: [...ModelConfigSchema.required, ...HfTransformersOnnxModelSchema.required],\n additionalProperties: false,\n} as const satisfies DataPortSchemaObject;\n\nexport type HfTransformersOnnxModelConfig = FromSchema<typeof HfTransformersOnnxModelConfigSchema>;\n",
|
|
6
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n AiProvider,\n type AiProviderReactiveRunFn,\n type AiProviderRegisterOptions,\n type AiProviderRunFn,\n type AiProviderStreamFn,\n} from \"@workglow/ai\";\nimport { HF_TRANSFORMERS_ONNX } from \"./common/HFT_Constants\";\nimport type { HfTransformersOnnxModelConfig } from \"./common/HFT_ModelSchema\";\n\n/**\n * AI provider for HuggingFace Transformers ONNX models.\n *\n * Supports text, vision, and multimodal tasks via the @huggingface/transformers library.\n *\n * Task run functions are injected via the constructor so that the heavy\n * `@huggingface/transformers` library is only imported where actually needed\n * (inline mode, worker server), not on the main thread in worker mode.\n *\n * @example\n * ```typescript\n * // Worker mode (main thread) -- lightweight, no heavy imports:\n * await new HuggingFaceTransformersProvider().register({\n * mode: \"worker\",\n * worker: new Worker(new URL(\"./worker_hft.ts\", import.meta.url), { type: \"module\" }),\n * });\n *\n * // Inline mode -- caller provides the tasks:\n * import { HFT_TASKS, HFT_STREAM_TASKS, HFT_REACTIVE_TASKS } from \"@workglow/ai-provider/hf-transformers\";\n * await new HuggingFaceTransformersProvider(HFT_TASKS, HFT_STREAM_TASKS, HFT_REACTIVE_TASKS).register({ mode: \"inline\" });\n *\n * // Worker side -- caller provides the tasks:\n * import { HFT_TASKS, HFT_STREAM_TASKS, HFT_REACTIVE_TASKS } from \"@workglow/ai-provider/hf-transformers\";\n * new HuggingFaceTransformersProvider(HFT_TASKS, HFT_STREAM_TASKS, HFT_REACTIVE_TASKS).registerOnWorkerServer(workerServer);\n * ```\n */\nexport class HuggingFaceTransformersProvider extends AiProvider<HfTransformersOnnxModelConfig> {\n readonly name = HF_TRANSFORMERS_ONNX;\n readonly isLocal = true;\n readonly supportsBrowser = true;\n\n readonly taskTypes = [\n \"DownloadModelTask\",\n \"UnloadModelTask\",\n \"ModelInfoTask\",\n \"CountTokensTask\",\n \"TextEmbeddingTask\",\n \"TextGenerationTask\",\n \"TextQuestionAnswerTask\",\n \"TextLanguageDetectionTask\",\n \"TextClassificationTask\",\n \"TextFillMaskTask\",\n \"TextNamedEntityRecognitionTask\",\n \"TextRewriterTask\",\n \"TextSummaryTask\",\n \"TextTranslationTask\",\n \"ImageSegmentationTask\",\n \"ImageToTextTask\",\n \"BackgroundRemovalTask\",\n \"ImageEmbeddingTask\",\n \"ImageClassificationTask\",\n \"ObjectDetectionTask\",\n \"ToolCallingTask\",\n ] as const;\n\n constructor(\n tasks?: Record<string, AiProviderRunFn<any, any, HfTransformersOnnxModelConfig>>,\n streamTasks?: Record<string, AiProviderStreamFn<any, any, HfTransformersOnnxModelConfig>>,\n reactiveTasks?: Record<string, AiProviderReactiveRunFn<any, any, HfTransformersOnnxModelConfig>>\n ) {\n super(tasks, streamTasks, reactiveTasks);\n }\n\n protected override async onInitialize(options: AiProviderRegisterOptions): Promise<void> {\n if (options.mode === \"inline\") {\n const { env } = await import(\"@huggingface/transformers\");\n // @ts-ignore -- backends.onnx.wasm.proxy is not fully typed\n env.backends.onnx.wasm.proxy = true;\n }\n }\n\n override async dispose(): Promise<void> {\n if (this.tasks) {\n const { clearPipelineCache } = await import(\"./common/HFT_JobRunFns\");\n clearPipelineCache();\n }\n }\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": "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",
|
|
9
|
+
"debugId": "47194B552DCD4CBC64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HTF_CACHE_NAME
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-m0r2hvfz.js";
|
|
4
4
|
import {
|
|
5
5
|
__require
|
|
6
6
|
} from "./index-6j5pq722.js";
|
|
7
7
|
|
|
8
8
|
// src/hf-transformers/common/HFT_JobRunFns.ts
|
|
9
|
-
import { buildToolDescription, filterValidToolCalls } from "@workglow/ai";
|
|
10
|
-
import { getLogger } from "@workglow/util";
|
|
9
|
+
import { buildToolDescription, filterValidToolCalls, toTextFlatMessages } from "@workglow/ai";
|
|
10
|
+
import { getLogger, parsePartialJson } from "@workglow/util";
|
|
11
11
|
var _transformersSdk;
|
|
12
12
|
async function loadTransformersSDK() {
|
|
13
13
|
if (!_transformersSdk) {
|
|
@@ -244,7 +244,8 @@ var deleteModelCache = async (model_path) => {
|
|
|
244
244
|
};
|
|
245
245
|
var HFT_TextEmbedding = async (input, model, onProgress, signal) => {
|
|
246
246
|
const logger = getLogger();
|
|
247
|
-
const
|
|
247
|
+
const uuid = crypto.randomUUID();
|
|
248
|
+
const timerLabel = `hft:TextEmbedding:${model?.provider_config.model_path}:${uuid}`;
|
|
248
249
|
logger.time(timerLabel, { model: model?.provider_config.model_path });
|
|
249
250
|
const generateEmbedding = await getPipeline(model, onProgress, {}, signal);
|
|
250
251
|
logger.debug("HFT TextEmbedding: pipeline ready, generating embedding", {
|
|
@@ -945,7 +946,7 @@ function mapHFTTools(tools) {
|
|
|
945
946
|
}));
|
|
946
947
|
}
|
|
947
948
|
function parseToolCallsFromText(responseText) {
|
|
948
|
-
const toolCalls =
|
|
949
|
+
const toolCalls = [];
|
|
949
950
|
let callIndex = 0;
|
|
950
951
|
let cleanedText = responseText;
|
|
951
952
|
const toolCallTagRegex = /<tool_call>([\s\S]*?)<\/tool_call>/g;
|
|
@@ -954,14 +955,14 @@ function parseToolCallsFromText(responseText) {
|
|
|
954
955
|
try {
|
|
955
956
|
const parsed = JSON.parse(tagMatch[1].trim());
|
|
956
957
|
const id = `call_${callIndex++}`;
|
|
957
|
-
toolCalls
|
|
958
|
+
toolCalls.push({
|
|
958
959
|
id,
|
|
959
960
|
name: parsed.name ?? parsed.function?.name ?? "",
|
|
960
961
|
input: parsed.arguments ?? parsed.function?.arguments ?? parsed.parameters ?? {}
|
|
961
|
-
};
|
|
962
|
+
});
|
|
962
963
|
} catch {}
|
|
963
964
|
}
|
|
964
|
-
if (
|
|
965
|
+
if (toolCalls.length > 0) {
|
|
965
966
|
cleanedText = responseText.replace(/<tool_call>[\s\S]*?<\/tool_call>/g, "").trim();
|
|
966
967
|
return { text: cleanedText, toolCalls };
|
|
967
968
|
}
|
|
@@ -1013,11 +1014,11 @@ function parseToolCallsFromText(responseText) {
|
|
|
1013
1014
|
const parsed = JSON.parse(candidate.text);
|
|
1014
1015
|
if (parsed.name && (parsed.arguments !== undefined || parsed.parameters !== undefined)) {
|
|
1015
1016
|
const id = `call_${callIndex++}`;
|
|
1016
|
-
toolCalls
|
|
1017
|
+
toolCalls.push({
|
|
1017
1018
|
id,
|
|
1018
1019
|
name: parsed.name,
|
|
1019
1020
|
input: parsed.arguments ?? parsed.parameters ?? {}
|
|
1020
|
-
};
|
|
1021
|
+
});
|
|
1021
1022
|
matchedRanges.push({ start: candidate.start, end: candidate.end });
|
|
1022
1023
|
} else if (parsed.function?.name) {
|
|
1023
1024
|
let functionArgs = parsed.function.arguments ?? {};
|
|
@@ -1030,16 +1031,16 @@ function parseToolCallsFromText(responseText) {
|
|
|
1030
1031
|
}
|
|
1031
1032
|
}
|
|
1032
1033
|
const id = `call_${callIndex++}`;
|
|
1033
|
-
toolCalls
|
|
1034
|
+
toolCalls.push({
|
|
1034
1035
|
id,
|
|
1035
1036
|
name: parsed.function.name,
|
|
1036
1037
|
input: functionArgs ?? {}
|
|
1037
|
-
};
|
|
1038
|
+
});
|
|
1038
1039
|
matchedRanges.push({ start: candidate.start, end: candidate.end });
|
|
1039
1040
|
}
|
|
1040
1041
|
} catch {}
|
|
1041
1042
|
}
|
|
1042
|
-
if (
|
|
1043
|
+
if (toolCalls.length > 0) {
|
|
1043
1044
|
let result = "";
|
|
1044
1045
|
let lastIndex = 0;
|
|
1045
1046
|
for (const range of matchedRanges) {
|
|
@@ -1079,40 +1080,34 @@ var HFT_ToolCalling = async (input, model, onProgress, signal) => {
|
|
|
1079
1080
|
if (isArrayInput) {
|
|
1080
1081
|
const prompts = input.prompt;
|
|
1081
1082
|
const texts = [];
|
|
1082
|
-
const
|
|
1083
|
-
for (const
|
|
1084
|
-
const
|
|
1085
|
-
|
|
1086
|
-
messages2.push({ role: "system", content: input.systemPrompt });
|
|
1087
|
-
}
|
|
1088
|
-
messages2.push({ role: "user", content: promptText });
|
|
1089
|
-
const singleInput = { ...input, prompt: promptText };
|
|
1083
|
+
const toolCallsList = [];
|
|
1084
|
+
for (const singlePrompt of prompts) {
|
|
1085
|
+
const singleInput = { ...input, prompt: singlePrompt };
|
|
1086
|
+
const messages2 = toTextFlatMessages(singleInput);
|
|
1090
1087
|
const tools2 = resolveHFTToolsAndMessages(singleInput, messages2);
|
|
1091
1088
|
const prompt2 = generateText.tokenizer.apply_chat_template(messages2, {
|
|
1092
1089
|
tools: tools2,
|
|
1093
1090
|
tokenize: false,
|
|
1094
1091
|
add_generation_prompt: true
|
|
1095
1092
|
});
|
|
1093
|
+
const streamer2 = createTextStreamer(generateText.tokenizer, onProgress);
|
|
1096
1094
|
let results2 = await generateText(prompt2, {
|
|
1097
1095
|
max_new_tokens: input.maxTokens ?? 1024,
|
|
1098
1096
|
temperature: input.temperature ?? undefined,
|
|
1099
|
-
return_full_text: false
|
|
1097
|
+
return_full_text: false,
|
|
1098
|
+
streamer: streamer2
|
|
1100
1099
|
});
|
|
1101
1100
|
if (!Array.isArray(results2)) {
|
|
1102
1101
|
results2 = [results2];
|
|
1103
1102
|
}
|
|
1104
1103
|
const responseText2 = extractGeneratedText(results2[0]?.generated_text).trim();
|
|
1105
|
-
const
|
|
1106
|
-
texts.push(
|
|
1107
|
-
|
|
1104
|
+
const { text: text2, toolCalls: toolCalls2 } = parseToolCallsFromText(responseText2);
|
|
1105
|
+
texts.push(text2);
|
|
1106
|
+
toolCallsList.push(filterValidToolCalls(toolCalls2, singleInput.tools));
|
|
1108
1107
|
}
|
|
1109
|
-
return { text: texts, toolCalls:
|
|
1110
|
-
}
|
|
1111
|
-
const messages = [];
|
|
1112
|
-
if (input.systemPrompt) {
|
|
1113
|
-
messages.push({ role: "system", content: input.systemPrompt });
|
|
1108
|
+
return { text: texts, toolCalls: toolCallsList };
|
|
1114
1109
|
}
|
|
1115
|
-
messages
|
|
1110
|
+
const messages = toTextFlatMessages(input);
|
|
1116
1111
|
const tools = resolveHFTToolsAndMessages(input, messages);
|
|
1117
1112
|
const prompt = generateText.tokenizer.apply_chat_template(messages, {
|
|
1118
1113
|
tools,
|
|
@@ -1131,16 +1126,15 @@ var HFT_ToolCalling = async (input, model, onProgress, signal) => {
|
|
|
1131
1126
|
}
|
|
1132
1127
|
const responseText = extractGeneratedText(results[0]?.generated_text).trim();
|
|
1133
1128
|
const { text, toolCalls } = parseToolCallsFromText(responseText);
|
|
1134
|
-
return {
|
|
1129
|
+
return {
|
|
1130
|
+
text,
|
|
1131
|
+
toolCalls: filterValidToolCalls(toolCalls, input.tools)
|
|
1132
|
+
};
|
|
1135
1133
|
};
|
|
1136
1134
|
var HFT_ToolCalling_Stream = async function* (input, model, signal) {
|
|
1137
1135
|
const noopProgress = () => {};
|
|
1138
1136
|
const generateText = await getPipeline(model, noopProgress, {}, signal);
|
|
1139
|
-
const messages =
|
|
1140
|
-
if (input.systemPrompt) {
|
|
1141
|
-
messages.push({ role: "system", content: input.systemPrompt });
|
|
1142
|
-
}
|
|
1143
|
-
messages.push({ role: "user", content: input.prompt });
|
|
1137
|
+
const messages = toTextFlatMessages(input);
|
|
1144
1138
|
const tools = resolveHFTToolsAndMessages(input, messages);
|
|
1145
1139
|
const prompt = generateText.tokenizer.apply_chat_template(messages, {
|
|
1146
1140
|
tools,
|
|
@@ -1186,8 +1180,8 @@ var HFT_ToolCalling_Stream = async function* (input, model, signal) {
|
|
|
1186
1180
|
await pipelinePromise;
|
|
1187
1181
|
const { text: cleanedText, toolCalls } = parseToolCallsFromText(fullText);
|
|
1188
1182
|
const validToolCalls = filterValidToolCalls(toolCalls, input.tools);
|
|
1189
|
-
if (
|
|
1190
|
-
yield { type: "object-delta", port: "toolCalls", objectDelta:
|
|
1183
|
+
if (validToolCalls.length > 0) {
|
|
1184
|
+
yield { type: "object-delta", port: "toolCalls", objectDelta: [...validToolCalls] };
|
|
1191
1185
|
}
|
|
1192
1186
|
yield {
|
|
1193
1187
|
type: "finish",
|
|
@@ -1202,7 +1196,7 @@ var HFT_ModelInfo = async (input, model) => {
|
|
|
1202
1196
|
const detail = input.detail;
|
|
1203
1197
|
const is_loaded = pipelines.has(getPipelineCacheKey(model));
|
|
1204
1198
|
const { pipeline: pipelineType, model_path, dtype, device } = model.provider_config;
|
|
1205
|
-
const cacheStatus = await ModelRegistry.
|
|
1199
|
+
const cacheStatus = await ModelRegistry.is_pipeline_cached_files(pipelineType, model_path, {
|
|
1206
1200
|
...dtype ? { dtype } : {}
|
|
1207
1201
|
});
|
|
1208
1202
|
logger.debug("is_pipeline_cached", {
|
|
@@ -1247,6 +1241,94 @@ var HFT_ModelInfo = async (input, model) => {
|
|
|
1247
1241
|
file_sizes
|
|
1248
1242
|
};
|
|
1249
1243
|
};
|
|
1244
|
+
function buildStructuredGenerationPrompt(input) {
|
|
1245
|
+
const schemaStr = JSON.stringify(input.outputSchema, null, 2);
|
|
1246
|
+
return `${input.prompt}
|
|
1247
|
+
|
|
1248
|
+
You MUST respond with ONLY a valid JSON object conforming to this JSON schema:
|
|
1249
|
+
${schemaStr}
|
|
1250
|
+
|
|
1251
|
+
Output ONLY the JSON object, no other text.`;
|
|
1252
|
+
}
|
|
1253
|
+
function extractJsonFromText(text) {
|
|
1254
|
+
try {
|
|
1255
|
+
return JSON.parse(text);
|
|
1256
|
+
} catch {
|
|
1257
|
+
const match = text.match(/\{[\s\S]*\}/);
|
|
1258
|
+
if (match) {
|
|
1259
|
+
try {
|
|
1260
|
+
return JSON.parse(match[0]);
|
|
1261
|
+
} catch {
|
|
1262
|
+
return parsePartialJson(match[0]) ?? {};
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
return {};
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
var HFT_StructuredGeneration = async (input, model, onProgress, signal) => {
|
|
1269
|
+
const generateText = await getPipeline(model, onProgress, {}, signal);
|
|
1270
|
+
const prompt = buildStructuredGenerationPrompt(input);
|
|
1271
|
+
const messages = [{ role: "user", content: prompt }];
|
|
1272
|
+
const formattedPrompt = generateText.tokenizer.apply_chat_template(messages, {
|
|
1273
|
+
tokenize: false,
|
|
1274
|
+
add_generation_prompt: true
|
|
1275
|
+
});
|
|
1276
|
+
const streamer = createTextStreamer(generateText.tokenizer, onProgress);
|
|
1277
|
+
let results = await generateText(formattedPrompt, {
|
|
1278
|
+
max_new_tokens: input.maxTokens ?? 1024,
|
|
1279
|
+
temperature: input.temperature ?? undefined,
|
|
1280
|
+
return_full_text: false,
|
|
1281
|
+
streamer
|
|
1282
|
+
});
|
|
1283
|
+
if (!Array.isArray(results)) {
|
|
1284
|
+
results = [results];
|
|
1285
|
+
}
|
|
1286
|
+
const responseText = extractGeneratedText(results[0]?.generated_text).trim();
|
|
1287
|
+
const object = extractJsonFromText(responseText);
|
|
1288
|
+
return { object };
|
|
1289
|
+
};
|
|
1290
|
+
var HFT_StructuredGeneration_Stream = async function* (input, model, signal) {
|
|
1291
|
+
const noopProgress = () => {};
|
|
1292
|
+
const generateText = await getPipeline(model, noopProgress, {}, signal);
|
|
1293
|
+
const prompt = buildStructuredGenerationPrompt(input);
|
|
1294
|
+
const messages = [{ role: "user", content: prompt }];
|
|
1295
|
+
const formattedPrompt = generateText.tokenizer.apply_chat_template(messages, {
|
|
1296
|
+
tokenize: false,
|
|
1297
|
+
add_generation_prompt: true
|
|
1298
|
+
});
|
|
1299
|
+
const queue = createStreamEventQueue();
|
|
1300
|
+
const streamer = createStreamingTextStreamer(generateText.tokenizer, queue);
|
|
1301
|
+
let fullText = "";
|
|
1302
|
+
const originalPush = queue.push;
|
|
1303
|
+
queue.push = (event) => {
|
|
1304
|
+
if (event.type === "text-delta" && "textDelta" in event) {
|
|
1305
|
+
fullText += event.textDelta;
|
|
1306
|
+
const match = fullText.match(/\{[\s\S]*/);
|
|
1307
|
+
if (match) {
|
|
1308
|
+
const partial = parsePartialJson(match[0]);
|
|
1309
|
+
if (partial !== undefined) {
|
|
1310
|
+
originalPush({
|
|
1311
|
+
type: "object-delta",
|
|
1312
|
+
port: "object",
|
|
1313
|
+
objectDelta: partial
|
|
1314
|
+
});
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
originalPush(event);
|
|
1320
|
+
};
|
|
1321
|
+
const pipelinePromise = generateText(formattedPrompt, {
|
|
1322
|
+
max_new_tokens: input.maxTokens ?? 1024,
|
|
1323
|
+
temperature: input.temperature ?? undefined,
|
|
1324
|
+
return_full_text: false,
|
|
1325
|
+
streamer
|
|
1326
|
+
}).then(() => queue.done(), (err) => queue.error(err));
|
|
1327
|
+
yield* queue.iterable;
|
|
1328
|
+
await pipelinePromise;
|
|
1329
|
+
const object = extractJsonFromText(fullText);
|
|
1330
|
+
yield { type: "finish", data: { object } };
|
|
1331
|
+
};
|
|
1250
1332
|
var HFT_TASKS = {
|
|
1251
1333
|
DownloadModelTask: HFT_Download,
|
|
1252
1334
|
UnloadModelTask: HFT_Unload,
|
|
@@ -1268,7 +1350,8 @@ var HFT_TASKS = {
|
|
|
1268
1350
|
ImageEmbeddingTask: HFT_ImageEmbedding,
|
|
1269
1351
|
ImageClassificationTask: HFT_ImageClassification,
|
|
1270
1352
|
ObjectDetectionTask: HFT_ObjectDetection,
|
|
1271
|
-
ToolCallingTask: HFT_ToolCalling
|
|
1353
|
+
ToolCallingTask: HFT_ToolCalling,
|
|
1354
|
+
StructuredGenerationTask: HFT_StructuredGeneration
|
|
1272
1355
|
};
|
|
1273
1356
|
var HFT_STREAM_TASKS = {
|
|
1274
1357
|
TextGenerationTask: HFT_TextGeneration_Stream,
|
|
@@ -1276,12 +1359,13 @@ var HFT_STREAM_TASKS = {
|
|
|
1276
1359
|
TextSummaryTask: HFT_TextSummary_Stream,
|
|
1277
1360
|
TextQuestionAnswerTask: HFT_TextQuestionAnswer_Stream,
|
|
1278
1361
|
TextTranslationTask: HFT_TextTranslation_Stream,
|
|
1279
|
-
ToolCallingTask: HFT_ToolCalling_Stream
|
|
1362
|
+
ToolCallingTask: HFT_ToolCalling_Stream,
|
|
1363
|
+
StructuredGenerationTask: HFT_StructuredGeneration_Stream
|
|
1280
1364
|
};
|
|
1281
1365
|
var HFT_REACTIVE_TASKS = {
|
|
1282
1366
|
CountTokensTask: HFT_CountTokens_Reactive
|
|
1283
1367
|
};
|
|
1284
1368
|
|
|
1285
|
-
export { clearPipelineCache, HFT_Download, HFT_Unload, HFT_TextEmbedding, HFT_TextClassification, HFT_TextLanguageDetection, HFT_TextNamedEntityRecognition, HFT_TextFillMask, HFT_TextGeneration, HFT_TextTranslation, HFT_TextRewriter, HFT_TextSummary, HFT_TextQuestionAnswer, HFT_ImageSegmentation, HFT_ImageToText, HFT_BackgroundRemoval, HFT_ImageEmbedding, HFT_ImageClassification, HFT_ObjectDetection, createToolCallMarkupFilter, HFT_TextGeneration_Stream, HFT_TextRewriter_Stream, HFT_TextSummary_Stream, HFT_TextQuestionAnswer_Stream, HFT_TextTranslation_Stream, HFT_CountTokens, HFT_CountTokens_Reactive, parseToolCallsFromText, HFT_ToolCalling, HFT_ToolCalling_Stream, HFT_ModelInfo, HFT_TASKS, HFT_STREAM_TASKS, HFT_REACTIVE_TASKS };
|
|
1369
|
+
export { clearPipelineCache, HFT_Download, HFT_Unload, HFT_TextEmbedding, HFT_TextClassification, HFT_TextLanguageDetection, HFT_TextNamedEntityRecognition, HFT_TextFillMask, HFT_TextGeneration, HFT_TextTranslation, HFT_TextRewriter, HFT_TextSummary, HFT_TextQuestionAnswer, HFT_ImageSegmentation, HFT_ImageToText, HFT_BackgroundRemoval, HFT_ImageEmbedding, HFT_ImageClassification, HFT_ObjectDetection, createToolCallMarkupFilter, HFT_TextGeneration_Stream, HFT_TextRewriter_Stream, HFT_TextSummary_Stream, HFT_TextQuestionAnswer_Stream, HFT_TextTranslation_Stream, HFT_CountTokens, HFT_CountTokens_Reactive, parseToolCallsFromText, HFT_ToolCalling, HFT_ToolCalling_Stream, HFT_ModelInfo, HFT_StructuredGeneration, HFT_StructuredGeneration_Stream, HFT_TASKS, HFT_STREAM_TASKS, HFT_REACTIVE_TASKS };
|
|
1286
1370
|
|
|
1287
|
-
//# debugId=
|
|
1371
|
+
//# debugId=84170CBF73939EA164756E2164756E21
|