@workglow/ai-provider 0.0.97 → 0.0.99

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.
Files changed (74) hide show
  1. package/dist/HFT_JobRunFns-ajak33q5.js +60 -0
  2. package/dist/HFT_JobRunFns-ajak33q5.js.map +9 -0
  3. package/dist/anthropic/index.js +11 -92
  4. package/dist/anthropic/index.js.map +4 -7
  5. package/dist/google-gemini/index.js +11 -103
  6. package/dist/google-gemini/index.js.map +4 -7
  7. package/dist/hf-transformers/common/HFT_JobRunFns.d.ts.map +1 -1
  8. package/dist/hf-transformers/index.js +46 -1080
  9. package/dist/hf-transformers/index.js.map +4 -9
  10. package/dist/index-2pvfsjyx.js +857 -0
  11. package/dist/index-2pvfsjyx.js.map +10 -0
  12. package/dist/index-34rcjm0y.js +78 -0
  13. package/dist/index-34rcjm0y.js.map +12 -0
  14. package/dist/index-9w5hs4zc.js +73 -0
  15. package/dist/index-9w5hs4zc.js.map +12 -0
  16. package/dist/index-jd3bbc2x.js +11 -0
  17. package/dist/index-jd3bbc2x.js.map +9 -0
  18. package/dist/index-kctzvn3c.js +75 -0
  19. package/dist/index-kctzvn3c.js.map +12 -0
  20. package/dist/index-m0r2hvfz.js +57 -0
  21. package/dist/index-m0r2hvfz.js.map +10 -0
  22. package/dist/index-rmbnv0rw.js +169 -0
  23. package/dist/index-rmbnv0rw.js.map +11 -0
  24. package/dist/index-tn88s0ke.js +71 -0
  25. package/dist/index-tn88s0ke.js.map +12 -0
  26. package/dist/index-wnmajxg6.js +86 -0
  27. package/dist/index-wnmajxg6.js.map +12 -0
  28. package/dist/index-xyavfrb8.js +97 -0
  29. package/dist/index-xyavfrb8.js.map +12 -0
  30. package/dist/index.browser-jd3bbc2x.js +11 -0
  31. package/dist/index.browser-jd3bbc2x.js.map +9 -0
  32. package/dist/index.d.ts +6 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +80 -1369
  35. package/dist/index.js.map +3 -20
  36. package/dist/provider-hf-inference/HFI_Worker.d.ts +7 -0
  37. package/dist/provider-hf-inference/HFI_Worker.d.ts.map +1 -0
  38. package/dist/provider-hf-inference/HfInferenceProvider.d.ts +40 -0
  39. package/dist/provider-hf-inference/HfInferenceProvider.d.ts.map +1 -0
  40. package/dist/provider-hf-inference/common/HFI_Constants.d.ts +7 -0
  41. package/dist/provider-hf-inference/common/HFI_Constants.d.ts.map +1 -0
  42. package/dist/provider-hf-inference/common/HFI_JobRunFns.d.ts +17 -0
  43. package/dist/provider-hf-inference/common/HFI_JobRunFns.d.ts.map +1 -0
  44. package/dist/provider-hf-inference/common/HFI_ModelSchema.d.ts +146 -0
  45. package/dist/provider-hf-inference/common/HFI_ModelSchema.d.ts.map +1 -0
  46. package/dist/provider-hf-inference/index.d.ts +11 -0
  47. package/dist/provider-hf-inference/index.d.ts.map +1 -0
  48. package/dist/provider-hf-inference/index.js +209 -0
  49. package/dist/provider-hf-inference/index.js.map +11 -0
  50. package/dist/provider-llamacpp/LlamaCppProvider.d.ts +38 -0
  51. package/dist/provider-llamacpp/LlamaCppProvider.d.ts.map +1 -0
  52. package/dist/provider-llamacpp/LlamaCpp_Worker.d.ts +7 -0
  53. package/dist/provider-llamacpp/LlamaCpp_Worker.d.ts.map +1 -0
  54. package/dist/provider-llamacpp/common/LlamaCpp_Constants.d.ts +8 -0
  55. package/dist/provider-llamacpp/common/LlamaCpp_Constants.d.ts.map +1 -0
  56. package/dist/provider-llamacpp/common/LlamaCpp_JobRunFns.d.ts +20 -0
  57. package/dist/provider-llamacpp/common/LlamaCpp_JobRunFns.d.ts.map +1 -0
  58. package/dist/provider-llamacpp/common/LlamaCpp_ModelSchema.d.ts +209 -0
  59. package/dist/provider-llamacpp/common/LlamaCpp_ModelSchema.d.ts.map +1 -0
  60. package/dist/provider-llamacpp/index.d.ts +11 -0
  61. package/dist/provider-llamacpp/index.d.ts.map +1 -0
  62. package/dist/provider-llamacpp/index.js +365 -0
  63. package/dist/provider-llamacpp/index.js.map +11 -0
  64. package/dist/provider-ollama/index.browser.js +4 -8
  65. package/dist/provider-ollama/index.browser.js.map +2 -2
  66. package/dist/provider-ollama/index.js +12 -88
  67. package/dist/provider-ollama/index.js.map +4 -7
  68. package/dist/provider-openai/index.js +11 -95
  69. package/dist/provider-openai/index.js.map +4 -7
  70. package/dist/tf-mediapipe/index.js +4 -8
  71. package/dist/tf-mediapipe/index.js.map +2 -2
  72. package/package.json +39 -18
  73. package/dist/ggml/server.d.ts +0 -2
  74. package/dist/ggml/server.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,929 +1,64 @@
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
- });
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
-
75
- // src/hf-transformers/common/HFT_JobRunFns.ts
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
- }
115
- function clearPipelineCache() {
116
- pipelines.clear();
117
- }
118
- function getPipelineCacheKey(model) {
119
- const dtype = model.provider_config.dtype || "q8";
120
- const device = model.provider_config.device || "";
121
- return `${model.provider_config.model_path}:${model.provider_config.pipeline}:${dtype}:${device}`;
122
- }
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", port: "text", textDelta: text });
199
- },
200
- ...signal ? { abort_signal: signal } : {}
201
- });
202
- }
203
- var _transformersSdk, pipelines, getPipeline = async (model, onProgress, options = {}, progressScaleMax = 10) => {
204
- const cacheKey = getPipelineCacheKey(model);
205
- if (pipelines.has(cacheKey)) {
206
- return pipelines.get(cacheKey);
207
- }
208
- const fileSizes = new Map;
209
- const fileProgress = new Map;
210
- const fileCompleted = new Set;
211
- const fileFirstSent = new Set;
212
- const fileLastSent = new Set;
213
- const fileLastEventTime = new Map;
214
- const pendingProgressByFile = new Map;
215
- let throttleTimer = null;
216
- const THROTTLE_MS = 160;
217
- const estimatedTinyFiles = 3;
218
- const estimatedMediumFiles = 1;
219
- const estimatedTinySize = 1024;
220
- const estimatedMediumSize = 20971520;
221
- const estimatedLargeSize = 1073741824;
222
- const baseEstimate = estimatedTinyFiles * estimatedTinySize + estimatedMediumFiles * estimatedMediumSize;
223
- const sendProgress = (overallProgress, file, fileProgressValue, isFirst, isLast) => {
224
- const now = Date.now();
225
- const lastTime = fileLastEventTime.get(file) || 0;
226
- const timeSinceLastEvent = now - lastTime;
227
- const shouldThrottle = !isFirst && !isLast && timeSinceLastEvent < THROTTLE_MS;
228
- if (shouldThrottle) {
229
- pendingProgressByFile.set(file, {
230
- progress: overallProgress,
231
- file,
232
- fileProgress: fileProgressValue
233
- });
234
- if (!throttleTimer) {
235
- const timeRemaining = Math.max(1, THROTTLE_MS - timeSinceLastEvent);
236
- throttleTimer = setTimeout(() => {
237
- for (const [pendingFile, pending] of pendingProgressByFile.entries()) {
238
- onProgress(Math.round(pending.progress), "Downloading model", {
239
- file: pendingFile,
240
- progress: pending.fileProgress
241
- });
242
- fileLastEventTime.set(pendingFile, Date.now());
243
- }
244
- pendingProgressByFile.clear();
245
- throttleTimer = null;
246
- }, timeRemaining);
247
- }
248
- return;
249
- }
250
- onProgress(Math.round(overallProgress), "Downloading model", {
251
- file,
252
- progress: fileProgressValue
253
- });
254
- fileLastEventTime.set(file, now);
255
- pendingProgressByFile.delete(file);
256
- if (throttleTimer && pendingProgressByFile.size === 0) {
257
- clearTimeout(throttleTimer);
258
- throttleTimer = null;
259
- }
260
- };
261
- let hasSeenSubstantialFile = false;
262
- const substantialFileThreshold = 1048576;
263
- const abortSignal = options.abort_signal;
264
- const progressCallback = (status) => {
265
- if (abortSignal?.aborted) {
266
- return;
267
- }
268
- if (status.status === "progress") {
269
- const file = status.file;
270
- const fileTotal = status.total;
271
- const fileProgressValue = status.progress;
272
- if (!fileSizes.has(file)) {
273
- fileSizes.set(file, fileTotal);
274
- fileProgress.set(file, 0);
275
- if (fileTotal >= substantialFileThreshold) {
276
- hasSeenSubstantialFile = true;
277
- }
278
- }
279
- fileProgress.set(file, fileProgressValue);
280
- const isComplete = fileProgressValue >= 100;
281
- if (isComplete && !fileCompleted.has(file)) {
282
- fileCompleted.add(file);
283
- fileProgress.set(file, 100);
284
- }
285
- let actualLoadedSize = 0;
286
- let actualTotalSize = 0;
287
- const tinyThreshold = 102400;
288
- const mediumThreshold = 104857600;
289
- let seenTinyCount = 0;
290
- let seenMediumCount = 0;
291
- let seenLargeCount = 0;
292
- for (const [trackedFile, size] of fileSizes.entries()) {
293
- actualTotalSize += size;
294
- const progress = fileProgress.get(trackedFile) || 0;
295
- actualLoadedSize += size * progress / 100;
296
- if (size < tinyThreshold) {
297
- seenTinyCount++;
298
- } else if (size < mediumThreshold) {
299
- seenMediumCount++;
300
- } else {
301
- seenLargeCount++;
302
- }
303
- }
304
- const unseenTinyFiles = Math.max(0, estimatedTinyFiles - seenTinyCount);
305
- const unseenMediumFiles = Math.max(0, estimatedMediumFiles - seenMediumCount);
306
- let estimatedLargeFiles;
307
- if (seenLargeCount > 0) {
308
- estimatedLargeFiles = 2;
309
- } else {
310
- estimatedLargeFiles = 1;
311
- }
312
- const unseenLargeFiles = Math.max(0, estimatedLargeFiles - seenLargeCount);
313
- const adjustedTotalSize = actualTotalSize + unseenTinyFiles * estimatedTinySize + unseenMediumFiles * estimatedMediumSize + unseenLargeFiles * estimatedLargeSize;
314
- const rawProgress = adjustedTotalSize > 0 ? actualLoadedSize / adjustedTotalSize * 100 : 0;
315
- const overallProgress = rawProgress * progressScaleMax / 100;
316
- const isFirst = !fileFirstSent.has(file);
317
- const isLast = isComplete && !fileLastSent.has(file);
318
- if (isFirst) {
319
- fileFirstSent.add(file);
320
- }
321
- if (isLast) {
322
- fileLastSent.add(file);
323
- }
324
- if (hasSeenSubstantialFile) {
325
- sendProgress(overallProgress, file, fileProgressValue, isFirst, isLast);
326
- }
327
- } else if (status.status === "done" || status.status === "download") {
328
- const file = status.file;
329
- const fileSize = fileSizes.get(file) || 0;
330
- if (fileSize >= substantialFileThreshold) {
331
- hasSeenSubstantialFile = true;
332
- }
333
- if (!fileCompleted.has(file)) {
334
- fileCompleted.add(file);
335
- fileProgress.set(file, 100);
336
- let actualLoadedSize = 0;
337
- let actualTotalSize = 0;
338
- const tinyThreshold = 102400;
339
- const mediumThreshold = 104857600;
340
- let seenTinyCount = 0;
341
- let seenMediumCount = 0;
342
- let seenLargeCount = 0;
343
- for (const [trackedFile, size] of fileSizes.entries()) {
344
- actualTotalSize += size;
345
- const progress = fileProgress.get(trackedFile) || 0;
346
- actualLoadedSize += size * progress / 100;
347
- if (size < tinyThreshold) {
348
- seenTinyCount++;
349
- } else if (size < mediumThreshold) {
350
- seenMediumCount++;
351
- } else {
352
- seenLargeCount++;
353
- }
354
- }
355
- const unseenTinyFiles = Math.max(0, estimatedTinyFiles - seenTinyCount);
356
- const unseenMediumFiles = Math.max(0, estimatedMediumFiles - seenMediumCount);
357
- let estimatedLargeFiles;
358
- if (seenLargeCount > 0) {
359
- estimatedLargeFiles = 2;
360
- } else {
361
- estimatedLargeFiles = 1;
362
- }
363
- const unseenLargeFiles = Math.max(0, estimatedLargeFiles - seenLargeCount);
364
- const adjustedTotalSize = actualTotalSize + unseenTinyFiles * estimatedTinySize + unseenMediumFiles * estimatedMediumSize + unseenLargeFiles * estimatedLargeSize;
365
- const rawProgress = adjustedTotalSize > 0 ? actualLoadedSize / adjustedTotalSize * 100 : 0;
366
- const overallProgress = rawProgress * progressScaleMax / 100;
367
- const isLast = !fileLastSent.has(file);
368
- if (isLast) {
369
- fileLastSent.add(file);
370
- if (hasSeenSubstantialFile) {
371
- sendProgress(overallProgress, file, 100, false, true);
372
- }
373
- }
374
- }
375
- }
376
- };
377
- const pipelineOptions = {
378
- dtype: model.provider_config.dtype || "q8",
379
- ...model.provider_config.use_external_data_format ? { useExternalDataFormat: model.provider_config.use_external_data_format } : {},
380
- ...model.provider_config.device ? { device: model.provider_config.device } : {},
381
- ...options,
382
- progress_callback: progressCallback
383
- };
384
- if (abortSignal?.aborted) {
385
- throw new Error("Operation aborted before pipeline creation");
386
- }
387
- const pipelineType = model.provider_config.pipeline;
388
- const abortPromise = new Promise((_, reject) => {
389
- if (abortSignal) {
390
- const handleAbort = () => {
391
- reject(new Error("Pipeline download aborted"));
392
- };
393
- if (abortSignal.aborted) {
394
- handleAbort();
395
- } else {
396
- abortSignal.addEventListener("abort", handleAbort, { once: true });
397
- }
398
- }
399
- });
400
- const { pipeline } = await loadTransformersSDK();
401
- const pipelinePromise = pipeline(pipelineType, model.provider_config.model_path, pipelineOptions);
402
- try {
403
- const result = await (abortSignal ? Promise.race([pipelinePromise, abortPromise]) : pipelinePromise);
404
- if (abortSignal?.aborted) {
405
- throw new Error("Operation aborted after pipeline creation");
406
- }
407
- pipelines.set(cacheKey, result);
408
- return result;
409
- } catch (error) {
410
- if (abortSignal?.aborted) {
411
- throw new Error("Pipeline download aborted");
412
- }
413
- throw error;
414
- }
415
- }, HFT_Download = async (input, model, onProgress, signal) => {
416
- await getPipeline(model, onProgress, { abort_signal: signal }, 100);
417
- return {
418
- model: input.model
419
- };
420
- }, HFT_Unload = async (input, model, onProgress, signal) => {
421
- const cacheKey = getPipelineCacheKey(model);
422
- if (pipelines.has(cacheKey)) {
423
- pipelines.delete(cacheKey);
424
- onProgress(50, "Pipeline removed from memory");
425
- }
426
- const model_path = model.provider_config.model_path;
427
- await deleteModelCache(model_path);
428
- onProgress(100, "Model cache deleted");
429
- return {
430
- model: input.model
431
- };
432
- }, deleteModelCache = async (model_path) => {
433
- const cache = await caches.open(HTF_CACHE_NAME);
434
- const keys = await cache.keys();
435
- const prefix = `/${model_path}/`;
436
- const requestsToDelete = [];
437
- for (const request of keys) {
438
- const url = new URL(request.url);
439
- if (url.pathname.startsWith(prefix)) {
440
- requestsToDelete.push(request);
441
- }
442
- }
443
- let deletedCount = 0;
444
- for (const request of requestsToDelete) {
445
- try {
446
- const deleted = await cache.delete(request);
447
- if (deleted) {
448
- deletedCount++;
449
- } else {
450
- const deletedByUrl = await cache.delete(request.url);
451
- if (deletedByUrl) {
452
- deletedCount++;
453
- }
454
- }
455
- } catch (error) {
456
- console.error(`Failed to delete cache entry: ${request.url}`, error);
457
- }
458
- }
459
- }, HFT_TextEmbedding = async (input, model, onProgress, signal) => {
460
- const generateEmbedding = await getPipeline(model, onProgress, {
461
- abort_signal: signal
462
- });
463
- const hfVector = await generateEmbedding(input.text, {
464
- pooling: model?.provider_config.pooling || "mean",
465
- normalize: model?.provider_config.normalize,
466
- ...signal ? { abort_signal: signal } : {}
467
- });
468
- const isArrayInput = Array.isArray(input.text);
469
- const embeddingDim = model?.provider_config.native_dimensions;
470
- if (isArrayInput && hfVector.dims.length > 1) {
471
- const [numTexts, vectorDim] = hfVector.dims;
472
- if (numTexts !== input.text.length) {
473
- throw new Error(`HuggingFace Embedding tensor batch size does not match input array length: ${numTexts} != ${input.text.length}`);
474
- }
475
- if (vectorDim !== embeddingDim) {
476
- throw new Error(`HuggingFace Embedding vector dimension does not match model dimensions: ${vectorDim} != ${embeddingDim}`);
477
- }
478
- const vectors = Array.from({ length: numTexts }, (_, i) => hfVector[i].data);
479
- return { vector: vectors };
480
- }
481
- if (hfVector.size !== embeddingDim) {
482
- console.warn(`HuggingFace Embedding vector length does not match model dimensions v${hfVector.size} != m${embeddingDim}`, input, hfVector);
483
- throw new Error(`HuggingFace Embedding vector length does not match model dimensions v${hfVector.size} != m${embeddingDim}`);
484
- }
485
- return { vector: hfVector.data };
486
- }, HFT_TextClassification = async (input, model, onProgress, signal) => {
487
- if (model?.provider_config?.pipeline === "zero-shot-classification") {
488
- if (!input.candidateLabels || !Array.isArray(input.candidateLabels) || input.candidateLabels.length === 0) {
489
- throw new Error("Zero-shot text classification requires candidate labels");
490
- }
491
- const zeroShotClassifier = await getPipeline(model, onProgress, {
492
- abort_signal: signal
493
- });
494
- const result2 = await zeroShotClassifier(input.text, input.candidateLabels, {});
495
- return {
496
- categories: result2.labels.map((label, idx) => ({
497
- label,
498
- score: result2.scores[idx]
499
- }))
500
- };
501
- }
502
- const TextClassification = await getPipeline(model, onProgress, {
503
- abort_signal: signal
504
- });
505
- const result = await TextClassification(input.text, {
506
- top_k: input.maxCategories || undefined,
507
- ...signal ? { abort_signal: signal } : {}
508
- });
509
- if (Array.isArray(result[0])) {
510
- return {
511
- categories: result[0].map((category) => ({
512
- label: category.label,
513
- score: category.score
514
- }))
515
- };
516
- }
517
- return {
518
- categories: result.map((category) => ({
519
- label: category.label,
520
- score: category.score
521
- }))
522
- };
523
- }, HFT_TextLanguageDetection = async (input, model, onProgress, signal) => {
524
- const TextClassification = await getPipeline(model, onProgress, {
525
- abort_signal: signal
526
- });
527
- const result = await TextClassification(input.text, {
528
- top_k: input.maxLanguages || undefined,
529
- ...signal ? { abort_signal: signal } : {}
530
- });
531
- if (Array.isArray(result[0])) {
532
- return {
533
- languages: result[0].map((category) => ({
534
- language: category.label,
535
- score: category.score
536
- }))
537
- };
538
- }
539
- return {
540
- languages: result.map((category) => ({
541
- language: category.label,
542
- score: category.score
543
- }))
544
- };
545
- }, HFT_TextNamedEntityRecognition = async (input, model, onProgress, signal) => {
546
- const textNamedEntityRecognition = await getPipeline(model, onProgress, {
547
- abort_signal: signal
548
- });
549
- let results = await textNamedEntityRecognition(input.text, {
550
- ignore_labels: input.blockList,
551
- ...signal ? { abort_signal: signal } : {}
552
- });
553
- let entities = [];
554
- if (!Array.isArray(results)) {
555
- entities = [results];
556
- } else {
557
- entities = results;
558
- }
559
- return {
560
- entities: entities.map((entity) => ({
561
- entity: entity.entity,
562
- score: entity.score,
563
- word: entity.word
564
- }))
565
- };
566
- }, HFT_TextFillMask = async (input, model, onProgress, signal) => {
567
- const unmasker = await getPipeline(model, onProgress, {
568
- abort_signal: signal
569
- });
570
- let results = await unmasker(input.text);
571
- let predictions = [];
572
- if (!Array.isArray(results)) {
573
- predictions = [results];
574
- } else {
575
- predictions = results;
576
- }
577
- return {
578
- predictions: predictions.map((prediction) => ({
579
- entity: prediction.token_str,
580
- score: prediction.score,
581
- sequence: prediction.sequence
582
- }))
583
- };
584
- }, HFT_TextGeneration = async (input, model, onProgress, signal) => {
585
- const generateText = await getPipeline(model, onProgress, {
586
- abort_signal: signal
587
- });
588
- const streamer = createTextStreamer(generateText.tokenizer, onProgress, signal);
589
- let results = await generateText(input.prompt, {
590
- streamer,
591
- ...signal ? { abort_signal: signal } : {}
592
- });
593
- if (!Array.isArray(results)) {
594
- results = [results];
595
- }
596
- let text = results[0]?.generated_text;
597
- if (Array.isArray(text)) {
598
- text = text[text.length - 1]?.content;
599
- }
600
- return {
601
- text
602
- };
603
- }, HFT_TextTranslation = async (input, model, onProgress, signal) => {
604
- const translate = await getPipeline(model, onProgress, {
605
- abort_signal: signal
606
- });
607
- const streamer = createTextStreamer(translate.tokenizer, onProgress);
608
- const result = await translate(input.text, {
609
- src_lang: input.source_lang,
610
- tgt_lang: input.target_lang,
611
- streamer,
612
- ...signal ? { abort_signal: signal } : {}
613
- });
614
- const translatedText = Array.isArray(result) ? result[0]?.translation_text || "" : result?.translation_text || "";
615
- return {
616
- text: translatedText,
617
- target_lang: input.target_lang
618
- };
619
- }, HFT_TextRewriter = async (input, model, onProgress, signal) => {
620
- const generateText = await getPipeline(model, onProgress, {
621
- abort_signal: signal
622
- });
623
- const streamer = createTextStreamer(generateText.tokenizer, onProgress);
624
- const promptedText = (input.prompt ? input.prompt + `
625
- ` : "") + input.text;
626
- let results = await generateText(promptedText, {
627
- streamer,
628
- ...signal ? { abort_signal: signal } : {}
629
- });
630
- if (!Array.isArray(results)) {
631
- results = [results];
632
- }
633
- let text = results[0]?.generated_text;
634
- if (Array.isArray(text)) {
635
- text = text[text.length - 1]?.content;
636
- }
637
- if (text === promptedText) {
638
- throw new Error("Rewriter failed to generate new text");
639
- }
640
- return {
641
- text
642
- };
643
- }, HFT_TextSummary = async (input, model, onProgress, signal) => {
644
- const generateSummary = await getPipeline(model, onProgress, {
645
- abort_signal: signal
646
- });
647
- const streamer = createTextStreamer(generateSummary.tokenizer, onProgress);
648
- let result = await generateSummary(input.text, {
649
- streamer,
650
- ...signal ? { abort_signal: signal } : {}
651
- });
652
- let summaryText = "";
653
- if (Array.isArray(result)) {
654
- summaryText = result[0]?.summary_text || "";
655
- } else {
656
- summaryText = result?.summary_text || "";
657
- }
658
- return {
659
- text: summaryText
660
- };
661
- }, HFT_TextQuestionAnswer = async (input, model, onProgress, signal) => {
662
- const generateAnswer = await getPipeline(model, onProgress, {
663
- abort_signal: signal
664
- });
665
- const streamer = createTextStreamer(generateAnswer.tokenizer, onProgress);
666
- const result = await generateAnswer(input.question, input.context, {
667
- streamer,
668
- ...signal ? { abort_signal: signal } : {}
669
- });
670
- let answerText = "";
671
- if (Array.isArray(result)) {
672
- answerText = result[0]?.answer || "";
673
- } else {
674
- answerText = result?.answer || "";
675
- }
676
- return {
677
- text: answerText
678
- };
679
- }, HFT_ImageSegmentation = async (input, model, onProgress, signal) => {
680
- const segmenter = await getPipeline(model, onProgress, {
681
- abort_signal: signal
682
- });
683
- const result = await segmenter(input.image, {
684
- threshold: input.threshold,
685
- mask_threshold: input.maskThreshold,
686
- ...signal ? { abort_signal: signal } : {}
687
- });
688
- const masks = Array.isArray(result) ? result : [result];
689
- const processedMasks = await Promise.all(masks.map(async (mask) => ({
690
- label: mask.label || "",
691
- score: mask.score || 0,
692
- mask: {}
693
- })));
694
- return {
695
- masks: processedMasks
696
- };
697
- }, HFT_ImageToText = async (input, model, onProgress, signal) => {
698
- const captioner = await getPipeline(model, onProgress, {
699
- abort_signal: signal
700
- });
701
- const result = await captioner(input.image, {
702
- max_new_tokens: input.maxTokens,
703
- ...signal ? { abort_signal: signal } : {}
704
- });
705
- const text = Array.isArray(result) ? result[0]?.generated_text : result?.generated_text;
706
- return {
707
- text: text || ""
708
- };
709
- }, HFT_BackgroundRemoval = async (input, model, onProgress, signal) => {
710
- const remover = await getPipeline(model, onProgress, {
711
- abort_signal: signal
712
- });
713
- const result = await remover(input.image, {
714
- ...signal ? { abort_signal: signal } : {}
715
- });
716
- const resultImage = Array.isArray(result) ? result[0] : result;
717
- return {
718
- image: imageToBase64(resultImage)
719
- };
720
- }, HFT_ImageEmbedding = async (input, model, onProgress, signal) => {
721
- const embedder = await getPipeline(model, onProgress, {
722
- abort_signal: signal
723
- });
724
- const result = await embedder(input.image);
725
- return {
726
- vector: result.data
727
- };
728
- }, HFT_ImageClassification = async (input, model, onProgress, signal) => {
729
- if (model?.provider_config?.pipeline === "zero-shot-image-classification") {
730
- if (!input.categories || !Array.isArray(input.categories) || input.categories.length === 0) {
731
- console.warn("Zero-shot image classification requires categories", input);
732
- throw new Error("Zero-shot image classification requires categories");
733
- }
734
- const zeroShotClassifier = await getPipeline(model, onProgress, {
735
- abort_signal: signal
736
- });
737
- const result2 = await zeroShotClassifier(input.image, input.categories, {});
738
- const results2 = Array.isArray(result2) ? result2 : [result2];
739
- return {
740
- categories: results2.map((r) => ({
741
- label: r.label,
742
- score: r.score
743
- }))
744
- };
745
- }
746
- const classifier = await getPipeline(model, onProgress, {
747
- abort_signal: signal
748
- });
749
- const result = await classifier(input.image, {
750
- top_k: input.maxCategories,
751
- ...signal ? { abort_signal: signal } : {}
752
- });
753
- const results = Array.isArray(result) ? result : [result];
754
- return {
755
- categories: results.map((r) => ({
756
- label: r.label,
757
- score: r.score
758
- }))
759
- };
760
- }, HFT_ObjectDetection = async (input, model, onProgress, signal) => {
761
- if (model?.provider_config?.pipeline === "zero-shot-object-detection") {
762
- if (!input.labels || !Array.isArray(input.labels) || input.labels.length === 0) {
763
- throw new Error("Zero-shot object detection requires labels");
764
- }
765
- const zeroShotDetector = await getPipeline(model, onProgress, {
766
- abort_signal: signal
767
- });
768
- const result2 = await zeroShotDetector(input.image, Array.from(input.labels), {
769
- threshold: input.threshold
770
- });
771
- const detections2 = Array.isArray(result2) ? result2 : [result2];
772
- return {
773
- detections: detections2.map((d) => ({
774
- label: d.label,
775
- score: d.score,
776
- box: d.box
777
- }))
778
- };
779
- }
780
- const detector = await getPipeline(model, onProgress, {
781
- abort_signal: signal
782
- });
783
- const result = await detector(input.image, {
784
- threshold: input.threshold,
785
- ...signal ? { abort_signal: signal } : {}
786
- });
787
- const detections = Array.isArray(result) ? result : [result];
788
- return {
789
- detections: detections.map((d) => ({
790
- label: d.label,
791
- score: d.score,
792
- box: d.box
793
- }))
794
- };
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,
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
813
- });
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";
1
+ import {
2
+ ANTHROPIC,
3
+ AnthropicModelConfigSchema,
4
+ AnthropicModelRecordSchema,
5
+ AnthropicModelSchema,
6
+ AnthropicProvider
7
+ } from "./index-kctzvn3c.js";
8
+ import {
9
+ GOOGLE_GEMINI,
10
+ GeminiModelConfigSchema,
11
+ GeminiModelRecordSchema,
12
+ GeminiModelSchema,
13
+ GoogleGeminiProvider
14
+ } from "./index-wnmajxg6.js";
15
+ import {
16
+ HfTransformersOnnxModelConfigSchema,
17
+ HfTransformersOnnxModelRecordSchema,
18
+ HfTransformersOnnxModelSchema,
19
+ HuggingFaceTransformersProvider
20
+ } from "./index-rmbnv0rw.js";
21
+ import {
22
+ AudioPipelineUseCase,
23
+ HF_TRANSFORMERS_ONNX,
24
+ HTF_CACHE_NAME,
25
+ MultimodalPipelineUseCase,
26
+ PipelineUseCase,
27
+ QuantizationDataType,
28
+ TextPipelineUseCase,
29
+ VisionPipelineUseCase
30
+ } from "./index-m0r2hvfz.js";
31
+ import {
32
+ LLAMACPP_DEFAULT_MODELS_DIR,
33
+ LOCAL_LLAMACPP,
34
+ LlamaCppModelConfigSchema,
35
+ LlamaCppModelRecordSchema,
36
+ LlamaCppModelSchema,
37
+ LlamaCppProvider
38
+ } from "./index-xyavfrb8.js";
39
+ import {
40
+ HF_INFERENCE,
41
+ HfInferenceModelConfigSchema,
42
+ HfInferenceModelRecordSchema,
43
+ HfInferenceModelSchema,
44
+ HfInferenceProvider
45
+ } from "./index-9w5hs4zc.js";
46
+ import {
47
+ OLLAMA,
48
+ OLLAMA_DEFAULT_BASE_URL,
49
+ OllamaModelConfigSchema,
50
+ OllamaModelRecordSchema,
51
+ OllamaModelSchema,
52
+ OllamaProvider
53
+ } from "./index-tn88s0ke.js";
54
+ import {
55
+ OPENAI,
56
+ OpenAiModelConfigSchema,
57
+ OpenAiModelRecordSchema,
58
+ OpenAiModelSchema,
59
+ OpenAiProvider
60
+ } from "./index-34rcjm0y.js";
61
+ import"./index-jd3bbc2x.js";
927
62
  // src/tf-mediapipe/common/TFMP_Constants.ts
