@workglow/ai-provider 0.0.89 → 0.0.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -45
- package/dist/anthropic/AnthropicProvider.d.ts +39 -0
- package/dist/anthropic/AnthropicProvider.d.ts.map +1 -0
- package/dist/anthropic/Anthropic_Worker.d.ts +7 -0
- package/dist/anthropic/Anthropic_Worker.d.ts.map +1 -0
- package/dist/anthropic/common/Anthropic_Constants.d.ts +7 -0
- package/dist/anthropic/common/Anthropic_Constants.d.ts.map +1 -0
- package/dist/anthropic/common/Anthropic_JobRunFns.d.ts +16 -0
- package/dist/anthropic/common/Anthropic_JobRunFns.d.ts.map +1 -0
- package/dist/anthropic/common/Anthropic_ModelSchema.d.ts +167 -0
- package/dist/anthropic/common/Anthropic_ModelSchema.d.ts.map +1 -0
- package/dist/anthropic/index.d.ts +11 -0
- package/dist/anthropic/index.d.ts.map +1 -0
- package/dist/anthropic/index.js +257 -0
- package/dist/anthropic/index.js.map +14 -0
- package/dist/google-gemini/Gemini_Worker.d.ts +7 -0
- package/dist/google-gemini/Gemini_Worker.d.ts.map +1 -0
- package/dist/google-gemini/GoogleGeminiProvider.d.ts +36 -0
- package/dist/google-gemini/GoogleGeminiProvider.d.ts.map +1 -0
- package/dist/google-gemini/common/Gemini_Constants.d.ts +7 -0
- package/dist/google-gemini/common/Gemini_Constants.d.ts.map +1 -0
- package/dist/google-gemini/common/Gemini_JobRunFns.d.ts +17 -0
- package/dist/google-gemini/common/Gemini_JobRunFns.d.ts.map +1 -0
- package/dist/google-gemini/common/Gemini_ModelSchema.d.ts +164 -0
- package/dist/google-gemini/common/Gemini_ModelSchema.d.ts.map +1 -0
- package/dist/google-gemini/index.d.ts +11 -0
- package/dist/google-gemini/index.d.ts.map +1 -0
- package/dist/google-gemini/index.js +300 -0
- package/dist/google-gemini/index.js.map +14 -0
- package/dist/hf-transformers/HFT_Worker.d.ts +7 -0
- package/dist/hf-transformers/HFT_Worker.d.ts.map +1 -0
- package/dist/hf-transformers/HuggingFaceTransformersProvider.d.ts +41 -0
- package/dist/hf-transformers/HuggingFaceTransformersProvider.d.ts.map +1 -0
- package/dist/hf-transformers/common/HFT_JobRunFns.d.ts +1218 -1
- package/dist/hf-transformers/common/HFT_JobRunFns.d.ts.map +1 -1
- package/dist/hf-transformers/index.d.ts +2 -3
- package/dist/hf-transformers/index.d.ts.map +1 -1
- package/dist/hf-transformers/index.js +1130 -0
- package/dist/hf-transformers/index.js.map +15 -0
- package/dist/index.d.ts +23 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +729 -865
- package/dist/index.js.map +20 -12
- package/dist/provider-ollama/OllamaProvider.d.ts +39 -0
- package/dist/provider-ollama/OllamaProvider.d.ts.map +1 -0
- package/dist/provider-ollama/Ollama_Worker.d.ts +7 -0
- package/dist/provider-ollama/Ollama_Worker.d.ts.map +1 -0
- package/dist/provider-ollama/common/Ollama_Constants.d.ts +8 -0
- package/dist/provider-ollama/common/Ollama_Constants.d.ts.map +1 -0
- package/dist/provider-ollama/common/Ollama_JobRunFns.d.ts +17 -0
- package/dist/provider-ollama/common/Ollama_JobRunFns.d.ts.map +1 -0
- package/dist/provider-ollama/common/Ollama_ModelSchema.d.ts +137 -0
- package/dist/provider-ollama/common/Ollama_ModelSchema.d.ts.map +1 -0
- package/dist/provider-ollama/index.d.ts +11 -0
- package/dist/provider-ollama/index.d.ts.map +1 -0
- package/dist/provider-ollama/index.js +274 -0
- package/dist/provider-ollama/index.js.map +14 -0
- package/dist/provider-openai/OpenAI_Worker.d.ts +7 -0
- package/dist/provider-openai/OpenAI_Worker.d.ts.map +1 -0
- package/dist/provider-openai/OpenAiProvider.d.ts +40 -0
- package/dist/provider-openai/OpenAiProvider.d.ts.map +1 -0
- package/dist/provider-openai/common/OpenAI_Constants.d.ts +7 -0
- package/dist/provider-openai/common/OpenAI_Constants.d.ts.map +1 -0
- package/dist/provider-openai/common/OpenAI_JobRunFns.d.ts +17 -0
- package/dist/provider-openai/common/OpenAI_JobRunFns.d.ts.map +1 -0
- package/dist/provider-openai/common/OpenAI_ModelSchema.d.ts +161 -0
- package/dist/provider-openai/common/OpenAI_ModelSchema.d.ts.map +1 -0
- package/dist/provider-openai/index.d.ts +11 -0
- package/dist/provider-openai/index.d.ts.map +1 -0
- package/dist/provider-openai/index.js +283 -0
- package/dist/provider-openai/index.js.map +14 -0
- package/dist/tf-mediapipe/TFMP_Worker.d.ts +7 -0
- package/dist/tf-mediapipe/TFMP_Worker.d.ts.map +1 -0
- package/dist/tf-mediapipe/TensorFlowMediaPipeProvider.d.ts +39 -0
- package/dist/tf-mediapipe/TensorFlowMediaPipeProvider.d.ts.map +1 -0
- package/dist/tf-mediapipe/common/TFMP_JobRunFns.d.ts +842 -0
- package/dist/tf-mediapipe/common/TFMP_JobRunFns.d.ts.map +1 -1
- package/dist/tf-mediapipe/index.d.ts +2 -3
- package/dist/tf-mediapipe/index.d.ts.map +1 -1
- package/dist/tf-mediapipe/index.js +674 -0
- package/dist/tf-mediapipe/index.js.map +14 -0
- package/package.json +87 -22
- package/dist/hf-transformers/registry/HFT_Client_RegisterJobFns.d.ts +0 -17
- package/dist/hf-transformers/registry/HFT_Client_RegisterJobFns.d.ts.map +0 -1
- package/dist/hf-transformers/registry/HFT_Inline_RegisterJobFns.d.ts +0 -16
- package/dist/hf-transformers/registry/HFT_Inline_RegisterJobFns.d.ts.map +0 -1
- package/dist/hf-transformers/registry/HFT_Worker_RegisterJobFns.d.ts +0 -8
- package/dist/hf-transformers/registry/HFT_Worker_RegisterJobFns.d.ts.map +0 -1
- package/dist/openai/provider/OpenAI_TaskRun.d.ts +0 -2
- package/dist/openai/provider/OpenAI_TaskRun.d.ts.map +0 -1
- package/dist/tf-mediapipe/registry/TFMP_Client_RegisterJobFns.d.ts +0 -17
- package/dist/tf-mediapipe/registry/TFMP_Client_RegisterJobFns.d.ts.map +0 -1
- package/dist/tf-mediapipe/registry/TFMP_Inline_RegisterJobFns.d.ts +0 -16
- package/dist/tf-mediapipe/registry/TFMP_Inline_RegisterJobFns.d.ts.map +0 -1
- package/dist/tf-mediapipe/registry/TFMP_Worker_RegisterJobFns.d.ts +0 -8
- package/dist/tf-mediapipe/registry/TFMP_Worker_RegisterJobFns.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,62 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, {
|
|
5
|
+
get: all[name],
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
set: (newValue) => all[name] = () => newValue
|
|
9
|
+
});
|
|
53
10
|
};
|
|
11
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
12
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
13
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
14
|
+
}) : x)(function(x) {
|
|
15
|
+
if (typeof require !== "undefined")
|
|
16
|
+
return require.apply(this, arguments);
|
|
17
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// src/hf-transformers/common/HFT_Constants.ts
|
|
21
|
+
var HF_TRANSFORMERS_ONNX = "HF_TRANSFORMERS_ONNX", HTF_CACHE_NAME = "transformers-cache", QuantizationDataType, TextPipelineUseCase, VisionPipelineUseCase, AudioPipelineUseCase, MultimodalPipelineUseCase, PipelineUseCase;
|
|
22
|
+
var init_HFT_Constants = __esm(() => {
|
|
23
|
+
QuantizationDataType = {
|
|
24
|
+
auto: "auto",
|
|
25
|
+
fp32: "fp32",
|
|
26
|
+
fp16: "fp16",
|
|
27
|
+
q8: "q8",
|
|
28
|
+
int8: "int8",
|
|
29
|
+
uint8: "uint8",
|
|
30
|
+
q4: "q4",
|
|
31
|
+
bnb4: "bnb4",
|
|
32
|
+
q4f16: "q4f16"
|
|
33
|
+
};
|
|
34
|
+
TextPipelineUseCase = {
|
|
35
|
+
"fill-mask": "fill-mask",
|
|
36
|
+
"token-classification": "token-classification",
|
|
37
|
+
"text-generation": "text-generation",
|
|
38
|
+
"text2text-generation": "text2text-generation",
|
|
39
|
+
"text-classification": "text-classification",
|
|
40
|
+
summarization: "summarization",
|
|
41
|
+
translation: "translation",
|
|
42
|
+
"feature-extraction": "feature-extraction",
|
|
43
|
+
"zero-shot-classification": "zero-shot-classification",
|
|
44
|
+
"question-answering": "question-answering"
|
|
45
|
+
};
|
|
46
|
+
VisionPipelineUseCase = {
|
|
47
|
+
"background-removal": "background-removal",
|
|
48
|
+
"image-segmentation": "image-segmentation",
|
|
49
|
+
"depth-estimation": "depth-estimation",
|
|
50
|
+
"image-classification": "image-classification",
|
|
51
|
+
"image-to-image": "image-to-image",
|
|
52
|
+
"object-detection": "object-detection",
|
|
53
|
+
"image-feature-extraction": "image-feature-extraction"
|
|
54
|
+
};
|
|
55
|
+
AudioPipelineUseCase = {
|
|
56
|
+
"audio-classification": "audio-classification",
|
|
57
|
+
"automatic-speech-recognition": "automatic-speech-recognition",
|
|
58
|
+
"text-to-speech": "text-to-speech"
|
|
59
|
+
};
|
|
60
|
+
MultimodalPipelineUseCase = {
|
|
61
|
+
"document-question-answering": "document-question-answering",
|
|
62
|
+
"image-to-text": "image-to-text",
|
|
63
|
+
"zero-shot-audio-classification": "zero-shot-audio-classification",
|
|
64
|
+
"zero-shot-image-classification": "zero-shot-image-classification",
|
|
65
|
+
"zero-shot-object-detection": "zero-shot-object-detection"
|
|
66
|
+
};
|
|
67
|
+
PipelineUseCase = {
|
|
68
|
+
...TextPipelineUseCase,
|
|
69
|
+
...VisionPipelineUseCase,
|
|
70
|
+
...AudioPipelineUseCase,
|
|
71
|
+
...MultimodalPipelineUseCase
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
|
|
54
75
|
// src/hf-transformers/common/HFT_JobRunFns.ts
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
76
|
+
var exports_HFT_JobRunFns = {};
|
|
77
|
+
__export(exports_HFT_JobRunFns, {
|
|
78
|
+
clearPipelineCache: () => clearPipelineCache,
|
|
79
|
+
HFT_Unload: () => HFT_Unload,
|
|
80
|
+
HFT_TextTranslation_Stream: () => HFT_TextTranslation_Stream,
|
|
81
|
+
HFT_TextTranslation: () => HFT_TextTranslation,
|
|
82
|
+
HFT_TextSummary_Stream: () => HFT_TextSummary_Stream,
|
|
83
|
+
HFT_TextSummary: () => HFT_TextSummary,
|
|
84
|
+
HFT_TextRewriter_Stream: () => HFT_TextRewriter_Stream,
|
|
85
|
+
HFT_TextRewriter: () => HFT_TextRewriter,
|
|
86
|
+
HFT_TextQuestionAnswer_Stream: () => HFT_TextQuestionAnswer_Stream,
|
|
87
|
+
HFT_TextQuestionAnswer: () => HFT_TextQuestionAnswer,
|
|
88
|
+
HFT_TextNamedEntityRecognition: () => HFT_TextNamedEntityRecognition,
|
|
89
|
+
HFT_TextLanguageDetection: () => HFT_TextLanguageDetection,
|
|
90
|
+
HFT_TextGeneration_Stream: () => HFT_TextGeneration_Stream,
|
|
91
|
+
HFT_TextGeneration: () => HFT_TextGeneration,
|
|
92
|
+
HFT_TextFillMask: () => HFT_TextFillMask,
|
|
93
|
+
HFT_TextEmbedding: () => HFT_TextEmbedding,
|
|
94
|
+
HFT_TextClassification: () => HFT_TextClassification,
|
|
95
|
+
HFT_TASKS: () => HFT_TASKS,
|
|
96
|
+
HFT_STREAM_TASKS: () => HFT_STREAM_TASKS,
|
|
97
|
+
HFT_ObjectDetection: () => HFT_ObjectDetection,
|
|
98
|
+
HFT_ImageToText: () => HFT_ImageToText,
|
|
99
|
+
HFT_ImageSegmentation: () => HFT_ImageSegmentation,
|
|
100
|
+
HFT_ImageEmbedding: () => HFT_ImageEmbedding,
|
|
101
|
+
HFT_ImageClassification: () => HFT_ImageClassification,
|
|
102
|
+
HFT_Download: () => HFT_Download,
|
|
103
|
+
HFT_BackgroundRemoval: () => HFT_BackgroundRemoval
|
|
104
|
+
});
|
|
105
|
+
async function loadTransformersSDK() {
|
|
106
|
+
if (!_transformersSdk) {
|
|
107
|
+
try {
|
|
108
|
+
_transformersSdk = await import("@sroussey/transformers");
|
|
109
|
+
} catch {
|
|
110
|
+
throw new Error("@sroussey/transformers is required for HuggingFace Transformers tasks. Install it with: bun add @sroussey/transformers");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return _transformersSdk;
|
|
114
|
+
}
|
|
60
115
|
function clearPipelineCache() {
|
|
61
116
|
pipelines.clear();
|
|
62
117
|
}
|
|
@@ -65,7 +120,87 @@ function getPipelineCacheKey(model) {
|
|
|
65
120
|
const device = model.provider_config.device || "";
|
|
66
121
|
return `${model.provider_config.model_path}:${model.provider_config.pipeline}:${dtype}:${device}`;
|
|
67
122
|
}
|
|
68
|
-
|
|
123
|
+
function imageToBase64(image) {
|
|
124
|
+
return image.toBase64?.() || "";
|
|
125
|
+
}
|
|
126
|
+
function createTextStreamer(tokenizer, updateProgress, signal) {
|
|
127
|
+
const { TextStreamer } = _transformersSdk;
|
|
128
|
+
let count = 0;
|
|
129
|
+
return new TextStreamer(tokenizer, {
|
|
130
|
+
skip_prompt: true,
|
|
131
|
+
decode_kwargs: { skip_special_tokens: true },
|
|
132
|
+
callback_function: (text) => {
|
|
133
|
+
count++;
|
|
134
|
+
const result = 100 * (1 - Math.exp(-0.05 * count));
|
|
135
|
+
const progress = Math.round(Math.min(result, 100));
|
|
136
|
+
updateProgress(progress, "Generating", { text, progress });
|
|
137
|
+
},
|
|
138
|
+
...signal ? { abort_signal: signal } : {}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function createStreamEventQueue() {
|
|
142
|
+
const buffer = [];
|
|
143
|
+
let resolve = null;
|
|
144
|
+
let finished = false;
|
|
145
|
+
let err = null;
|
|
146
|
+
const push = (event) => {
|
|
147
|
+
if (resolve) {
|
|
148
|
+
const r = resolve;
|
|
149
|
+
resolve = null;
|
|
150
|
+
r({ value: event, done: false });
|
|
151
|
+
} else {
|
|
152
|
+
buffer.push(event);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const done = () => {
|
|
156
|
+
finished = true;
|
|
157
|
+
if (resolve) {
|
|
158
|
+
const r = resolve;
|
|
159
|
+
resolve = null;
|
|
160
|
+
r({ value: undefined, done: true });
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const error = (e) => {
|
|
164
|
+
err = e;
|
|
165
|
+
if (resolve) {
|
|
166
|
+
const r = resolve;
|
|
167
|
+
resolve = null;
|
|
168
|
+
r({ value: undefined, done: true });
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const iterable = {
|
|
172
|
+
[Symbol.asyncIterator]() {
|
|
173
|
+
return {
|
|
174
|
+
next() {
|
|
175
|
+
if (err)
|
|
176
|
+
return Promise.reject(err);
|
|
177
|
+
if (buffer.length > 0) {
|
|
178
|
+
return Promise.resolve({ value: buffer.shift(), done: false });
|
|
179
|
+
}
|
|
180
|
+
if (finished) {
|
|
181
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
182
|
+
}
|
|
183
|
+
return new Promise((r) => {
|
|
184
|
+
resolve = r;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
return { push, done, error, iterable };
|
|
191
|
+
}
|
|
192
|
+
function createStreamingTextStreamer(tokenizer, queue, signal) {
|
|
193
|
+
const { TextStreamer } = _transformersSdk;
|
|
194
|
+
return new TextStreamer(tokenizer, {
|
|
195
|
+
skip_prompt: true,
|
|
196
|
+
decode_kwargs: { skip_special_tokens: true },
|
|
197
|
+
callback_function: (text) => {
|
|
198
|
+
queue.push({ type: "text-delta", textDelta: text });
|
|
199
|
+
},
|
|
200
|
+
...signal ? { abort_signal: signal } : {}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
var _transformersSdk, pipelines, getPipeline = async (model, onProgress, options = {}, progressScaleMax = 10) => {
|
|
69
204
|
const cacheKey = getPipelineCacheKey(model);
|
|
70
205
|
if (pipelines.has(cacheKey)) {
|
|
71
206
|
return pipelines.get(cacheKey);
|
|
@@ -82,8 +217,8 @@ var getPipeline = async (model, onProgress, options = {}, progressScaleMax = 10)
|
|
|
82
217
|
const estimatedTinyFiles = 3;
|
|
83
218
|
const estimatedMediumFiles = 1;
|
|
84
219
|
const estimatedTinySize = 1024;
|
|
85
|
-
const estimatedMediumSize =
|
|
86
|
-
const estimatedLargeSize =
|
|
220
|
+
const estimatedMediumSize = 20971520;
|
|
221
|
+
const estimatedLargeSize = 1073741824;
|
|
87
222
|
const baseEstimate = estimatedTinyFiles * estimatedTinySize + estimatedMediumFiles * estimatedMediumSize;
|
|
88
223
|
const sendProgress = (overallProgress, file, fileProgressValue, isFirst, isLast) => {
|
|
89
224
|
const now = Date.now();
|
|
@@ -124,7 +259,7 @@ var getPipeline = async (model, onProgress, options = {}, progressScaleMax = 10)
|
|
|
124
259
|
}
|
|
125
260
|
};
|
|
126
261
|
let hasSeenSubstantialFile = false;
|
|
127
|
-
const substantialFileThreshold =
|
|
262
|
+
const substantialFileThreshold = 1048576;
|
|
128
263
|
const abortSignal = options.abort_signal;
|
|
129
264
|
const progressCallback = (status) => {
|
|
130
265
|
if (abortSignal?.aborted) {
|
|
@@ -149,8 +284,8 @@ var getPipeline = async (model, onProgress, options = {}, progressScaleMax = 10)
|
|
|
149
284
|
}
|
|
150
285
|
let actualLoadedSize = 0;
|
|
151
286
|
let actualTotalSize = 0;
|
|
152
|
-
const tinyThreshold =
|
|
153
|
-
const mediumThreshold =
|
|
287
|
+
const tinyThreshold = 102400;
|
|
288
|
+
const mediumThreshold = 104857600;
|
|
154
289
|
let seenTinyCount = 0;
|
|
155
290
|
let seenMediumCount = 0;
|
|
156
291
|
let seenLargeCount = 0;
|
|
@@ -200,8 +335,8 @@ var getPipeline = async (model, onProgress, options = {}, progressScaleMax = 10)
|
|
|
200
335
|
fileProgress.set(file, 100);
|
|
201
336
|
let actualLoadedSize = 0;
|
|
202
337
|
let actualTotalSize = 0;
|
|
203
|
-
const tinyThreshold =
|
|
204
|
-
const mediumThreshold =
|
|
338
|
+
const tinyThreshold = 102400;
|
|
339
|
+
const mediumThreshold = 104857600;
|
|
205
340
|
let seenTinyCount = 0;
|
|
206
341
|
let seenMediumCount = 0;
|
|
207
342
|
let seenLargeCount = 0;
|
|
@@ -262,6 +397,7 @@ var getPipeline = async (model, onProgress, options = {}, progressScaleMax = 10)
|
|
|
262
397
|
}
|
|
263
398
|
}
|
|
264
399
|
});
|
|
400
|
+
const { pipeline } = await loadTransformersSDK();
|
|
265
401
|
const pipelinePromise = pipeline(pipelineType, model.provider_config.model_path, pipelineOptions);
|
|
266
402
|
try {
|
|
267
403
|
const result = await (abortSignal ? Promise.race([pipelinePromise, abortPromise]) : pipelinePromise);
|
|
@@ -276,14 +412,12 @@ var getPipeline = async (model, onProgress, options = {}, progressScaleMax = 10)
|
|
|
276
412
|
}
|
|
277
413
|
throw error;
|
|
278
414
|
}
|
|
279
|
-
}
|
|
280
|
-
var HFT_Download = async (input, model, onProgress, signal) => {
|
|
415
|
+
}, HFT_Download = async (input, model, onProgress, signal) => {
|
|
281
416
|
await getPipeline(model, onProgress, { abort_signal: signal }, 100);
|
|
282
417
|
return {
|
|
283
418
|
model: input.model
|
|
284
419
|
};
|
|
285
|
-
}
|
|
286
|
-
var HFT_Unload = async (input, model, onProgress, signal) => {
|
|
420
|
+
}, HFT_Unload = async (input, model, onProgress, signal) => {
|
|
287
421
|
const cacheKey = getPipelineCacheKey(model);
|
|
288
422
|
if (pipelines.has(cacheKey)) {
|
|
289
423
|
pipelines.delete(cacheKey);
|
|
@@ -295,8 +429,7 @@ var HFT_Unload = async (input, model, onProgress, signal) => {
|
|
|
295
429
|
return {
|
|
296
430
|
model: input.model
|
|
297
431
|
};
|
|
298
|
-
}
|
|
299
|
-
var deleteModelCache = async (model_path) => {
|
|
432
|
+
}, deleteModelCache = async (model_path) => {
|
|
300
433
|
const cache = await caches.open(HTF_CACHE_NAME);
|
|
301
434
|
const keys = await cache.keys();
|
|
302
435
|
const prefix = `/${model_path}/`;
|
|
@@ -323,8 +456,7 @@ var deleteModelCache = async (model_path) => {
|
|
|
323
456
|
console.error(`Failed to delete cache entry: ${request.url}`, error);
|
|
324
457
|
}
|
|
325
458
|
}
|
|
326
|
-
}
|
|
327
|
-
var HFT_TextEmbedding = async (input, model, onProgress, signal) => {
|
|
459
|
+
}, HFT_TextEmbedding = async (input, model, onProgress, signal) => {
|
|
328
460
|
const generateEmbedding = await getPipeline(model, onProgress, {
|
|
329
461
|
abort_signal: signal
|
|
330
462
|
});
|
|
@@ -351,8 +483,7 @@ var HFT_TextEmbedding = async (input, model, onProgress, signal) => {
|
|
|
351
483
|
throw new Error(`HuggingFace Embedding vector length does not match model dimensions v${hfVector.size} != m${embeddingDim}`);
|
|
352
484
|
}
|
|
353
485
|
return { vector: hfVector.data };
|
|
354
|
-
}
|
|
355
|
-
var HFT_TextClassification = async (input, model, onProgress, signal) => {
|
|
486
|
+
}, HFT_TextClassification = async (input, model, onProgress, signal) => {
|
|
356
487
|
if (model?.provider_config?.pipeline === "zero-shot-classification") {
|
|
357
488
|
if (!input.candidateLabels || !Array.isArray(input.candidateLabels) || input.candidateLabels.length === 0) {
|
|
358
489
|
throw new Error("Zero-shot text classification requires candidate labels");
|
|
@@ -389,8 +520,7 @@ var HFT_TextClassification = async (input, model, onProgress, signal) => {
|
|
|
389
520
|
score: category.score
|
|
390
521
|
}))
|
|
391
522
|
};
|
|
392
|
-
}
|
|
393
|
-
var HFT_TextLanguageDetection = async (input, model, onProgress, signal) => {
|
|
523
|
+
}, HFT_TextLanguageDetection = async (input, model, onProgress, signal) => {
|
|
394
524
|
const TextClassification = await getPipeline(model, onProgress, {
|
|
395
525
|
abort_signal: signal
|
|
396
526
|
});
|
|
@@ -412,8 +542,7 @@ var HFT_TextLanguageDetection = async (input, model, onProgress, signal) => {
|
|
|
412
542
|
score: category.score
|
|
413
543
|
}))
|
|
414
544
|
};
|
|
415
|
-
}
|
|
416
|
-
var HFT_TextNamedEntityRecognition = async (input, model, onProgress, signal) => {
|
|
545
|
+
}, HFT_TextNamedEntityRecognition = async (input, model, onProgress, signal) => {
|
|
417
546
|
const textNamedEntityRecognition = await getPipeline(model, onProgress, {
|
|
418
547
|
abort_signal: signal
|
|
419
548
|
});
|
|
@@ -434,8 +563,7 @@ var HFT_TextNamedEntityRecognition = async (input, model, onProgress, signal) =>
|
|
|
434
563
|
word: entity.word
|
|
435
564
|
}))
|
|
436
565
|
};
|
|
437
|
-
}
|
|
438
|
-
var HFT_TextFillMask = async (input, model, onProgress, signal) => {
|
|
566
|
+
}, HFT_TextFillMask = async (input, model, onProgress, signal) => {
|
|
439
567
|
const unmasker = await getPipeline(model, onProgress, {
|
|
440
568
|
abort_signal: signal
|
|
441
569
|
});
|
|
@@ -453,8 +581,7 @@ var HFT_TextFillMask = async (input, model, onProgress, signal) => {
|
|
|
453
581
|
sequence: prediction.sequence
|
|
454
582
|
}))
|
|
455
583
|
};
|
|
456
|
-
}
|
|
457
|
-
var HFT_TextGeneration = async (input, model, onProgress, signal) => {
|
|
584
|
+
}, HFT_TextGeneration = async (input, model, onProgress, signal) => {
|
|
458
585
|
const generateText = await getPipeline(model, onProgress, {
|
|
459
586
|
abort_signal: signal
|
|
460
587
|
});
|
|
@@ -473,8 +600,7 @@ var HFT_TextGeneration = async (input, model, onProgress, signal) => {
|
|
|
473
600
|
return {
|
|
474
601
|
text
|
|
475
602
|
};
|
|
476
|
-
}
|
|
477
|
-
var HFT_TextTranslation = async (input, model, onProgress, signal) => {
|
|
603
|
+
}, HFT_TextTranslation = async (input, model, onProgress, signal) => {
|
|
478
604
|
const translate = await getPipeline(model, onProgress, {
|
|
479
605
|
abort_signal: signal
|
|
480
606
|
});
|
|
@@ -490,8 +616,7 @@ var HFT_TextTranslation = async (input, model, onProgress, signal) => {
|
|
|
490
616
|
text: translatedText,
|
|
491
617
|
target_lang: input.target_lang
|
|
492
618
|
};
|
|
493
|
-
}
|
|
494
|
-
var HFT_TextRewriter = async (input, model, onProgress, signal) => {
|
|
619
|
+
}, HFT_TextRewriter = async (input, model, onProgress, signal) => {
|
|
495
620
|
const generateText = await getPipeline(model, onProgress, {
|
|
496
621
|
abort_signal: signal
|
|
497
622
|
});
|
|
@@ -515,8 +640,7 @@ var HFT_TextRewriter = async (input, model, onProgress, signal) => {
|
|
|
515
640
|
return {
|
|
516
641
|
text
|
|
517
642
|
};
|
|
518
|
-
}
|
|
519
|
-
var HFT_TextSummary = async (input, model, onProgress, signal) => {
|
|
643
|
+
}, HFT_TextSummary = async (input, model, onProgress, signal) => {
|
|
520
644
|
const generateSummary = await getPipeline(model, onProgress, {
|
|
521
645
|
abort_signal: signal
|
|
522
646
|
});
|
|
@@ -534,8 +658,7 @@ var HFT_TextSummary = async (input, model, onProgress, signal) => {
|
|
|
534
658
|
return {
|
|
535
659
|
text: summaryText
|
|
536
660
|
};
|
|
537
|
-
}
|
|
538
|
-
var HFT_TextQuestionAnswer = async (input, model, onProgress, signal) => {
|
|
661
|
+
}, HFT_TextQuestionAnswer = async (input, model, onProgress, signal) => {
|
|
539
662
|
const generateAnswer = await getPipeline(model, onProgress, {
|
|
540
663
|
abort_signal: signal
|
|
541
664
|
});
|
|
@@ -553,8 +676,7 @@ var HFT_TextQuestionAnswer = async (input, model, onProgress, signal) => {
|
|
|
553
676
|
return {
|
|
554
677
|
text: answerText
|
|
555
678
|
};
|
|
556
|
-
}
|
|
557
|
-
var HFT_ImageSegmentation = async (input, model, onProgress, signal) => {
|
|
679
|
+
}, HFT_ImageSegmentation = async (input, model, onProgress, signal) => {
|
|
558
680
|
const segmenter = await getPipeline(model, onProgress, {
|
|
559
681
|
abort_signal: signal
|
|
560
682
|
});
|
|
@@ -572,8 +694,7 @@ var HFT_ImageSegmentation = async (input, model, onProgress, signal) => {
|
|
|
572
694
|
return {
|
|
573
695
|
masks: processedMasks
|
|
574
696
|
};
|
|
575
|
-
}
|
|
576
|
-
var HFT_ImageToText = async (input, model, onProgress, signal) => {
|
|
697
|
+
}, HFT_ImageToText = async (input, model, onProgress, signal) => {
|
|
577
698
|
const captioner = await getPipeline(model, onProgress, {
|
|
578
699
|
abort_signal: signal
|
|
579
700
|
});
|
|
@@ -585,8 +706,7 @@ var HFT_ImageToText = async (input, model, onProgress, signal) => {
|
|
|
585
706
|
return {
|
|
586
707
|
text: text || ""
|
|
587
708
|
};
|
|
588
|
-
}
|
|
589
|
-
var HFT_BackgroundRemoval = async (input, model, onProgress, signal) => {
|
|
709
|
+
}, HFT_BackgroundRemoval = async (input, model, onProgress, signal) => {
|
|
590
710
|
const remover = await getPipeline(model, onProgress, {
|
|
591
711
|
abort_signal: signal
|
|
592
712
|
});
|
|
@@ -597,8 +717,7 @@ var HFT_BackgroundRemoval = async (input, model, onProgress, signal) => {
|
|
|
597
717
|
return {
|
|
598
718
|
image: imageToBase64(resultImage)
|
|
599
719
|
};
|
|
600
|
-
}
|
|
601
|
-
var HFT_ImageEmbedding = async (input, model, onProgress, signal) => {
|
|
720
|
+
}, HFT_ImageEmbedding = async (input, model, onProgress, signal) => {
|
|
602
721
|
const embedder = await getPipeline(model, onProgress, {
|
|
603
722
|
abort_signal: signal
|
|
604
723
|
});
|
|
@@ -606,8 +725,7 @@ var HFT_ImageEmbedding = async (input, model, onProgress, signal) => {
|
|
|
606
725
|
return {
|
|
607
726
|
vector: result.data
|
|
608
727
|
};
|
|
609
|
-
}
|
|
610
|
-
var HFT_ImageClassification = async (input, model, onProgress, signal) => {
|
|
728
|
+
}, HFT_ImageClassification = async (input, model, onProgress, signal) => {
|
|
611
729
|
if (model?.provider_config?.pipeline === "zero-shot-image-classification") {
|
|
612
730
|
if (!input.categories || !Array.isArray(input.categories) || input.categories.length === 0) {
|
|
613
731
|
console.warn("Zero-shot image classification requires categories", input);
|
|
@@ -639,8 +757,7 @@ var HFT_ImageClassification = async (input, model, onProgress, signal) => {
|
|
|
639
757
|
score: r.score
|
|
640
758
|
}))
|
|
641
759
|
};
|
|
642
|
-
}
|
|
643
|
-
var HFT_ObjectDetection = async (input, model, onProgress, signal) => {
|
|
760
|
+
}, HFT_ObjectDetection = async (input, model, onProgress, signal) => {
|
|
644
761
|
if (model?.provider_config?.pipeline === "zero-shot-object-detection") {
|
|
645
762
|
if (!input.labels || !Array.isArray(input.labels) || input.labels.length === 0) {
|
|
646
763
|
throw new Error("Zero-shot object detection requires labels");
|
|
@@ -675,26 +792,285 @@ var HFT_ObjectDetection = async (input, model, onProgress, signal) => {
|
|
|
675
792
|
box: d.box
|
|
676
793
|
}))
|
|
677
794
|
};
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
callback_function: (text) => {
|
|
688
|
-
count++;
|
|
689
|
-
const result = 100 * (1 - Math.exp(-0.05 * count));
|
|
690
|
-
const progress = Math.round(Math.min(result, 100));
|
|
691
|
-
updateProgress(progress, "Generating", { text, progress });
|
|
692
|
-
},
|
|
795
|
+
}, HFT_TextGeneration_Stream = async function* (input, model, signal) {
|
|
796
|
+
const noopProgress = () => {};
|
|
797
|
+
const generateText = await getPipeline(model, noopProgress, {
|
|
798
|
+
abort_signal: signal
|
|
799
|
+
});
|
|
800
|
+
const queue = createStreamEventQueue();
|
|
801
|
+
const streamer = createStreamingTextStreamer(generateText.tokenizer, queue, signal);
|
|
802
|
+
const pipelinePromise = generateText(input.prompt, {
|
|
803
|
+
streamer,
|
|
693
804
|
...signal ? { abort_signal: signal } : {}
|
|
805
|
+
}).then(() => queue.done(), (err) => queue.error(err));
|
|
806
|
+
yield* queue.iterable;
|
|
807
|
+
await pipelinePromise;
|
|
808
|
+
yield { type: "finish", data: {} };
|
|
809
|
+
}, HFT_TextRewriter_Stream = async function* (input, model, signal) {
|
|
810
|
+
const noopProgress = () => {};
|
|
811
|
+
const generateText = await getPipeline(model, noopProgress, {
|
|
812
|
+
abort_signal: signal
|
|
694
813
|
});
|
|
695
|
-
|
|
696
|
-
|
|
814
|
+
const queue = createStreamEventQueue();
|
|
815
|
+
const streamer = createStreamingTextStreamer(generateText.tokenizer, queue);
|
|
816
|
+
const promptedText = (input.prompt ? input.prompt + `
|
|
817
|
+
` : "") + input.text;
|
|
818
|
+
const pipelinePromise = generateText(promptedText, {
|
|
819
|
+
streamer,
|
|
820
|
+
...signal ? { abort_signal: signal } : {}
|
|
821
|
+
}).then(() => queue.done(), (err) => queue.error(err));
|
|
822
|
+
yield* queue.iterable;
|
|
823
|
+
await pipelinePromise;
|
|
824
|
+
yield { type: "finish", data: {} };
|
|
825
|
+
}, HFT_TextSummary_Stream = async function* (input, model, signal) {
|
|
826
|
+
const noopProgress = () => {};
|
|
827
|
+
const generateSummary = await getPipeline(model, noopProgress, {
|
|
828
|
+
abort_signal: signal
|
|
829
|
+
});
|
|
830
|
+
const queue = createStreamEventQueue();
|
|
831
|
+
const streamer = createStreamingTextStreamer(generateSummary.tokenizer, queue);
|
|
832
|
+
const pipelinePromise = generateSummary(input.text, {
|
|
833
|
+
streamer,
|
|
834
|
+
...signal ? { abort_signal: signal } : {}
|
|
835
|
+
}).then(() => queue.done(), (err) => queue.error(err));
|
|
836
|
+
yield* queue.iterable;
|
|
837
|
+
await pipelinePromise;
|
|
838
|
+
yield { type: "finish", data: {} };
|
|
839
|
+
}, HFT_TextQuestionAnswer_Stream = async function* (input, model, signal) {
|
|
840
|
+
const noopProgress = () => {};
|
|
841
|
+
const generateAnswer = await getPipeline(model, noopProgress, {
|
|
842
|
+
abort_signal: signal
|
|
843
|
+
});
|
|
844
|
+
const queue = createStreamEventQueue();
|
|
845
|
+
const streamer = createStreamingTextStreamer(generateAnswer.tokenizer, queue);
|
|
846
|
+
let pipelineResult;
|
|
847
|
+
const pipelinePromise = generateAnswer(input.question, input.context, {
|
|
848
|
+
streamer,
|
|
849
|
+
...signal ? { abort_signal: signal } : {}
|
|
850
|
+
}).then((result) => {
|
|
851
|
+
pipelineResult = result;
|
|
852
|
+
queue.done();
|
|
853
|
+
}, (err) => queue.error(err));
|
|
854
|
+
yield* queue.iterable;
|
|
855
|
+
await pipelinePromise;
|
|
856
|
+
let answerText = "";
|
|
857
|
+
if (pipelineResult !== undefined) {
|
|
858
|
+
if (Array.isArray(pipelineResult)) {
|
|
859
|
+
answerText = pipelineResult[0]?.answer ?? "";
|
|
860
|
+
} else {
|
|
861
|
+
answerText = pipelineResult?.answer ?? "";
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
yield { type: "finish", data: { text: answerText } };
|
|
865
|
+
}, HFT_TextTranslation_Stream = async function* (input, model, signal) {
|
|
866
|
+
const noopProgress = () => {};
|
|
867
|
+
const translate = await getPipeline(model, noopProgress, {
|
|
868
|
+
abort_signal: signal
|
|
869
|
+
});
|
|
870
|
+
const queue = createStreamEventQueue();
|
|
871
|
+
const streamer = createStreamingTextStreamer(translate.tokenizer, queue);
|
|
872
|
+
const pipelinePromise = translate(input.text, {
|
|
873
|
+
src_lang: input.source_lang,
|
|
874
|
+
tgt_lang: input.target_lang,
|
|
875
|
+
streamer,
|
|
876
|
+
...signal ? { abort_signal: signal } : {}
|
|
877
|
+
}).then(() => queue.done(), (err) => queue.error(err));
|
|
878
|
+
yield* queue.iterable;
|
|
879
|
+
await pipelinePromise;
|
|
880
|
+
yield { type: "finish", data: { target_lang: input.target_lang } };
|
|
881
|
+
}, HFT_TASKS, HFT_STREAM_TASKS;
|
|
882
|
+
var init_HFT_JobRunFns = __esm(() => {
|
|
883
|
+
init_HFT_Constants();
|
|
884
|
+
pipelines = new Map;
|
|
885
|
+
HFT_TASKS = {
|
|
886
|
+
DownloadModelTask: HFT_Download,
|
|
887
|
+
UnloadModelTask: HFT_Unload,
|
|
888
|
+
TextEmbeddingTask: HFT_TextEmbedding,
|
|
889
|
+
TextGenerationTask: HFT_TextGeneration,
|
|
890
|
+
TextQuestionAnswerTask: HFT_TextQuestionAnswer,
|
|
891
|
+
TextLanguageDetectionTask: HFT_TextLanguageDetection,
|
|
892
|
+
TextClassificationTask: HFT_TextClassification,
|
|
893
|
+
TextFillMaskTask: HFT_TextFillMask,
|
|
894
|
+
TextNamedEntityRecognitionTask: HFT_TextNamedEntityRecognition,
|
|
895
|
+
TextRewriterTask: HFT_TextRewriter,
|
|
896
|
+
TextSummaryTask: HFT_TextSummary,
|
|
897
|
+
TextTranslationTask: HFT_TextTranslation,
|
|
898
|
+
ImageSegmentationTask: HFT_ImageSegmentation,
|
|
899
|
+
ImageToTextTask: HFT_ImageToText,
|
|
900
|
+
BackgroundRemovalTask: HFT_BackgroundRemoval,
|
|
901
|
+
ImageEmbeddingTask: HFT_ImageEmbedding,
|
|
902
|
+
ImageClassificationTask: HFT_ImageClassification,
|
|
903
|
+
ObjectDetectionTask: HFT_ObjectDetection
|
|
904
|
+
};
|
|
905
|
+
HFT_STREAM_TASKS = {
|
|
906
|
+
TextGenerationTask: HFT_TextGeneration_Stream,
|
|
907
|
+
TextRewriterTask: HFT_TextRewriter_Stream,
|
|
908
|
+
TextSummaryTask: HFT_TextSummary_Stream,
|
|
909
|
+
TextQuestionAnswerTask: HFT_TextQuestionAnswer_Stream,
|
|
910
|
+
TextTranslationTask: HFT_TextTranslation_Stream
|
|
911
|
+
};
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
// src/anthropic/common/Anthropic_Constants.ts
|
|
915
|
+
var ANTHROPIC = "ANTHROPIC";
|
|
916
|
+
// src/google-gemini/common/Gemini_Constants.ts
|
|
917
|
+
var GOOGLE_GEMINI = "GOOGLE_GEMINI";
|
|
918
|
+
|
|
919
|
+
// src/index.ts
|
|
920
|
+
init_HFT_Constants();
|
|
921
|
+
|
|
922
|
+
// src/provider-ollama/common/Ollama_Constants.ts
|
|
923
|
+
var OLLAMA = "OLLAMA";
|
|
924
|
+
var OLLAMA_DEFAULT_BASE_URL = "http://localhost:11434";
|
|
925
|
+
// src/provider-openai/common/OpenAI_Constants.ts
|
|
926
|
+
var OPENAI = "OPENAI";
|
|
927
|
+
// src/tf-mediapipe/common/TFMP_Constants.ts
|
|
928
|
+
var TENSORFLOW_MEDIAPIPE = "TENSORFLOW_MEDIAPIPE";
|
|
929
|
+
var TextPipelineTask = {
|
|
930
|
+
"text-embedder": "text-embedder",
|
|
931
|
+
"text-classifier": "text-classifier",
|
|
932
|
+
"text-language-detector": "text-language-detector",
|
|
933
|
+
"genai-text": "genai-text",
|
|
934
|
+
"audio-classifier": "audio-classifier",
|
|
935
|
+
"audio-embedder": "audio-embedder",
|
|
936
|
+
"vision-face-detector": "vision-face-detector",
|
|
937
|
+
"vision-face-landmarker": "vision-face-landmarker",
|
|
938
|
+
"vision-face-stylizer": "vision-face-stylizer",
|
|
939
|
+
"vision-gesture-recognizer": "vision-gesture-recognizer",
|
|
940
|
+
"vision-hand-landmarker": "vision-hand-landmarker",
|
|
941
|
+
"vision-holistic-landmarker": "vision-holistic-landmarker",
|
|
942
|
+
"vision-image-classifier": "vision-image-classifier",
|
|
943
|
+
"vision-image-embedder": "vision-image-embedder",
|
|
944
|
+
"vision-image-segmenter": "vision-image-segmenter",
|
|
945
|
+
"vision-image-interactive-segmenter": "vision-image-interactive-segmenter",
|
|
946
|
+
"vision-object-detector": "vision-object-detector",
|
|
947
|
+
"vision-pose-landmarker": "vision-pose-landmarker"
|
|
948
|
+
};
|
|
949
|
+
// src/anthropic/common/Anthropic_ModelSchema.ts
|
|
697
950
|
import { ModelConfigSchema, ModelRecordSchema } from "@workglow/ai";
|
|
951
|
+
var AnthropicModelSchema = {
|
|
952
|
+
type: "object",
|
|
953
|
+
properties: {
|
|
954
|
+
provider: {
|
|
955
|
+
const: ANTHROPIC,
|
|
956
|
+
description: "Discriminator: Anthropic cloud provider."
|
|
957
|
+
},
|
|
958
|
+
provider_config: {
|
|
959
|
+
type: "object",
|
|
960
|
+
description: "Anthropic-specific configuration.",
|
|
961
|
+
properties: {
|
|
962
|
+
model_name: {
|
|
963
|
+
type: "string",
|
|
964
|
+
description: "The Anthropic model identifier (e.g., 'claude-sonnet-4-20250514', 'claude-3-5-haiku-20241022')."
|
|
965
|
+
},
|
|
966
|
+
api_key: {
|
|
967
|
+
type: "string",
|
|
968
|
+
description: "Anthropic API key. Falls back to ANTHROPIC_API_KEY environment variable if not set.",
|
|
969
|
+
"x-ui-hidden": true
|
|
970
|
+
},
|
|
971
|
+
base_url: {
|
|
972
|
+
type: "string",
|
|
973
|
+
description: "Base URL for the Anthropic API (optional)."
|
|
974
|
+
},
|
|
975
|
+
max_tokens: {
|
|
976
|
+
type: "integer",
|
|
977
|
+
description: "Default max tokens for responses. Anthropic requires this parameter.",
|
|
978
|
+
default: 1024,
|
|
979
|
+
minimum: 1
|
|
980
|
+
}
|
|
981
|
+
},
|
|
982
|
+
required: ["model_name"],
|
|
983
|
+
additionalProperties: false
|
|
984
|
+
}
|
|
985
|
+
},
|
|
986
|
+
required: ["provider", "provider_config"],
|
|
987
|
+
additionalProperties: true
|
|
988
|
+
};
|
|
989
|
+
var AnthropicModelRecordSchema = {
|
|
990
|
+
type: "object",
|
|
991
|
+
properties: {
|
|
992
|
+
...ModelRecordSchema.properties,
|
|
993
|
+
...AnthropicModelSchema.properties
|
|
994
|
+
},
|
|
995
|
+
required: [...ModelRecordSchema.required, ...AnthropicModelSchema.required],
|
|
996
|
+
additionalProperties: false
|
|
997
|
+
};
|
|
998
|
+
var AnthropicModelConfigSchema = {
|
|
999
|
+
type: "object",
|
|
1000
|
+
properties: {
|
|
1001
|
+
...ModelConfigSchema.properties,
|
|
1002
|
+
...AnthropicModelSchema.properties
|
|
1003
|
+
},
|
|
1004
|
+
required: [...ModelConfigSchema.required, ...AnthropicModelSchema.required],
|
|
1005
|
+
additionalProperties: false
|
|
1006
|
+
};
|
|
1007
|
+
// src/google-gemini/common/Gemini_ModelSchema.ts
|
|
1008
|
+
import { ModelConfigSchema as ModelConfigSchema2, ModelRecordSchema as ModelRecordSchema2 } from "@workglow/ai";
|
|
1009
|
+
var GeminiModelSchema = {
|
|
1010
|
+
type: "object",
|
|
1011
|
+
properties: {
|
|
1012
|
+
provider: {
|
|
1013
|
+
const: GOOGLE_GEMINI,
|
|
1014
|
+
description: "Discriminator: Google Gemini cloud provider."
|
|
1015
|
+
},
|
|
1016
|
+
provider_config: {
|
|
1017
|
+
type: "object",
|
|
1018
|
+
description: "Google Gemini-specific configuration.",
|
|
1019
|
+
properties: {
|
|
1020
|
+
model_name: {
|
|
1021
|
+
type: "string",
|
|
1022
|
+
description: "The Gemini model identifier (e.g., 'gemini-2.0-flash', 'text-embedding-004')."
|
|
1023
|
+
},
|
|
1024
|
+
api_key: {
|
|
1025
|
+
type: "string",
|
|
1026
|
+
description: "Google AI API key. Falls back to default API key if not set."
|
|
1027
|
+
},
|
|
1028
|
+
embedding_task_type: {
|
|
1029
|
+
oneOf: [
|
|
1030
|
+
{ type: "null" },
|
|
1031
|
+
{
|
|
1032
|
+
type: "string",
|
|
1033
|
+
enum: [
|
|
1034
|
+
"RETRIEVAL_QUERY",
|
|
1035
|
+
"RETRIEVAL_DOCUMENT",
|
|
1036
|
+
"SEMANTIC_SIMILARITY",
|
|
1037
|
+
"CLASSIFICATION",
|
|
1038
|
+
"CLUSTERING"
|
|
1039
|
+
]
|
|
1040
|
+
}
|
|
1041
|
+
],
|
|
1042
|
+
description: "Task type hint for embedding models.",
|
|
1043
|
+
default: null
|
|
1044
|
+
}
|
|
1045
|
+
},
|
|
1046
|
+
required: ["model_name"],
|
|
1047
|
+
additionalProperties: false
|
|
1048
|
+
}
|
|
1049
|
+
},
|
|
1050
|
+
required: ["provider", "provider_config"],
|
|
1051
|
+
additionalProperties: true
|
|
1052
|
+
};
|
|
1053
|
+
var GeminiModelRecordSchema = {
|
|
1054
|
+
type: "object",
|
|
1055
|
+
properties: {
|
|
1056
|
+
...ModelRecordSchema2.properties,
|
|
1057
|
+
...GeminiModelSchema.properties
|
|
1058
|
+
},
|
|
1059
|
+
required: [...ModelRecordSchema2.required, ...GeminiModelSchema.required],
|
|
1060
|
+
additionalProperties: false
|
|
1061
|
+
};
|
|
1062
|
+
var GeminiModelConfigSchema = {
|
|
1063
|
+
type: "object",
|
|
1064
|
+
properties: {
|
|
1065
|
+
...ModelConfigSchema2.properties,
|
|
1066
|
+
...GeminiModelSchema.properties
|
|
1067
|
+
},
|
|
1068
|
+
required: [...ModelConfigSchema2.required, ...GeminiModelSchema.required],
|
|
1069
|
+
additionalProperties: false
|
|
1070
|
+
};
|
|
1071
|
+
// src/hf-transformers/common/HFT_ModelSchema.ts
|
|
1072
|
+
init_HFT_Constants();
|
|
1073
|
+
import { ModelConfigSchema as ModelConfigSchema3, ModelRecordSchema as ModelRecordSchema3 } from "@workglow/ai";
|
|
698
1074
|
var HfTransformersOnnxModelSchema = {
|
|
699
1075
|
type: "object",
|
|
700
1076
|
properties: {
|
|
@@ -791,638 +1167,127 @@ var HfTransformersOnnxModelSchema = {
|
|
|
791
1167
|
var HfTransformersOnnxModelRecordSchema = {
|
|
792
1168
|
type: "object",
|
|
793
1169
|
properties: {
|
|
794
|
-
...
|
|
1170
|
+
...ModelRecordSchema3.properties,
|
|
795
1171
|
...HfTransformersOnnxModelSchema.properties
|
|
796
1172
|
},
|
|
797
|
-
required: [...
|
|
1173
|
+
required: [...ModelRecordSchema3.required, ...HfTransformersOnnxModelSchema.required],
|
|
798
1174
|
additionalProperties: false
|
|
799
1175
|
};
|
|
800
1176
|
var HfTransformersOnnxModelConfigSchema = {
|
|
801
1177
|
type: "object",
|
|
802
1178
|
properties: {
|
|
803
|
-
...
|
|
1179
|
+
...ModelConfigSchema3.properties,
|
|
804
1180
|
...HfTransformersOnnxModelSchema.properties
|
|
805
1181
|
},
|
|
806
|
-
required: [...
|
|
1182
|
+
required: [...ModelConfigSchema3.required, ...HfTransformersOnnxModelSchema.required],
|
|
807
1183
|
additionalProperties: false
|
|
808
1184
|
};
|
|
809
|
-
// src/
|
|
810
|
-
import {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
workerManager.registerWorker(HF_TRANSFORMERS_ONNX, worker);
|
|
818
|
-
const ProviderRegistry = getAiProviderRegistry();
|
|
819
|
-
const names = [
|
|
820
|
-
"DownloadModelTask",
|
|
821
|
-
"UnloadModelTask",
|
|
822
|
-
"TextEmbeddingTask",
|
|
823
|
-
"TextLanguageDetectionTask",
|
|
824
|
-
"TextClassificationTask",
|
|
825
|
-
"TextFillMaskTask",
|
|
826
|
-
"TextNamedEntityRecognitionTask",
|
|
827
|
-
"TextGenerationTask",
|
|
828
|
-
"TextTranslationTask",
|
|
829
|
-
"TextRewriterTask",
|
|
830
|
-
"TextSummaryTask",
|
|
831
|
-
"TextQuestionAnswerTask",
|
|
832
|
-
"ImageSegmentationTask",
|
|
833
|
-
"ImageToTextTask",
|
|
834
|
-
"BackgroundRemovalTask",
|
|
835
|
-
"ImageEmbeddingTask",
|
|
836
|
-
"ImageClassificationTask",
|
|
837
|
-
"ObjectDetectionTask"
|
|
838
|
-
];
|
|
839
|
-
for (const name of names) {
|
|
840
|
-
ProviderRegistry.registerAsWorkerRunFn(HF_TRANSFORMERS_ONNX, name);
|
|
841
|
-
}
|
|
842
|
-
if (!client) {
|
|
843
|
-
const storage = new InMemoryQueueStorage(HF_TRANSFORMERS_ONNX);
|
|
844
|
-
const server = new JobQueueServer(AiJob, {
|
|
845
|
-
storage,
|
|
846
|
-
queueName: HF_TRANSFORMERS_ONNX,
|
|
847
|
-
limiter: new ConcurrencyLimiter(1, 100)
|
|
848
|
-
});
|
|
849
|
-
client = new JobQueueClient({
|
|
850
|
-
storage,
|
|
851
|
-
queueName: HF_TRANSFORMERS_ONNX
|
|
852
|
-
});
|
|
853
|
-
client.attach(server);
|
|
854
|
-
getTaskQueueRegistry().registerQueue({ server, client, storage });
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
// src/hf-transformers/registry/HFT_Inline_RegisterJobFns.ts
|
|
858
|
-
import { env } from "@sroussey/transformers";
|
|
859
|
-
import { AiJob as AiJob2, getAiProviderRegistry as getAiProviderRegistry2 } from "@workglow/ai";
|
|
860
|
-
import { ConcurrencyLimiter as ConcurrencyLimiter2, JobQueueClient as JobQueueClient2, JobQueueServer as JobQueueServer2 } from "@workglow/job-queue";
|
|
861
|
-
import { InMemoryQueueStorage as InMemoryQueueStorage2 } from "@workglow/storage";
|
|
862
|
-
import { getTaskQueueRegistry as getTaskQueueRegistry2 } from "@workglow/task-graph";
|
|
863
|
-
async function register_HFT_InlineJobFns(client) {
|
|
864
|
-
env.backends.onnx.wasm.proxy = true;
|
|
865
|
-
const ProviderRegistry = getAiProviderRegistry2();
|
|
866
|
-
const fns = {
|
|
867
|
-
["DownloadModelTask"]: HFT_Download,
|
|
868
|
-
["UnloadModelTask"]: HFT_Unload,
|
|
869
|
-
["TextEmbeddingTask"]: HFT_TextEmbedding,
|
|
870
|
-
["TextGenerationTask"]: HFT_TextGeneration,
|
|
871
|
-
["TextQuestionAnswerTask"]: HFT_TextQuestionAnswer,
|
|
872
|
-
["TextLanguageDetectionTask"]: HFT_TextLanguageDetection,
|
|
873
|
-
["TextClassificationTask"]: HFT_TextClassification,
|
|
874
|
-
["TextFillMaskTask"]: HFT_TextFillMask,
|
|
875
|
-
["TextNamedEntityRecognitionTask"]: HFT_TextNamedEntityRecognition,
|
|
876
|
-
["TextRewriterTask"]: HFT_TextRewriter,
|
|
877
|
-
["TextSummaryTask"]: HFT_TextSummary,
|
|
878
|
-
["TextTranslationTask"]: HFT_TextTranslation,
|
|
879
|
-
["ImageSegmentationTask"]: HFT_ImageSegmentation,
|
|
880
|
-
["ImageToTextTask"]: HFT_ImageToText,
|
|
881
|
-
["BackgroundRemovalTask"]: HFT_BackgroundRemoval,
|
|
882
|
-
["ImageEmbeddingTask"]: HFT_ImageEmbedding,
|
|
883
|
-
["ImageClassificationTask"]: HFT_ImageClassification,
|
|
884
|
-
["ObjectDetectionTask"]: HFT_ObjectDetection
|
|
885
|
-
};
|
|
886
|
-
for (const [jobName, fn] of Object.entries(fns)) {
|
|
887
|
-
ProviderRegistry.registerRunFn(HF_TRANSFORMERS_ONNX, jobName, fn);
|
|
888
|
-
}
|
|
889
|
-
if (!client) {
|
|
890
|
-
const storage = new InMemoryQueueStorage2(HF_TRANSFORMERS_ONNX);
|
|
891
|
-
await storage.setupDatabase();
|
|
892
|
-
const server = new JobQueueServer2(AiJob2, {
|
|
893
|
-
storage,
|
|
894
|
-
queueName: HF_TRANSFORMERS_ONNX,
|
|
895
|
-
limiter: new ConcurrencyLimiter2(1, 100)
|
|
896
|
-
});
|
|
897
|
-
client = new JobQueueClient2({
|
|
898
|
-
storage,
|
|
899
|
-
queueName: HF_TRANSFORMERS_ONNX
|
|
900
|
-
});
|
|
901
|
-
client.attach(server);
|
|
902
|
-
getTaskQueueRegistry2().registerQueue({ server, client, storage });
|
|
903
|
-
await server.start();
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
// src/hf-transformers/registry/HFT_Worker_RegisterJobFns.ts
|
|
907
|
-
import {
|
|
908
|
-
createServiceToken,
|
|
909
|
-
globalServiceRegistry as globalServiceRegistry2,
|
|
910
|
-
parentPort,
|
|
911
|
-
WORKER_SERVER
|
|
912
|
-
} from "@workglow/util";
|
|
913
|
-
var HFT_WORKER_JOBRUN = createServiceToken("worker.ai-provider.hft");
|
|
914
|
-
var HFT_WORKER_JOBRUN_REGISTER = globalServiceRegistry2.register(HFT_WORKER_JOBRUN, () => {
|
|
915
|
-
const workerServer = globalServiceRegistry2.get(WORKER_SERVER);
|
|
916
|
-
workerServer.registerFunction("DownloadModelTask", HFT_Download);
|
|
917
|
-
workerServer.registerFunction("UnloadModelTask", HFT_Unload);
|
|
918
|
-
workerServer.registerFunction("TextEmbeddingTask", HFT_TextEmbedding);
|
|
919
|
-
workerServer.registerFunction("TextGenerationTask", HFT_TextGeneration);
|
|
920
|
-
workerServer.registerFunction("TextLanguageDetectionTask", HFT_TextLanguageDetection);
|
|
921
|
-
workerServer.registerFunction("TextClassificationTask", HFT_TextClassification);
|
|
922
|
-
workerServer.registerFunction("TextFillMaskTask", HFT_TextFillMask);
|
|
923
|
-
workerServer.registerFunction("TextNamedEntityRecognitionTask", HFT_TextNamedEntityRecognition);
|
|
924
|
-
workerServer.registerFunction("TextTranslationTask", HFT_TextTranslation);
|
|
925
|
-
workerServer.registerFunction("TextRewriterTask", HFT_TextRewriter);
|
|
926
|
-
workerServer.registerFunction("TextSummaryTask", HFT_TextSummary);
|
|
927
|
-
workerServer.registerFunction("TextQuestionAnswerTask", HFT_TextQuestionAnswer);
|
|
928
|
-
workerServer.registerFunction("ImageSegmentationTask", HFT_ImageSegmentation);
|
|
929
|
-
workerServer.registerFunction("ImageToTextTask", HFT_ImageToText);
|
|
930
|
-
workerServer.registerFunction("BackgroundRemovalTask", HFT_BackgroundRemoval);
|
|
931
|
-
workerServer.registerFunction("ImageEmbeddingTask", HFT_ImageEmbedding);
|
|
932
|
-
workerServer.registerFunction("ImageClassificationTask", HFT_ImageClassification);
|
|
933
|
-
workerServer.registerFunction("ObjectDetectionTask", HFT_ObjectDetection);
|
|
934
|
-
parentPort.postMessage({ type: "ready" });
|
|
935
|
-
console.log("HFT_WORKER_JOBRUN registered");
|
|
936
|
-
return workerServer;
|
|
937
|
-
}, true);
|
|
938
|
-
// src/tf-mediapipe/common/TFMP_Constants.ts
|
|
939
|
-
var TENSORFLOW_MEDIAPIPE = "TENSORFLOW_MEDIAPIPE";
|
|
940
|
-
var TextPipelineTask = {
|
|
941
|
-
"text-embedder": "text-embedder",
|
|
942
|
-
"text-classifier": "text-classifier",
|
|
943
|
-
"text-language-detector": "text-language-detector",
|
|
944
|
-
"genai-text": "genai-text",
|
|
945
|
-
"audio-classifier": "audio-classifier",
|
|
946
|
-
"audio-embedder": "audio-embedder",
|
|
947
|
-
"vision-face-detector": "vision-face-detector",
|
|
948
|
-
"vision-face-landmarker": "vision-face-landmarker",
|
|
949
|
-
"vision-face-stylizer": "vision-face-stylizer",
|
|
950
|
-
"vision-gesture-recognizer": "vision-gesture-recognizer",
|
|
951
|
-
"vision-hand-landmarker": "vision-hand-landmarker",
|
|
952
|
-
"vision-holistic-landmarker": "vision-holistic-landmarker",
|
|
953
|
-
"vision-image-classifier": "vision-image-classifier",
|
|
954
|
-
"vision-image-embedder": "vision-image-embedder",
|
|
955
|
-
"vision-image-segmenter": "vision-image-segmenter",
|
|
956
|
-
"vision-image-interactive-segmenter": "vision-image-interactive-segmenter",
|
|
957
|
-
"vision-object-detector": "vision-object-detector",
|
|
958
|
-
"vision-pose-landmarker": "vision-pose-landmarker"
|
|
959
|
-
};
|
|
960
|
-
// src/tf-mediapipe/common/TFMP_JobRunFns.ts
|
|
961
|
-
import {
|
|
962
|
-
FilesetResolver,
|
|
963
|
-
LanguageDetector,
|
|
964
|
-
TextClassifier,
|
|
965
|
-
TextEmbedder
|
|
966
|
-
} from "@mediapipe/tasks-text";
|
|
967
|
-
import {
|
|
968
|
-
FaceDetector,
|
|
969
|
-
FaceLandmarker,
|
|
970
|
-
GestureRecognizer,
|
|
971
|
-
HandLandmarker,
|
|
972
|
-
ImageClassifier,
|
|
973
|
-
ImageEmbedder,
|
|
974
|
-
ImageSegmenter,
|
|
975
|
-
ObjectDetector,
|
|
976
|
-
PoseLandmarker
|
|
977
|
-
} from "@mediapipe/tasks-vision";
|
|
978
|
-
import { PermanentJobError } from "@workglow/job-queue";
|
|
979
|
-
var wasm_tasks = new Map;
|
|
980
|
-
var wasm_reference_counts = new Map;
|
|
981
|
-
var getWasmTask = async (model, onProgress, signal) => {
|
|
982
|
-
const task_engine = model.provider_config.task_engine;
|
|
983
|
-
if (wasm_tasks.has(task_engine)) {
|
|
984
|
-
return wasm_tasks.get(task_engine);
|
|
985
|
-
}
|
|
986
|
-
if (signal.aborted) {
|
|
987
|
-
throw new PermanentJobError("Aborted job");
|
|
988
|
-
}
|
|
989
|
-
onProgress(0.1, "Loading WASM task");
|
|
990
|
-
let wasmFileset;
|
|
991
|
-
switch (task_engine) {
|
|
992
|
-
case "text":
|
|
993
|
-
wasmFileset = await FilesetResolver.forTextTasks("https://cdn.jsdelivr.net/npm/@mediapipe/tasks-text@latest/wasm");
|
|
994
|
-
break;
|
|
995
|
-
case "audio":
|
|
996
|
-
wasmFileset = await FilesetResolver.forAudioTasks("https://cdn.jsdelivr.net/npm/@mediapipe/tasks-audio@latest/wasm");
|
|
997
|
-
break;
|
|
998
|
-
case "vision":
|
|
999
|
-
wasmFileset = await FilesetResolver.forVisionTasks("https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm");
|
|
1000
|
-
break;
|
|
1001
|
-
case "genai":
|
|
1002
|
-
wasmFileset = await FilesetResolver.forGenAiTasks("https://cdn.jsdelivr.net/npm/@mediapipe/tasks-genai@latest/wasm");
|
|
1003
|
-
break;
|
|
1004
|
-
default:
|
|
1005
|
-
throw new PermanentJobError("Invalid task engine");
|
|
1006
|
-
}
|
|
1007
|
-
wasm_tasks.set(task_engine, wasmFileset);
|
|
1008
|
-
return wasmFileset;
|
|
1009
|
-
};
|
|
1010
|
-
var modelTaskCache = new Map;
|
|
1011
|
-
var optionsMatch = (opts1, opts2) => {
|
|
1012
|
-
const keys1 = Object.keys(opts1).sort();
|
|
1013
|
-
const keys2 = Object.keys(opts2).sort();
|
|
1014
|
-
if (keys1.length !== keys2.length)
|
|
1015
|
-
return false;
|
|
1016
|
-
return keys1.every((key) => {
|
|
1017
|
-
const val1 = opts1[key];
|
|
1018
|
-
const val2 = opts2[key];
|
|
1019
|
-
if (Array.isArray(val1) && Array.isArray(val2)) {
|
|
1020
|
-
return JSON.stringify(val1) === JSON.stringify(val2);
|
|
1021
|
-
}
|
|
1022
|
-
return val1 === val2;
|
|
1023
|
-
});
|
|
1024
|
-
};
|
|
1025
|
-
var getModelTask = async (model, options, onProgress, signal, TaskType) => {
|
|
1026
|
-
const model_path = model.provider_config.model_path;
|
|
1027
|
-
const task_engine = model.provider_config.task_engine;
|
|
1028
|
-
const cachedTasks = modelTaskCache.get(model_path);
|
|
1029
|
-
if (cachedTasks) {
|
|
1030
|
-
const matchedTask = cachedTasks.find((cached) => optionsMatch(cached.options, options));
|
|
1031
|
-
if (matchedTask) {
|
|
1032
|
-
return matchedTask.task;
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
const wasmFileset = await getWasmTask(model, onProgress, signal);
|
|
1036
|
-
onProgress(0.2, "Creating model task");
|
|
1037
|
-
const task = await TaskType.createFromOptions(wasmFileset, {
|
|
1038
|
-
baseOptions: {
|
|
1039
|
-
modelAssetPath: model_path
|
|
1185
|
+
// src/provider-ollama/common/Ollama_ModelSchema.ts
|
|
1186
|
+
import { ModelConfigSchema as ModelConfigSchema4, ModelRecordSchema as ModelRecordSchema4 } from "@workglow/ai";
|
|
1187
|
+
var OllamaModelSchema = {
|
|
1188
|
+
type: "object",
|
|
1189
|
+
properties: {
|
|
1190
|
+
provider: {
|
|
1191
|
+
const: OLLAMA,
|
|
1192
|
+
description: "Discriminator: Ollama local LLM server."
|
|
1040
1193
|
},
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
case "text-classifier":
|
|
1058
|
-
task = await getModelTask(model, {}, onProgress, signal, TextClassifier);
|
|
1059
|
-
break;
|
|
1060
|
-
case "text-language-detector":
|
|
1061
|
-
task = await getModelTask(model, {}, onProgress, signal, LanguageDetector);
|
|
1062
|
-
break;
|
|
1063
|
-
case "vision-image-classifier":
|
|
1064
|
-
task = await getModelTask(model, {}, onProgress, signal, ImageClassifier);
|
|
1065
|
-
break;
|
|
1066
|
-
case "vision-image-embedder":
|
|
1067
|
-
task = await getModelTask(model, {}, onProgress, signal, ImageEmbedder);
|
|
1068
|
-
break;
|
|
1069
|
-
case "vision-image-segmenter":
|
|
1070
|
-
task = await getModelTask(model, {}, onProgress, signal, ImageSegmenter);
|
|
1071
|
-
break;
|
|
1072
|
-
case "vision-object-detector":
|
|
1073
|
-
task = await getModelTask(model, {}, onProgress, signal, ObjectDetector);
|
|
1074
|
-
break;
|
|
1075
|
-
case "vision-face-detector":
|
|
1076
|
-
task = await getModelTask(model, {}, onProgress, signal, FaceDetector);
|
|
1077
|
-
break;
|
|
1078
|
-
case "vision-face-landmarker":
|
|
1079
|
-
task = await getModelTask(model, {}, onProgress, signal, FaceLandmarker);
|
|
1080
|
-
break;
|
|
1081
|
-
case "vision-gesture-recognizer":
|
|
1082
|
-
task = await getModelTask(model, {}, onProgress, signal, GestureRecognizer);
|
|
1083
|
-
break;
|
|
1084
|
-
case "vision-hand-landmarker":
|
|
1085
|
-
task = await getModelTask(model, {}, onProgress, signal, HandLandmarker);
|
|
1086
|
-
break;
|
|
1087
|
-
case "vision-pose-landmarker":
|
|
1088
|
-
task = await getModelTask(model, {}, onProgress, signal, PoseLandmarker);
|
|
1089
|
-
break;
|
|
1090
|
-
default:
|
|
1091
|
-
throw new PermanentJobError(`Invalid pipeline: ${model?.provider_config.pipeline}. Supported pipelines: text-embedder, text-classifier, text-language-detector, vision-image-classifier, vision-image-embedder, vision-image-segmenter, vision-object-detector, vision-face-detector, vision-face-landmarker, vision-gesture-recognizer, vision-hand-landmarker, vision-pose-landmarker`);
|
|
1092
|
-
}
|
|
1093
|
-
onProgress(0.9, "Pipeline loaded");
|
|
1094
|
-
task.close();
|
|
1095
|
-
const task_engine = model?.provider_config.task_engine;
|
|
1096
|
-
wasm_reference_counts.set(task_engine, wasm_reference_counts.get(task_engine) - 1);
|
|
1097
|
-
return {
|
|
1098
|
-
model: input.model
|
|
1099
|
-
};
|
|
1100
|
-
};
|
|
1101
|
-
var TFMP_TextEmbedding = async (input, model, onProgress, signal) => {
|
|
1102
|
-
const textEmbedder = await getModelTask(model, {}, onProgress, signal, TextEmbedder);
|
|
1103
|
-
if (Array.isArray(input.text)) {
|
|
1104
|
-
const embeddings = input.text.map((text) => {
|
|
1105
|
-
const result2 = textEmbedder.embed(text);
|
|
1106
|
-
if (!result2.embeddings?.[0]?.floatEmbedding) {
|
|
1107
|
-
throw new PermanentJobError("Failed to generate embedding: Empty result");
|
|
1108
|
-
}
|
|
1109
|
-
return Float32Array.from(result2.embeddings[0].floatEmbedding);
|
|
1110
|
-
});
|
|
1111
|
-
return {
|
|
1112
|
-
vector: embeddings
|
|
1113
|
-
};
|
|
1114
|
-
}
|
|
1115
|
-
const result = textEmbedder.embed(input.text);
|
|
1116
|
-
if (!result.embeddings?.[0]?.floatEmbedding) {
|
|
1117
|
-
throw new PermanentJobError("Failed to generate embedding: Empty result");
|
|
1118
|
-
}
|
|
1119
|
-
const embedding = Float32Array.from(result.embeddings[0].floatEmbedding);
|
|
1120
|
-
return {
|
|
1121
|
-
vector: embedding
|
|
1122
|
-
};
|
|
1123
|
-
};
|
|
1124
|
-
var TFMP_TextClassification = async (input, model, onProgress, signal) => {
|
|
1125
|
-
const TextClassification = await getModelTask(model, {
|
|
1126
|
-
maxCategories: input.maxCategories
|
|
1127
|
-
}, onProgress, signal, TextClassifier);
|
|
1128
|
-
const result = TextClassification.classify(input.text);
|
|
1129
|
-
if (!result.classifications?.[0]?.categories) {
|
|
1130
|
-
throw new PermanentJobError("Failed to classify text: Empty result");
|
|
1131
|
-
}
|
|
1132
|
-
const categories = result.classifications[0].categories.map((category) => ({
|
|
1133
|
-
label: category.categoryName,
|
|
1134
|
-
score: category.score
|
|
1135
|
-
}));
|
|
1136
|
-
return {
|
|
1137
|
-
categories
|
|
1138
|
-
};
|
|
1139
|
-
};
|
|
1140
|
-
var TFMP_TextLanguageDetection = async (input, model, onProgress, signal) => {
|
|
1141
|
-
const maxLanguages = input.maxLanguages === 0 ? -1 : input.maxLanguages;
|
|
1142
|
-
const textLanguageDetector = await getModelTask(model, {
|
|
1143
|
-
maxLanguages
|
|
1144
|
-
}, onProgress, signal, LanguageDetector);
|
|
1145
|
-
const result = textLanguageDetector.detect(input.text);
|
|
1146
|
-
if (!result.languages?.[0]?.languageCode) {
|
|
1147
|
-
throw new PermanentJobError("Failed to detect language: Empty result");
|
|
1148
|
-
}
|
|
1149
|
-
const languages = result.languages.map((language) => ({
|
|
1150
|
-
language: language.languageCode,
|
|
1151
|
-
score: language.probability
|
|
1152
|
-
}));
|
|
1153
|
-
return {
|
|
1154
|
-
languages
|
|
1155
|
-
};
|
|
1156
|
-
};
|
|
1157
|
-
var TFMP_Unload = async (input, model, onProgress, signal) => {
|
|
1158
|
-
const model_path = model.provider_config.model_path;
|
|
1159
|
-
onProgress(10, "Unloading model");
|
|
1160
|
-
if (modelTaskCache.has(model_path)) {
|
|
1161
|
-
const cachedTasks = modelTaskCache.get(model_path);
|
|
1162
|
-
for (const cachedTask of cachedTasks) {
|
|
1163
|
-
const task = cachedTask.task;
|
|
1164
|
-
if ("close" in task && typeof task.close === "function")
|
|
1165
|
-
task.close();
|
|
1166
|
-
const task_engine = cachedTask.task_engine;
|
|
1167
|
-
const currentCount = wasm_reference_counts.get(task_engine) || 0;
|
|
1168
|
-
const newCount = currentCount - 1;
|
|
1169
|
-
if (newCount <= 0) {
|
|
1170
|
-
wasm_tasks.delete(task_engine);
|
|
1171
|
-
wasm_reference_counts.delete(task_engine);
|
|
1172
|
-
} else {
|
|
1173
|
-
wasm_reference_counts.set(task_engine, newCount);
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
modelTaskCache.delete(model_path);
|
|
1177
|
-
}
|
|
1178
|
-
return {
|
|
1179
|
-
model: input.model
|
|
1180
|
-
};
|
|
1181
|
-
};
|
|
1182
|
-
var TFMP_ImageSegmentation = async (input, model, onProgress, signal) => {
|
|
1183
|
-
const imageSegmenter = await getModelTask(model, {}, onProgress, signal, ImageSegmenter);
|
|
1184
|
-
const result = imageSegmenter.segment(input.image);
|
|
1185
|
-
if (!result.categoryMask) {
|
|
1186
|
-
throw new PermanentJobError("Failed to segment image: Empty result");
|
|
1187
|
-
}
|
|
1188
|
-
const masks = [
|
|
1189
|
-
{
|
|
1190
|
-
label: "segment",
|
|
1191
|
-
score: 1,
|
|
1192
|
-
mask: {
|
|
1193
|
-
data: result.categoryMask.canvas,
|
|
1194
|
-
width: result.categoryMask.width,
|
|
1195
|
-
height: result.categoryMask.height
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
];
|
|
1199
|
-
return {
|
|
1200
|
-
masks
|
|
1201
|
-
};
|
|
1202
|
-
};
|
|
1203
|
-
var TFMP_ImageEmbedding = async (input, model, onProgress, signal) => {
|
|
1204
|
-
const imageEmbedder = await getModelTask(model, {}, onProgress, signal, ImageEmbedder);
|
|
1205
|
-
const result = imageEmbedder.embed(input.image);
|
|
1206
|
-
if (!result.embeddings?.[0]?.floatEmbedding) {
|
|
1207
|
-
throw new PermanentJobError("Failed to generate embedding: Empty result");
|
|
1208
|
-
}
|
|
1209
|
-
const embedding = Float32Array.from(result.embeddings[0].floatEmbedding);
|
|
1210
|
-
return {
|
|
1211
|
-
vector: embedding
|
|
1212
|
-
};
|
|
1213
|
-
};
|
|
1214
|
-
var TFMP_ImageClassification = async (input, model, onProgress, signal) => {
|
|
1215
|
-
const imageClassifier = await getModelTask(model, {
|
|
1216
|
-
maxResults: input.maxCategories
|
|
1217
|
-
}, onProgress, signal, ImageClassifier);
|
|
1218
|
-
const result = imageClassifier.classify(input.image);
|
|
1219
|
-
if (!result.classifications?.[0]?.categories) {
|
|
1220
|
-
throw new PermanentJobError("Failed to classify image: Empty result");
|
|
1221
|
-
}
|
|
1222
|
-
const categories = result.classifications[0].categories.map((category) => ({
|
|
1223
|
-
label: category.categoryName,
|
|
1224
|
-
score: category.score
|
|
1225
|
-
}));
|
|
1226
|
-
return {
|
|
1227
|
-
categories
|
|
1228
|
-
};
|
|
1229
|
-
};
|
|
1230
|
-
var TFMP_ObjectDetection = async (input, model, onProgress, signal) => {
|
|
1231
|
-
const objectDetector = await getModelTask(model, {
|
|
1232
|
-
scoreThreshold: input.threshold
|
|
1233
|
-
}, onProgress, signal, ObjectDetector);
|
|
1234
|
-
const result = objectDetector.detect(input.image);
|
|
1235
|
-
if (!result.detections) {
|
|
1236
|
-
throw new PermanentJobError("Failed to detect objects: Empty result");
|
|
1237
|
-
}
|
|
1238
|
-
const detections = result.detections.map((detection) => ({
|
|
1239
|
-
label: detection.categories?.[0]?.categoryName || "unknown",
|
|
1240
|
-
score: detection.categories?.[0]?.score || 0,
|
|
1241
|
-
box: {
|
|
1242
|
-
x: detection.boundingBox?.originX || 0,
|
|
1243
|
-
y: detection.boundingBox?.originY || 0,
|
|
1244
|
-
width: detection.boundingBox?.width || 0,
|
|
1245
|
-
height: detection.boundingBox?.height || 0
|
|
1194
|
+
provider_config: {
|
|
1195
|
+
type: "object",
|
|
1196
|
+
description: "Ollama-specific configuration.",
|
|
1197
|
+
properties: {
|
|
1198
|
+
model_name: {
|
|
1199
|
+
type: "string",
|
|
1200
|
+
description: "The Ollama model identifier (e.g., 'llama3.2', 'nomic-embed-text')."
|
|
1201
|
+
},
|
|
1202
|
+
base_url: {
|
|
1203
|
+
type: "string",
|
|
1204
|
+
description: "Base URL for the Ollama server.",
|
|
1205
|
+
default: OLLAMA_DEFAULT_BASE_URL
|
|
1206
|
+
}
|
|
1207
|
+
},
|
|
1208
|
+
required: ["model_name"],
|
|
1209
|
+
additionalProperties: false
|
|
1246
1210
|
}
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
};
|
|
1211
|
+
},
|
|
1212
|
+
required: ["provider", "provider_config"],
|
|
1213
|
+
additionalProperties: true
|
|
1251
1214
|
};
|
|
1252
|
-
var
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
if (!result.gestures || !result.landmarks) {
|
|
1261
|
-
throw new PermanentJobError("Failed to recognize gestures: Empty result");
|
|
1262
|
-
}
|
|
1263
|
-
const hands = result.gestures.map((gestures, index) => ({
|
|
1264
|
-
gestures: gestures.map((g) => ({
|
|
1265
|
-
label: g.categoryName,
|
|
1266
|
-
score: g.score
|
|
1267
|
-
})),
|
|
1268
|
-
handedness: result.handedness[index].map((h) => ({
|
|
1269
|
-
label: h.categoryName,
|
|
1270
|
-
score: h.score
|
|
1271
|
-
})),
|
|
1272
|
-
landmarks: result.landmarks[index].map((l) => ({
|
|
1273
|
-
x: l.x,
|
|
1274
|
-
y: l.y,
|
|
1275
|
-
z: l.z
|
|
1276
|
-
})),
|
|
1277
|
-
worldLandmarks: result.worldLandmarks[index].map((l) => ({
|
|
1278
|
-
x: l.x,
|
|
1279
|
-
y: l.y,
|
|
1280
|
-
z: l.z
|
|
1281
|
-
}))
|
|
1282
|
-
}));
|
|
1283
|
-
return {
|
|
1284
|
-
hands
|
|
1285
|
-
};
|
|
1215
|
+
var OllamaModelRecordSchema = {
|
|
1216
|
+
type: "object",
|
|
1217
|
+
properties: {
|
|
1218
|
+
...ModelRecordSchema4.properties,
|
|
1219
|
+
...OllamaModelSchema.properties
|
|
1220
|
+
},
|
|
1221
|
+
required: [...ModelRecordSchema4.required, ...OllamaModelSchema.required],
|
|
1222
|
+
additionalProperties: false
|
|
1286
1223
|
};
|
|
1287
|
-
var
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
if (!result.landmarks) {
|
|
1296
|
-
throw new PermanentJobError("Failed to detect hand landmarks: Empty result");
|
|
1297
|
-
}
|
|
1298
|
-
const hands = result.landmarks.map((landmarks, index) => ({
|
|
1299
|
-
handedness: result.handedness[index].map((h) => ({
|
|
1300
|
-
label: h.categoryName,
|
|
1301
|
-
score: h.score
|
|
1302
|
-
})),
|
|
1303
|
-
landmarks: landmarks.map((l) => ({
|
|
1304
|
-
x: l.x,
|
|
1305
|
-
y: l.y,
|
|
1306
|
-
z: l.z
|
|
1307
|
-
})),
|
|
1308
|
-
worldLandmarks: result.worldLandmarks[index].map((l) => ({
|
|
1309
|
-
x: l.x,
|
|
1310
|
-
y: l.y,
|
|
1311
|
-
z: l.z
|
|
1312
|
-
}))
|
|
1313
|
-
}));
|
|
1314
|
-
return {
|
|
1315
|
-
hands
|
|
1316
|
-
};
|
|
1224
|
+
var OllamaModelConfigSchema = {
|
|
1225
|
+
type: "object",
|
|
1226
|
+
properties: {
|
|
1227
|
+
...ModelConfigSchema4.properties,
|
|
1228
|
+
...OllamaModelSchema.properties
|
|
1229
|
+
},
|
|
1230
|
+
required: [...ModelConfigSchema4.required, ...OllamaModelSchema.required],
|
|
1231
|
+
additionalProperties: false
|
|
1317
1232
|
};
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
}
|
|
1327
|
-
const faces = result.detections.map((detection) => ({
|
|
1328
|
-
box: {
|
|
1329
|
-
x: detection.boundingBox?.originX || 0,
|
|
1330
|
-
y: detection.boundingBox?.originY || 0,
|
|
1331
|
-
width: detection.boundingBox?.width || 0,
|
|
1332
|
-
height: detection.boundingBox?.height || 0
|
|
1233
|
+
// src/provider-openai/common/OpenAI_ModelSchema.ts
|
|
1234
|
+
import { ModelConfigSchema as ModelConfigSchema5, ModelRecordSchema as ModelRecordSchema5 } from "@workglow/ai";
|
|
1235
|
+
var OpenAiModelSchema = {
|
|
1236
|
+
type: "object",
|
|
1237
|
+
properties: {
|
|
1238
|
+
provider: {
|
|
1239
|
+
const: OPENAI,
|
|
1240
|
+
description: "Discriminator: OpenAI cloud provider."
|
|
1333
1241
|
},
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
const faces = result.faceLandmarks.map((landmarks, index) => {
|
|
1359
|
-
const face = {
|
|
1360
|
-
landmarks: landmarks.map((l) => ({
|
|
1361
|
-
x: l.x,
|
|
1362
|
-
y: l.y,
|
|
1363
|
-
z: l.z
|
|
1364
|
-
}))
|
|
1365
|
-
};
|
|
1366
|
-
if (result.faceBlendshapes && result.faceBlendshapes[index]) {
|
|
1367
|
-
face.blendshapes = result.faceBlendshapes[index].categories.map((b) => ({
|
|
1368
|
-
label: b.categoryName,
|
|
1369
|
-
score: b.score
|
|
1370
|
-
}));
|
|
1371
|
-
}
|
|
1372
|
-
if (result.facialTransformationMatrixes && result.facialTransformationMatrixes[index]) {
|
|
1373
|
-
face.transformationMatrix = Array.from(result.facialTransformationMatrixes[index].data);
|
|
1242
|
+
provider_config: {
|
|
1243
|
+
type: "object",
|
|
1244
|
+
description: "OpenAI-specific configuration.",
|
|
1245
|
+
properties: {
|
|
1246
|
+
model_name: {
|
|
1247
|
+
type: "string",
|
|
1248
|
+
description: "The OpenAI model identifier (e.g., 'gpt-4o', 'text-embedding-3-small')."
|
|
1249
|
+
},
|
|
1250
|
+
api_key: {
|
|
1251
|
+
type: "string",
|
|
1252
|
+
description: "OpenAI API key. Falls back to default API key if not set."
|
|
1253
|
+
},
|
|
1254
|
+
base_url: {
|
|
1255
|
+
type: "string",
|
|
1256
|
+
description: "Base URL for the OpenAI API. Useful for Azure OpenAI or proxy servers.",
|
|
1257
|
+
default: "https://api.openai.com/v1"
|
|
1258
|
+
},
|
|
1259
|
+
organization: {
|
|
1260
|
+
type: "string",
|
|
1261
|
+
description: "OpenAI organization ID (optional)."
|
|
1262
|
+
}
|
|
1263
|
+
},
|
|
1264
|
+
required: ["model_name"],
|
|
1265
|
+
additionalProperties: false
|
|
1374
1266
|
}
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
faces
|
|
1379
|
-
};
|
|
1267
|
+
},
|
|
1268
|
+
required: ["provider", "provider_config"],
|
|
1269
|
+
additionalProperties: true
|
|
1380
1270
|
};
|
|
1381
|
-
var
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
z: l.z,
|
|
1399
|
-
visibility: l.visibility,
|
|
1400
|
-
presence: l.presence
|
|
1401
|
-
})),
|
|
1402
|
-
worldLandmarks: result.worldLandmarks[index].map((l) => ({
|
|
1403
|
-
x: l.x,
|
|
1404
|
-
y: l.y,
|
|
1405
|
-
z: l.z,
|
|
1406
|
-
visibility: l.visibility,
|
|
1407
|
-
presence: l.presence
|
|
1408
|
-
}))
|
|
1409
|
-
};
|
|
1410
|
-
if (result.segmentationMasks && result.segmentationMasks[index]) {
|
|
1411
|
-
const mask = result.segmentationMasks[index];
|
|
1412
|
-
pose.segmentationMask = {
|
|
1413
|
-
data: mask.canvas || mask,
|
|
1414
|
-
width: mask.width,
|
|
1415
|
-
height: mask.height
|
|
1416
|
-
};
|
|
1417
|
-
}
|
|
1418
|
-
return pose;
|
|
1419
|
-
});
|
|
1420
|
-
return {
|
|
1421
|
-
poses
|
|
1422
|
-
};
|
|
1271
|
+
var OpenAiModelRecordSchema = {
|
|
1272
|
+
type: "object",
|
|
1273
|
+
properties: {
|
|
1274
|
+
...ModelRecordSchema5.properties,
|
|
1275
|
+
...OpenAiModelSchema.properties
|
|
1276
|
+
},
|
|
1277
|
+
required: [...ModelRecordSchema5.required, ...OpenAiModelSchema.required],
|
|
1278
|
+
additionalProperties: false
|
|
1279
|
+
};
|
|
1280
|
+
var OpenAiModelConfigSchema = {
|
|
1281
|
+
type: "object",
|
|
1282
|
+
properties: {
|
|
1283
|
+
...ModelConfigSchema5.properties,
|
|
1284
|
+
...OpenAiModelSchema.properties
|
|
1285
|
+
},
|
|
1286
|
+
required: [...ModelConfigSchema5.required, ...OpenAiModelSchema.required],
|
|
1287
|
+
additionalProperties: false
|
|
1423
1288
|
};
|
|
1424
1289
|
// src/tf-mediapipe/common/TFMP_ModelSchema.ts
|
|
1425
|
-
import { ModelConfigSchema as
|
|
1290
|
+
import { ModelConfigSchema as ModelConfigSchema6, ModelRecordSchema as ModelRecordSchema6 } from "@workglow/ai";
|
|
1426
1291
|
var TFMPModelSchema = {
|
|
1427
1292
|
type: "object",
|
|
1428
1293
|
properties: {
|
|
@@ -1459,181 +1324,180 @@ var TFMPModelSchema = {
|
|
|
1459
1324
|
var TFMPModelRecordSchema = {
|
|
1460
1325
|
type: "object",
|
|
1461
1326
|
properties: {
|
|
1462
|
-
...
|
|
1327
|
+
...ModelRecordSchema6.properties,
|
|
1463
1328
|
...TFMPModelSchema.properties
|
|
1464
1329
|
},
|
|
1465
|
-
required: [...
|
|
1330
|
+
required: [...ModelRecordSchema6.required, ...TFMPModelSchema.required],
|
|
1466
1331
|
additionalProperties: false
|
|
1467
1332
|
};
|
|
1468
1333
|
var TFMPModelConfigSchema = {
|
|
1469
1334
|
type: "object",
|
|
1470
1335
|
properties: {
|
|
1471
|
-
...
|
|
1336
|
+
...ModelConfigSchema6.properties,
|
|
1472
1337
|
...TFMPModelSchema.properties
|
|
1473
1338
|
},
|
|
1474
|
-
required: [...
|
|
1339
|
+
required: [...ModelConfigSchema6.required, ...TFMPModelSchema.required],
|
|
1475
1340
|
additionalProperties: false
|
|
1476
1341
|
};
|
|
1477
|
-
// src/
|
|
1478
|
-
import {
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1342
|
+
// src/anthropic/AnthropicProvider.ts
|
|
1343
|
+
import { AiProvider } from "@workglow/ai";
|
|
1344
|
+
class AnthropicProvider extends AiProvider {
|
|
1345
|
+
name = ANTHROPIC;
|
|
1346
|
+
taskTypes = ["TextGenerationTask", "TextRewriterTask", "TextSummaryTask"];
|
|
1347
|
+
constructor(tasks, streamTasks) {
|
|
1348
|
+
super(tasks, streamTasks);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
// src/google-gemini/GoogleGeminiProvider.ts
|
|
1352
|
+
import { AiProvider as AiProvider2 } from "@workglow/ai";
|
|
1353
|
+
class GoogleGeminiProvider extends AiProvider2 {
|
|
1354
|
+
name = GOOGLE_GEMINI;
|
|
1355
|
+
taskTypes = [
|
|
1356
|
+
"TextGenerationTask",
|
|
1357
|
+
"TextEmbeddingTask",
|
|
1358
|
+
"TextRewriterTask",
|
|
1359
|
+
"TextSummaryTask"
|
|
1360
|
+
];
|
|
1361
|
+
constructor(tasks, streamTasks) {
|
|
1362
|
+
super(tasks, streamTasks);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
// src/hf-transformers/HuggingFaceTransformersProvider.ts
|
|
1366
|
+
init_HFT_Constants();
|
|
1367
|
+
import {
|
|
1368
|
+
AiProvider as AiProvider3
|
|
1369
|
+
} from "@workglow/ai";
|
|
1370
|
+
|
|
1371
|
+
class HuggingFaceTransformersProvider extends AiProvider3 {
|
|
1372
|
+
name = HF_TRANSFORMERS_ONNX;
|
|
1373
|
+
taskTypes = [
|
|
1488
1374
|
"DownloadModelTask",
|
|
1489
1375
|
"UnloadModelTask",
|
|
1490
1376
|
"TextEmbeddingTask",
|
|
1377
|
+
"TextGenerationTask",
|
|
1378
|
+
"TextQuestionAnswerTask",
|
|
1491
1379
|
"TextLanguageDetectionTask",
|
|
1492
1380
|
"TextClassificationTask",
|
|
1381
|
+
"TextFillMaskTask",
|
|
1382
|
+
"TextNamedEntityRecognitionTask",
|
|
1383
|
+
"TextRewriterTask",
|
|
1384
|
+
"TextSummaryTask",
|
|
1385
|
+
"TextTranslationTask",
|
|
1493
1386
|
"ImageSegmentationTask",
|
|
1387
|
+
"ImageToTextTask",
|
|
1388
|
+
"BackgroundRemovalTask",
|
|
1494
1389
|
"ImageEmbeddingTask",
|
|
1495
1390
|
"ImageClassificationTask",
|
|
1496
1391
|
"ObjectDetectionTask"
|
|
1497
1392
|
];
|
|
1498
|
-
|
|
1499
|
-
|
|
1393
|
+
constructor(tasks, streamTasks) {
|
|
1394
|
+
super(tasks, streamTasks);
|
|
1500
1395
|
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
});
|
|
1513
|
-
client.attach(server);
|
|
1514
|
-
getTaskQueueRegistry3().registerQueue({ server, client, storage });
|
|
1515
|
-
await server.start();
|
|
1396
|
+
async onInitialize(options) {
|
|
1397
|
+
if (options.mode === "inline") {
|
|
1398
|
+
const { env } = await import("@sroussey/transformers");
|
|
1399
|
+
env.backends.onnx.wasm.proxy = true;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
async dispose() {
|
|
1403
|
+
if (this.tasks) {
|
|
1404
|
+
const { clearPipelineCache: clearPipelineCache2 } = await Promise.resolve().then(() => (init_HFT_JobRunFns(), exports_HFT_JobRunFns));
|
|
1405
|
+
clearPipelineCache2();
|
|
1406
|
+
}
|
|
1516
1407
|
}
|
|
1517
1408
|
}
|
|
1518
|
-
// src/
|
|
1519
|
-
import {
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1409
|
+
// src/provider-ollama/OllamaProvider.ts
|
|
1410
|
+
import { AiProvider as AiProvider4 } from "@workglow/ai";
|
|
1411
|
+
class OllamaProvider extends AiProvider4 {
|
|
1412
|
+
name = OLLAMA;
|
|
1413
|
+
taskTypes = [
|
|
1414
|
+
"TextGenerationTask",
|
|
1415
|
+
"TextEmbeddingTask",
|
|
1416
|
+
"TextRewriterTask",
|
|
1417
|
+
"TextSummaryTask"
|
|
1418
|
+
];
|
|
1419
|
+
constructor(tasks, streamTasks) {
|
|
1420
|
+
super(tasks, streamTasks);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
// src/provider-openai/OpenAiProvider.ts
|
|
1424
|
+
import { AiProvider as AiProvider5 } from "@workglow/ai";
|
|
1425
|
+
class OpenAiProvider extends AiProvider5 {
|
|
1426
|
+
name = OPENAI;
|
|
1427
|
+
taskTypes = [
|
|
1428
|
+
"TextGenerationTask",
|
|
1429
|
+
"TextEmbeddingTask",
|
|
1430
|
+
"TextRewriterTask",
|
|
1431
|
+
"TextSummaryTask"
|
|
1432
|
+
];
|
|
1433
|
+
constructor(tasks, streamTasks) {
|
|
1434
|
+
super(tasks, streamTasks);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
// src/tf-mediapipe/TensorFlowMediaPipeProvider.ts
|
|
1438
|
+
import { AiProvider as AiProvider6 } from "@workglow/ai";
|
|
1439
|
+
class TensorFlowMediaPipeProvider extends AiProvider6 {
|
|
1440
|
+
name = TENSORFLOW_MEDIAPIPE;
|
|
1441
|
+
taskTypes = [
|
|
1442
|
+
"DownloadModelTask",
|
|
1443
|
+
"UnloadModelTask",
|
|
1444
|
+
"TextEmbeddingTask",
|
|
1445
|
+
"TextLanguageDetectionTask",
|
|
1446
|
+
"TextClassificationTask",
|
|
1447
|
+
"ImageSegmentationTask",
|
|
1448
|
+
"ImageEmbeddingTask",
|
|
1449
|
+
"ImageClassificationTask",
|
|
1450
|
+
"ObjectDetectionTask",
|
|
1451
|
+
"GestureRecognizerTask",
|
|
1452
|
+
"HandLandmarkerTask",
|
|
1453
|
+
"FaceDetectorTask",
|
|
1454
|
+
"FaceLandmarkerTask",
|
|
1455
|
+
"PoseLandmarkerTask"
|
|
1456
|
+
];
|
|
1457
|
+
constructor(tasks) {
|
|
1458
|
+
super(tasks);
|
|
1554
1459
|
}
|
|
1555
1460
|
}
|
|
1556
|
-
// src/tf-mediapipe/registry/TFMP_Worker_RegisterJobFns.ts
|
|
1557
|
-
import {
|
|
1558
|
-
createServiceToken as createServiceToken2,
|
|
1559
|
-
globalServiceRegistry as globalServiceRegistry4,
|
|
1560
|
-
parentPort as parentPort2,
|
|
1561
|
-
WORKER_SERVER as WORKER_SERVER2
|
|
1562
|
-
} from "@workglow/util";
|
|
1563
|
-
var TFMP_WORKER_JOBRUN = createServiceToken2("worker.ai-provider.tfmp");
|
|
1564
|
-
var TFMP_WORKER_JOBRUN_REGISTER = globalServiceRegistry4.register(TFMP_WORKER_JOBRUN, () => {
|
|
1565
|
-
const workerServer = globalServiceRegistry4.get(WORKER_SERVER2);
|
|
1566
|
-
workerServer.registerFunction("DownloadModelTask", TFMP_Download);
|
|
1567
|
-
workerServer.registerFunction("UnloadModelTask", TFMP_Unload);
|
|
1568
|
-
workerServer.registerFunction("TextEmbeddingTask", TFMP_TextEmbedding);
|
|
1569
|
-
workerServer.registerFunction("TextLanguageDetectionTask", TFMP_TextLanguageDetection);
|
|
1570
|
-
workerServer.registerFunction("TextClassificationTask", TFMP_TextClassification);
|
|
1571
|
-
workerServer.registerFunction("ImageSegmentationTask", TFMP_ImageSegmentation);
|
|
1572
|
-
workerServer.registerFunction("ImageEmbeddingTask", TFMP_ImageEmbedding);
|
|
1573
|
-
workerServer.registerFunction("ImageClassificationTask", TFMP_ImageClassification);
|
|
1574
|
-
workerServer.registerFunction("ObjectDetectionTask", TFMP_ObjectDetection);
|
|
1575
|
-
parentPort2.postMessage({ type: "ready" });
|
|
1576
|
-
console.log("TFMP_WORKER_JOBRUN registered");
|
|
1577
|
-
return workerServer;
|
|
1578
|
-
}, true);
|
|
1579
1461
|
export {
|
|
1580
|
-
register_TFMP_InlineJobFns,
|
|
1581
|
-
register_TFMP_ClientJobFns,
|
|
1582
|
-
register_HFT_InlineJobFns,
|
|
1583
|
-
register_HFT_ClientJobFns,
|
|
1584
|
-
clearPipelineCache,
|
|
1585
1462
|
VisionPipelineUseCase,
|
|
1586
1463
|
TextPipelineUseCase,
|
|
1587
1464
|
TextPipelineTask,
|
|
1588
|
-
|
|
1589
|
-
TFMP_WORKER_JOBRUN,
|
|
1590
|
-
TFMP_Unload,
|
|
1591
|
-
TFMP_TextLanguageDetection,
|
|
1592
|
-
TFMP_TextEmbedding,
|
|
1593
|
-
TFMP_TextClassification,
|
|
1594
|
-
TFMP_PoseLandmarker,
|
|
1595
|
-
TFMP_ObjectDetection,
|
|
1596
|
-
TFMP_ImageSegmentation,
|
|
1597
|
-
TFMP_ImageEmbedding,
|
|
1598
|
-
TFMP_ImageClassification,
|
|
1599
|
-
TFMP_HandLandmarker,
|
|
1600
|
-
TFMP_GestureRecognizer,
|
|
1601
|
-
TFMP_FaceLandmarker,
|
|
1602
|
-
TFMP_FaceDetector,
|
|
1603
|
-
TFMP_Download,
|
|
1465
|
+
TensorFlowMediaPipeProvider,
|
|
1604
1466
|
TFMPModelSchema,
|
|
1605
1467
|
TFMPModelRecordSchema,
|
|
1606
1468
|
TFMPModelConfigSchema,
|
|
1607
1469
|
TENSORFLOW_MEDIAPIPE,
|
|
1608
1470
|
QuantizationDataType,
|
|
1609
1471
|
PipelineUseCase,
|
|
1472
|
+
OpenAiProvider,
|
|
1473
|
+
OpenAiModelSchema,
|
|
1474
|
+
OpenAiModelRecordSchema,
|
|
1475
|
+
OpenAiModelConfigSchema,
|
|
1476
|
+
OllamaProvider,
|
|
1477
|
+
OllamaModelSchema,
|
|
1478
|
+
OllamaModelRecordSchema,
|
|
1479
|
+
OllamaModelConfigSchema,
|
|
1480
|
+
OPENAI,
|
|
1481
|
+
OLLAMA_DEFAULT_BASE_URL,
|
|
1482
|
+
OLLAMA,
|
|
1610
1483
|
MultimodalPipelineUseCase,
|
|
1484
|
+
HuggingFaceTransformersProvider,
|
|
1611
1485
|
HfTransformersOnnxModelSchema,
|
|
1612
1486
|
HfTransformersOnnxModelRecordSchema,
|
|
1613
1487
|
HfTransformersOnnxModelConfigSchema,
|
|
1614
1488
|
HTF_CACHE_NAME,
|
|
1615
1489
|
HF_TRANSFORMERS_ONNX,
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
HFT_TextEmbedding,
|
|
1628
|
-
HFT_TextClassification,
|
|
1629
|
-
HFT_ObjectDetection,
|
|
1630
|
-
HFT_ImageToText,
|
|
1631
|
-
HFT_ImageSegmentation,
|
|
1632
|
-
HFT_ImageEmbedding,
|
|
1633
|
-
HFT_ImageClassification,
|
|
1634
|
-
HFT_Download,
|
|
1635
|
-
HFT_BackgroundRemoval,
|
|
1636
|
-
AudioPipelineUseCase
|
|
1490
|
+
GoogleGeminiProvider,
|
|
1491
|
+
GeminiModelSchema,
|
|
1492
|
+
GeminiModelRecordSchema,
|
|
1493
|
+
GeminiModelConfigSchema,
|
|
1494
|
+
GOOGLE_GEMINI,
|
|
1495
|
+
AudioPipelineUseCase,
|
|
1496
|
+
AnthropicProvider,
|
|
1497
|
+
AnthropicModelSchema,
|
|
1498
|
+
AnthropicModelRecordSchema,
|
|
1499
|
+
AnthropicModelConfigSchema,
|
|
1500
|
+
ANTHROPIC
|
|
1637
1501
|
};
|
|
1638
1502
|
|
|
1639
|
-
//# debugId=
|
|
1503
|
+
//# debugId=3A10C01C45D92C7564756E2164756E21
|