@workglow/ai-provider 0.0.52

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 (41) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +488 -0
  3. package/dist/ggml/model/GgmlLocalModel.d.ts +7 -0
  4. package/dist/ggml/model/GgmlLocalModel.d.ts.map +1 -0
  5. package/dist/ggml/server.d.ts +2 -0
  6. package/dist/ggml/server.d.ts.map +1 -0
  7. package/dist/hf-transformers/common/HFT_CallbackStatus.d.ts +36 -0
  8. package/dist/hf-transformers/common/HFT_CallbackStatus.d.ts.map +1 -0
  9. package/dist/hf-transformers/common/HFT_Constants.d.ts +18 -0
  10. package/dist/hf-transformers/common/HFT_Constants.d.ts.map +1 -0
  11. package/dist/hf-transformers/common/HFT_JobRunFns.d.ts +45 -0
  12. package/dist/hf-transformers/common/HFT_JobRunFns.d.ts.map +1 -0
  13. package/dist/hf-transformers/index.d.ts +11 -0
  14. package/dist/hf-transformers/index.d.ts.map +1 -0
  15. package/dist/hf-transformers/registry/HFT_Client_RegisterJobFns.d.ts +7 -0
  16. package/dist/hf-transformers/registry/HFT_Client_RegisterJobFns.d.ts.map +1 -0
  17. package/dist/hf-transformers/registry/HFT_Inline_RegisterJobFns.d.ts +7 -0
  18. package/dist/hf-transformers/registry/HFT_Inline_RegisterJobFns.d.ts.map +1 -0
  19. package/dist/hf-transformers/registry/HFT_Worker_RegisterJobFns.d.ts +8 -0
  20. package/dist/hf-transformers/registry/HFT_Worker_RegisterJobFns.d.ts.map +1 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +342 -0
  24. package/dist/index.js.map +19 -0
  25. package/dist/openai/provider/OpenAI_TaskRun.d.ts +2 -0
  26. package/dist/openai/provider/OpenAI_TaskRun.d.ts.map +1 -0
  27. package/dist/tf-mediapipe/common/TFMP_Constants.d.ts +7 -0
  28. package/dist/tf-mediapipe/common/TFMP_Constants.d.ts.map +1 -0
  29. package/dist/tf-mediapipe/common/TFMP_JobRunFns.d.ts +17 -0
  30. package/dist/tf-mediapipe/common/TFMP_JobRunFns.d.ts.map +1 -0
  31. package/dist/tf-mediapipe/index.d.ts +11 -0
  32. package/dist/tf-mediapipe/index.d.ts.map +1 -0
  33. package/dist/tf-mediapipe/registry/TFMP_Client_RegisterJobFns.d.ts +7 -0
  34. package/dist/tf-mediapipe/registry/TFMP_Client_RegisterJobFns.d.ts.map +1 -0
  35. package/dist/tf-mediapipe/registry/TFMP_Inline_RegisterJobFns.d.ts +7 -0
  36. package/dist/tf-mediapipe/registry/TFMP_Inline_RegisterJobFns.d.ts.map +1 -0
  37. package/dist/tf-mediapipe/registry/TFMP_Worker_RegisterJobFns.d.ts +8 -0
  38. package/dist/tf-mediapipe/registry/TFMP_Worker_RegisterJobFns.d.ts.map +1 -0
  39. package/dist/types.d.ts +7 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/package.json +67 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Steven Roussey
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,488 @@
1
+ # @workglow/ai-provider
2
+
3
+ AI provider implementations for Workglow AI task pipelines.
4
+
5
+ ## Overview
6
+
7
+ The `@workglow/ai-provider` package provides concrete implementations of AI providers that can be used with Workglow's task execution system. It includes support for various AI services and local model execution frameworks.
8
+
9
+ ## Features
10
+
11
+ - **HuggingFace Transformers**: Support for ONNX models via HuggingFace Transformers.js
12
+ - **TensorFlow MediaPipe**: Integration with Google's MediaPipe for text processing tasks
13
+ - [FUTURE] **OpenAI Integration**: Support for OpenAI API services
14
+ - [FUTURE] **GGML Support**: Local model execution with GGML format models
15
+ - **Multi-Platform**: Works in browser, Node.js, and Bun environments
16
+ - **Worker Support**: Offload AI computation to web workers for better performance
17
+ - **Type Safety**: Full TypeScript support with comprehensive type definitions
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @workglow/ai-provider
23
+ # or
24
+ bun add @workglow/ai-provider
25
+ ```
26
+
27
+ ## Peer Dependencies
28
+
29
+ Depending on which providers you use, you may need to install additional peer dependencies:
30
+
31
+ ```bash
32
+ # For HuggingFace Transformers support
33
+ npm install @sroussey/transformers
34
+
35
+ # For MediaPipe support
36
+ npm install @mediapipe/tasks-text
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ### 1. Basic Setup
42
+
43
+ ```typescript
44
+ import {
45
+ HF_TRANSFORMERS_ONNX,
46
+ TENSORFLOW_MEDIAPIPE,
47
+ register_HFT_InlineJobFns,
48
+ register_TFMP_InlineJobFns,
49
+ } from "@workglow/ai-provider";
50
+ import { getTaskQueueRegistry } from "@workglow/task-graph";
51
+ import { AiJob } from "@workglow/ai";
52
+ import { JobQueue, ConcurrencyLimiter } from "@workglow/job-queue";
53
+ import { InMemoryQueueStorage } from "@workglow/storage";
54
+
55
+ // Register AI providers
56
+ await register_HFT_InlineJobFns();
57
+ register_TFMP_InlineJobFns();
58
+
59
+ // Set up job queues
60
+ const queueRegistry = getTaskQueueRegistry();
61
+
62
+ queueRegistry.registerQueue(
63
+ new JobQueue(HF_TRANSFORMERS_ONNX, AiJob, {
64
+ limiter: new ConcurrencyLimiter(1, 100),
65
+ storage: new InMemoryQueueStorage(HF_TRANSFORMERS_ONNX),
66
+ })
67
+ );
68
+
69
+ queueRegistry.registerQueue(
70
+ new JobQueue(TENSORFLOW_MEDIAPIPE, AiJob, {
71
+ limiter: new ConcurrencyLimiter(1, 100),
72
+ storage: new InMemoryQueueStorage(TENSORFLOW_MEDIAPIPE),
73
+ })
74
+ );
75
+ ```
76
+
77
+ ### 2. Using AI Tasks in Workflows
78
+
79
+ ```typescript
80
+ import {
81
+ TextGenerationTask,
82
+ TextEmbeddingTask,
83
+ TextTranslationTask,
84
+ TextSummaryTask,
85
+ } from "@workglow/ai";
86
+ import { Workflow } from "@workglow/task-graph";
87
+
88
+ const workflow = new Workflow();
89
+
90
+ // Add AI tasks to your workflow
91
+ const result = await workflow
92
+ .add(
93
+ new TextGenerationTask({
94
+ model: "Xenova/gpt2",
95
+ prompt: "The future of AI is",
96
+ })
97
+ )
98
+ .add(
99
+ new TextEmbeddingTask({
100
+ model: "Xenova/all-MiniLM-L6-v2",
101
+ text: "Hello world",
102
+ })
103
+ )
104
+ .run();
105
+ ```
106
+
107
+ ## Available Providers
108
+
109
+ ### HuggingFace Transformers (`HF_TRANSFORMERS_ONNX`)
110
+
111
+ Supports ONNX models from HuggingFace Hub with the following task types:
112
+
113
+ #### Supported Tasks
114
+
115
+ - **TextGenerationTask**: Generate text from prompts
116
+ - **TextEmbeddingTask**: Generate vector embeddings for text
117
+ - **TextTranslationTask**: Translate text between languages
118
+ - **TextSummaryTask**: Summarize long text
119
+ - **TextRewriterTask**: Rewrite text with a given prompt
120
+ - **TextQuestionAnswerTask**: Answer questions based on context
121
+ - **DownloadModelTask**: Pre-download and cache models
122
+
123
+ #### Model Configuration
124
+
125
+ Models support various quantization options:
126
+
127
+ ```typescript
128
+ import { QUANTIZATION_DATA_TYPES } from "@workglow/ai-provider";
129
+
130
+ // Quantization options
131
+ // "auto" - Auto-detect based on environment
132
+ // "fp32" - 32-bit floating point
133
+ // "fp16" - 16-bit floating point
134
+ // "q8" - 8-bit quantized
135
+ // "int8" - 8-bit integer
136
+ // "uint8" - 8-bit unsigned integer
137
+ // "q4" - 4-bit quantized
138
+ // "bnb4" - BitsAndBytes 4-bit
139
+ // "q4f16" - fp16 model with int4 block weight quantization
140
+ ```
141
+
142
+ #### Task Examples
143
+
144
+ **Text Generation:**
145
+
146
+ ```typescript
147
+ import { TextGenerationTask } from "@workglow/ai";
148
+
149
+ const task = new TextGenerationTask({
150
+ model: "Xenova/gpt2",
151
+ prompt: "Once upon a time",
152
+ maxTokens: 50,
153
+ temperature: 0.7,
154
+ topP: 0.9,
155
+ frequencyPenalty: 0,
156
+ presencePenalty: 0,
157
+ });
158
+
159
+ const result = await task.execute();
160
+ // result.text: string - Generated text
161
+ ```
162
+
163
+ **Text Embedding:**
164
+
165
+ ```typescript
166
+ import { TextEmbeddingTask } from "@workglow/ai";
167
+
168
+ const task = new TextEmbeddingTask({
169
+ model: "Xenova/all-MiniLM-L6-v2",
170
+ text: "This is a sample text for embedding",
171
+ });
172
+
173
+ const result = await task.execute();
174
+ // result.vector: TypedArray - Vector embedding
175
+ ```
176
+
177
+ **Text Translation:**
178
+
179
+ ```typescript
180
+ import { TextTranslationTask } from "@workglow/ai";
181
+
182
+ const task = new TextTranslationTask({
183
+ model: "Xenova/t5-small",
184
+ text: "Hello world",
185
+ source_lang: "en",
186
+ target_lang: "fr",
187
+ });
188
+
189
+ const result = await task.execute();
190
+ // result.text: string - Translated text
191
+ // result.target_lang: string - Target language
192
+ ```
193
+
194
+ **Text Summary:**
195
+
196
+ ```typescript
197
+ import { TextSummaryTask } from "@workglow/ai";
198
+
199
+ const task = new TextSummaryTask({
200
+ model: "Xenova/distilbart-cnn-6-6",
201
+ text: "Long text to summarize...",
202
+ });
203
+
204
+ const result = await task.execute();
205
+ // result.text: string - Summary text
206
+ ```
207
+
208
+ **Text Rewriter:**
209
+
210
+ ```typescript
211
+ import { TextRewriterTask } from "@workglow/ai";
212
+
213
+ const task = new TextRewriterTask({
214
+ model: "Xenova/gpt2",
215
+ text: "The weather is nice today",
216
+ prompt: "Rewrite this as a pirate would say it",
217
+ });
218
+
219
+ const result = await task.execute();
220
+ // result.text: string - Rewritten text
221
+ ```
222
+
223
+ **Question Answering:**
224
+
225
+ ```typescript
226
+ import { TextQuestionAnswerTask } from "@workglow/ai";
227
+
228
+ const task = new TextQuestionAnswerTask({
229
+ model: "Xenova/distilbert-base-uncased-distilled-squad",
230
+ context: "The capital of France is Paris. It is known for the Eiffel Tower.",
231
+ question: "What is the capital of France?",
232
+ });
233
+
234
+ const result = await task.execute();
235
+ // result.text: string - Answer text
236
+ ```
237
+
238
+ ### TensorFlow MediaPipe (`TENSORFLOW_MEDIAPIPE`)
239
+
240
+ Optimized for performance using Google's MediaPipe framework.
241
+
242
+ #### Supported Tasks
243
+
244
+ - **TextEmbeddingTask**: Generate vector embeddings for text
245
+ - **DownloadModelTask**: Pre-download and cache models
246
+
247
+ #### Example
248
+
249
+ ```typescript
250
+ import { TextEmbeddingTask } from "@workglow/ai";
251
+
252
+ const task = new TextEmbeddingTask({
253
+ model: "path/to/mediapipe/model.tflite",
254
+ text: "Text to embed",
255
+ });
256
+
257
+ const result = await task.execute();
258
+ // result.vector: Float32Array - Vector embedding
259
+ ```
260
+
261
+ ## Advanced Usage
262
+
263
+ ### Worker Setup
264
+
265
+ For better performance, especially in browser environments, run AI inference in web workers:
266
+
267
+ #### Main Thread Setup
268
+
269
+ ```typescript
270
+ import { register_HFT_ClientJobFns, register_TFMP_ClientJobFns } from "@workglow/ai-provider";
271
+
272
+ // Register HuggingFace Transformers with worker
273
+ register_HFT_ClientJobFns(
274
+ new Worker(new URL("./hft-worker.ts", import.meta.url), { type: "module" })
275
+ );
276
+
277
+ // Register MediaPipe with worker
278
+ register_TFMP_ClientJobFns(
279
+ new Worker(new URL("./tfmp-worker.ts", import.meta.url), { type: "module" })
280
+ );
281
+ ```
282
+
283
+ #### Worker Setup Files
284
+
285
+ **hft-worker.ts:**
286
+
287
+ ```typescript
288
+ import { register_HFT_WorkerJobFns } from "@workglow/ai-provider";
289
+
290
+ // Register HuggingFace Transformers worker functions
291
+ register_HFT_WorkerJobFns();
292
+ ```
293
+
294
+ **tfmp-worker.ts:**
295
+
296
+ ```typescript
297
+ import { register_TFMP_WorkerJobFns } from "@workglow/ai-provider";
298
+
299
+ // Register MediaPipe worker functions
300
+ register_TFMP_WorkerJobFns();
301
+ ```
302
+
303
+ ### Model Management
304
+
305
+ ```typescript
306
+ import { getGlobalModelRepository } from "@workglow/ai";
307
+ import { DownloadModelTask } from "@workglow/ai";
308
+
309
+ // Pre-download models
310
+ const downloadTask = new DownloadModelTask({
311
+ model: "Xenova/all-MiniLM-L6-v2",
312
+ });
313
+
314
+ await downloadTask.execute();
315
+
316
+ // Models are automatically cached for subsequent use
317
+ ```
318
+
319
+ ### Custom Job Queue Configuration
320
+
321
+ ```typescript
322
+ import { JobQueue, ConcurrencyLimiter, DelayLimiter } from "@workglow/job-queue";
323
+ import { InMemoryQueueStorage } from "@workglow/storage";
324
+
325
+ // Configure queue with custom limits
326
+ const customQueue = new JobQueue(HF_TRANSFORMERS_ONNX, AiJob, {
327
+ limiter: new ConcurrencyLimiter(2, 1000), // 2 concurrent jobs, 1000ms timeout
328
+ storage: new InMemoryQueueStorage(HF_TRANSFORMERS_ONNX),
329
+ });
330
+ ```
331
+
332
+ ### Error Handling
333
+
334
+ ```typescript
335
+ import { PermanentJobError, AbortSignalJobError } from "@workglow/job-queue";
336
+
337
+ try {
338
+ const task = new TextGenerationTask({
339
+ model: "invalid-model",
340
+ prompt: "Test",
341
+ });
342
+
343
+ await task.execute();
344
+ } catch (error) {
345
+ if (error instanceof PermanentJobError) {
346
+ console.error("Permanent error:", error.message);
347
+ } else if (error instanceof AbortSignalJobError) {
348
+ console.error("Task was aborted");
349
+ }
350
+ }
351
+ ```
352
+
353
+ ### Progress Tracking
354
+
355
+ ```typescript
356
+ const task = new TextGenerationTask({
357
+ model: "Xenova/gpt2",
358
+ prompt: "Generate text...",
359
+ });
360
+
361
+ // Listen for progress updates
362
+ task.on("progress", (progress, message, details) => {
363
+ console.log(`Progress: ${progress}% - ${message}`, details);
364
+ });
365
+
366
+ await task.execute();
367
+ ```
368
+
369
+ ## Complete Working Example
370
+
371
+ ```typescript
372
+ import { HF_TRANSFORMERS_ONNX, register_HFT_InlineJobFns } from "@workglow/ai-provider";
373
+ import { TextGenerationTask, TextEmbeddingTask, AiJob } from "@workglow/ai";
374
+ import { Workflow, getTaskQueueRegistry } from "@workglow/task-graph";
375
+ import { JobQueue, ConcurrencyLimiter } from "@workglow/job-queue";
376
+ import { InMemoryQueueStorage } from "@workglow/storage";
377
+
378
+ async function main() {
379
+ // 1. Register the AI provider
380
+ await register_HFT_InlineJobFns();
381
+
382
+ // 2. Set up job queue
383
+ const queueRegistry = getTaskQueueRegistry();
384
+ queueRegistry.registerQueue(
385
+ new JobQueue(HF_TRANSFORMERS_ONNX, AiJob, {
386
+ limiter: new ConcurrencyLimiter(1, 100),
387
+ storage: new InMemoryQueueStorage(HF_TRANSFORMERS_ONNX),
388
+ })
389
+ );
390
+
391
+ // 3. Create and run workflow
392
+ const workflow = new Workflow();
393
+
394
+ const result = await workflow
395
+ .add(
396
+ new TextGenerationTask({
397
+ model: "Xenova/gpt2",
398
+ prompt: "The benefits of AI include",
399
+ maxTokens: 50,
400
+ })
401
+ )
402
+ .add(
403
+ new TextEmbeddingTask({
404
+ model: "Xenova/all-MiniLM-L6-v2",
405
+ text: "AI is transforming the world",
406
+ })
407
+ )
408
+ .run();
409
+
410
+ console.log("Generated text:", result.outputs[0].text);
411
+ console.log("Embedding dimensions:", result.outputs[1].vector.length);
412
+ }
413
+
414
+ main().catch(console.error);
415
+ ```
416
+
417
+ ## Task Input/Output Schemas
418
+
419
+ ### Common Types
420
+
421
+ ```typescript
422
+ // Model reference (string)
423
+ model: string
424
+
425
+ // Text input/output
426
+ text: string
427
+
428
+ // Vector embedding (typed array)
429
+ vector: Float32Array | Float64Array | Int32Array | etc.
430
+
431
+ // Language codes (ISO 639-1)
432
+ source_lang: string // e.g., "en", "fr", "es"
433
+ target_lang: string
434
+ ```
435
+
436
+ ### Task Schemas Summary
437
+
438
+ | Task | Input | Output |
439
+ | -------------------------- | ----------------------------------------------------------------------------------------- | ----------------------- |
440
+ | **TextGenerationTask** | `{ model, prompt, maxTokens?, temperature?, topP?, frequencyPenalty?, presencePenalty? }` | `{ text }` |
441
+ | **TextEmbeddingTask** | `{ model, text }` | `{ vector }` |
442
+ | **TextTranslationTask** | `{ model, text, source_lang, target_lang }` | `{ text, target_lang }` |
443
+ | **TextSummaryTask** | `{ model, text }` | `{ text }` |
444
+ | **TextRewriterTask** | `{ model, text, prompt }` | `{ text }` |
445
+ | **TextQuestionAnswerTask** | `{ model, context, question }` | `{ text }` |
446
+ | **DownloadModelTask** | `{ model }` | `{ model }` |
447
+
448
+ ## Popular Models
449
+
450
+ ### HuggingFace Transformers Models
451
+
452
+ **Text Generation:**
453
+
454
+ - `Xenova/gpt2` - GPT-2 text generation
455
+ - `Xenova/distilgpt2` - Smaller GPT-2 variant
456
+
457
+ **Text Embedding:**
458
+
459
+ - `Xenova/all-MiniLM-L6-v2` - General purpose embeddings
460
+ - `Xenova/all-mpnet-base-v2` - High quality embeddings
461
+
462
+ **Translation:**
463
+
464
+ - `Xenova/t5-small` - Multilingual translation
465
+ - `Xenova/marian-mt-en-fr` - English to French
466
+
467
+ **Summarization:**
468
+
469
+ - `Xenova/distilbart-cnn-6-6` - News summarization
470
+ - `Xenova/t5-small` - General summarization
471
+
472
+ **Question Answering:**
473
+
474
+ - `Xenova/distilbert-base-uncased-distilled-squad` - SQuAD trained
475
+
476
+ ## Dependencies
477
+
478
+ This package depends on:
479
+
480
+ - `@workglow/ai` - Core AI abstractions
481
+ - `@workglow/job-queue` - Job queue system
482
+ - `@workglow/storage` - Storage abstractions
483
+ - `@workglow/task-graph` - Task graph system
484
+ - `@workglow/util` - Utility functions
485
+
486
+ ## License
487
+
488
+ Apache 2.0 - See [LICENSE](./LICENSE) for details.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export declare const LOCAL_LLAMACPP = "LOCAL_LLAMACPP";
7
+ //# sourceMappingURL=GgmlLocalModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GgmlLocalModel.d.ts","sourceRoot":"","sources":["../../../src/ggml/model/GgmlLocalModel.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=server.d.ts.map