928
63
  var TENSORFLOW_MEDIAPIPE = "TENSORFLOW_MEDIAPIPE";
929
64
  var TextPipelineTask = {
@@ -946,348 +81,8 @@ var TextPipelineTask = {
946
81
  "vision-object-detector": "vision-object-detector",
947
82
  "vision-pose-landmarker": "vision-pose-landmarker"
948
83
  };
949
- // src/anthropic/common/Anthropic_ModelSchema.ts
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";
1074
- var HfTransformersOnnxModelSchema = {
1075
- type: "object",
1076
- properties: {
1077
- provider: {
1078
- const: HF_TRANSFORMERS_ONNX,
1079
- description: "Discriminator: ONNX runtime backend."
1080
- },
1081
- provider_config: {
1082
- type: "object",
1083
- description: "ONNX runtime-specific options.",
1084
- properties: {
1085
- pipeline: {
1086
- type: "string",
1087
- enum: Object.values(PipelineUseCase),
1088
- description: "Pipeline type for the ONNX model.",
1089
- default: "text-generation"
1090
- },
1091
- model_path: {
1092
- type: "string",
1093
- description: "Filesystem path or URI for the ONNX model."
1094
- },
1095
- dtype: {
1096
- type: "string",
1097
- enum: Object.values(QuantizationDataType),
1098
- description: "Data type for the ONNX model.",
1099
- default: "auto"
1100
- },
1101
- device: {
1102
- type: "string",
1103
- enum: ["cpu", "gpu", "webgpu", "wasm", "metal"],
1104
- description: "High-level device selection.",
1105
- default: "webgpu"
1106
- },
1107
- execution_providers: {
1108
- type: "array",
1109
- items: { type: "string" },
1110
- description: "Raw ONNX Runtime execution provider identifiers.",
1111
- "x-ui-hidden": true
1112
- },
1113
- intra_op_num_threads: {
1114
- type: "integer",
1115
- minimum: 1
1116
- },
1117
- inter_op_num_threads: {
1118
- type: "integer",
1119
- minimum: 1
1120
- },
1121
- use_external_data_format: {
1122
- type: "boolean",
1123
- description: "Whether the model uses external data format."
1124
- },
1125
- native_dimensions: {
1126
- type: "integer",
1127
- description: "The native dimensions of the model."
1128
- },
1129
- pooling: {
1130
- type: "string",
1131
- enum: ["mean", "last_token", "cls"],
1132
- description: "The pooling strategy to use for the model.",
1133
- default: "mean"
1134
- },
1135
- normalize: {
1136
- type: "boolean",
1137
- description: "Whether the model uses normalization.",
1138
- default: true
1139
- },
1140
- language_style: {
1141
- type: "string",
1142
- description: "The language style of the model."
1143
- },
1144
- mrl: {
1145
- type: "boolean",
1146
- description: "Whether the model uses matryoshka.",
1147
- default: false
1148
- }
1149
- },
1150
- required: ["model_path", "pipeline"],
1151
- additionalProperties: false,
1152
- if: {
1153
- properties: {
1154
- pipeline: {
1155
- const: "feature-extraction"
1156
- }
1157
- }
1158
- },
1159
- then: {
1160
- required: ["native_dimensions"]
1161
- }
1162
- }
1163
- },
1164
- required: ["provider", "provider_config"],
1165
- additionalProperties: true
1166
- };
1167
- var HfTransformersOnnxModelRecordSchema = {
1168
- type: "object",
1169
- properties: {
1170
- ...ModelRecordSchema3.properties,
1171
- ...HfTransformersOnnxModelSchema.properties
1172
- },
1173
- required: [...ModelRecordSchema3.required, ...HfTransformersOnnxModelSchema.required],
1174
- additionalProperties: false
1175
- };
1176
- var HfTransformersOnnxModelConfigSchema = {
1177
- type: "object",
1178
- properties: {
1179
- ...ModelConfigSchema3.properties,
1180
- ...HfTransformersOnnxModelSchema.properties
1181
- },
1182
- required: [...ModelConfigSchema3.required, ...HfTransformersOnnxModelSchema.required],
1183
- additionalProperties: false
1184
- };
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."
1193
- },
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
1210
- }
1211
- },
1212
- required: ["provider", "provider_config"],
1213
- additionalProperties: true
1214
- };
1215
- var OllamaModelRecordSchema = {
1216
- type: "object",
1217
- properties: {
1218
- ...ModelRecordSchema4.properties,
1219
- ...OllamaModelSchema.properties
1220
- },
1221
- required: [...ModelRecordSchema4.required, ...OllamaModelSchema.required],
1222
- additionalProperties: false
1223
- };
1224
- var OllamaModelConfigSchema = {
1225
- type: "object",
1226
- properties: {
1227
- ...ModelConfigSchema4.properties,
1228
- ...OllamaModelSchema.properties
1229
- },
1230
- required: [...ModelConfigSchema4.required, ...OllamaModelSchema.required],
1231
- additionalProperties: false
1232
- };
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."
1241
- },
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
1266
- }
1267
- },
1268
- required: ["provider", "provider_config"],
1269
- additionalProperties: true
1270
- };
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
1288
- };
1289
84
  // src/tf-mediapipe/common/TFMP_ModelSchema.ts
1290
- import { ModelConfigSchema as ModelConfigSchema6, ModelRecordSchema as ModelRecordSchema6 } from "@workglow/ai";
85
+ import { ModelConfigSchema, ModelRecordSchema } from "@workglow/ai";
1291
86
  var TFMPModelSchema = {
1292
87
  type: "object",
1293
88
  properties: {
@@ -1324,119 +119,24 @@ var TFMPModelSchema = {
1324
119
  var TFMPModelRecordSchema = {
1325
120
  type: "object",
1326
121
  properties: {
1327
- ...ModelRecordSchema6.properties,
122
+ ...ModelRecordSchema.properties,
1328
123
  ...TFMPModelSchema.properties
1329
124
  },
1330
- required: [...ModelRecordSchema6.required, ...TFMPModelSchema.required],
125
+ required: [...ModelRecordSchema.required, ...TFMPModelSchema.required],
1331
126
  additionalProperties: false
1332
127
  };
1333
128
  var TFMPModelConfigSchema = {
1334
129
  type: "object",
1335
130
  properties: {
1336
- ...ModelConfigSchema6.properties,
131
+ ...ModelConfigSchema.properties,
1337
132
  ...TFMPModelSchema.properties
1338
133
  },
1339
- required: [...ModelConfigSchema6.required, ...TFMPModelSchema.required],
134
+ required: [...ModelConfigSchema.required, ...TFMPModelSchema.required],
1340
135
  additionalProperties: false
1341
136
  };
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 = [
1374
- "DownloadModelTask",
1375
- "UnloadModelTask",
1376
- "TextEmbeddingTask",
1377
- "TextGenerationTask",
1378
- "TextQuestionAnswerTask",
1379
- "TextLanguageDetectionTask",
1380
- "TextClassificationTask",
1381
- "TextFillMaskTask",
1382
- "TextNamedEntityRecognitionTask",
1383
- "TextRewriterTask",
1384
- "TextSummaryTask",
1385
- "TextTranslationTask",
1386
- "ImageSegmentationTask",
1387
- "ImageToTextTask",
1388
- "BackgroundRemovalTask",
1389
- "ImageEmbeddingTask",
1390
- "ImageClassificationTask",
1391
- "ObjectDetectionTask"
1392
- ];
1393
- constructor(tasks, streamTasks) {
1394
- super(tasks, streamTasks);
1395
- }
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
- }
1407
- }
1408
- }
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
137
  // src/tf-mediapipe/TensorFlowMediaPipeProvider.ts
1438
- import { AiProvider as AiProvider6 } from "@workglow/ai";
1439
- class TensorFlowMediaPipeProvider extends AiProvider6 {
138
+ import { AiProvider } from "@workglow/ai";
139
+ class TensorFlowMediaPipeProvider extends AiProvider {
1440
140
  name = TENSORFLOW_MEDIAPIPE;
1441
141
  taskTypes = [
1442
142
  "DownloadModelTask",
@@ -1481,12 +181,23 @@ export {
1481
181
  OLLAMA_DEFAULT_BASE_URL,
1482
182
  OLLAMA,
1483
183
  MultimodalPipelineUseCase,
184
+ LlamaCppProvider,
185
+ LlamaCppModelSchema,
186
+ LlamaCppModelRecordSchema,
187
+ LlamaCppModelConfigSchema,
188
+ LOCAL_LLAMACPP,
189
+ LLAMACPP_DEFAULT_MODELS_DIR,
1484
190
  HuggingFaceTransformersProvider,
1485
191
  HfTransformersOnnxModelSchema,
1486
192
  HfTransformersOnnxModelRecordSchema,
1487
193
  HfTransformersOnnxModelConfigSchema,
194
+ HfInferenceProvider,
195
+ HfInferenceModelSchema,
196
+ HfInferenceModelRecordSchema,
197
+ HfInferenceModelConfigSchema,
1488
198
  HTF_CACHE_NAME,
1489
199
  HF_TRANSFORMERS_ONNX,
200
+ HF_INFERENCE,
1490
201
  GoogleGeminiProvider,
1491
202
  GeminiModelSchema,
1492
203
  GeminiModelRecordSchema,
@@ -1500,4 +211,4 @@ export {
1500
211
  ANTHROPIC
1501
212
  };
1502
213
 
1503
- //# debugId=341CF407830F74C864756E2164756E21
214
+ //# debugId=5DD642E9FD2CB22A64756E2164756E21