@workglow/ai-provider 0.0.90 → 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 +83 -18
- 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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { AiProvider, type AiProviderRunFn, type AiProviderStreamFn } from "@workglow/ai";
|
|
7
|
+
import type { OllamaModelConfig } from "./common/Ollama_ModelSchema";
|
|
8
|
+
/**
|
|
9
|
+
* AI provider for Ollama local LLM server.
|
|
10
|
+
*
|
|
11
|
+
* Supports text generation, text embedding, text rewriting, and text summarization
|
|
12
|
+
* via the Ollama API using the `ollama` SDK.
|
|
13
|
+
*
|
|
14
|
+
* Ollama runs locally and does not require an API key -- only a `base_url`
|
|
15
|
+
* (defaults to `http://localhost:11434`).
|
|
16
|
+
*
|
|
17
|
+
* Task run functions are injected via the constructor so that the `ollama` SDK
|
|
18
|
+
* is only imported where actually needed (inline mode, worker server), not on
|
|
19
|
+
* the main thread in worker mode.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Worker mode (main thread) -- lightweight, no SDK import:
|
|
24
|
+
* await new OllamaProvider().register({
|
|
25
|
+
* mode: "worker",
|
|
26
|
+
* worker: new Worker(new URL("./worker_ollama.ts", import.meta.url), { type: "module" }),
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Inline mode -- caller provides the tasks:
|
|
30
|
+
* import { OLLAMA_TASKS } from "@workglow/ai-provider/ollama";
|
|
31
|
+
* await new OllamaProvider(OLLAMA_TASKS).register({ mode: "inline" });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class OllamaProvider extends AiProvider<OllamaModelConfig> {
|
|
35
|
+
readonly name = "OLLAMA";
|
|
36
|
+
readonly taskTypes: readonly ["TextGenerationTask", "TextEmbeddingTask", "TextRewriterTask", "TextSummaryTask"];
|
|
37
|
+
constructor(tasks?: Record<string, AiProviderRunFn<any, any, OllamaModelConfig>>, streamTasks?: Record<string, AiProviderStreamFn<any, any, OllamaModelConfig>>);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=OllamaProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OllamaProvider.d.ts","sourceRoot":"","sources":["../../src/provider-ollama/OllamaProvider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEzF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,cAAe,SAAQ,UAAU,CAAC,iBAAiB,CAAC;IAC/D,QAAQ,CAAC,IAAI,YAAU;IAEvB,QAAQ,CAAC,SAAS,8FAKP;gBAGT,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC,EACpE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC;CAIhF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ollama_Worker.d.ts","sourceRoot":"","sources":["../../src/provider-ollama/Ollama_Worker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,wBAAgB,6BAA6B,SAK5C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export declare const OLLAMA = "OLLAMA";
|
|
7
|
+
export declare const OLLAMA_DEFAULT_BASE_URL = "http://localhost:11434";
|
|
8
|
+
//# sourceMappingURL=Ollama_Constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ollama_Constants.d.ts","sourceRoot":"","sources":["../../../src/provider-ollama/common/Ollama_Constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,eAAO,MAAM,uBAAuB,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProviderRunFn, AiProviderStreamFn, TextEmbeddingTaskInput, TextEmbeddingTaskOutput, TextGenerationTaskInput, TextGenerationTaskOutput, TextRewriterTaskInput, TextRewriterTaskOutput, TextSummaryTaskInput, TextSummaryTaskOutput } from "@workglow/ai";
|
|
7
|
+
import type { OllamaModelConfig } from "./Ollama_ModelSchema";
|
|
8
|
+
export declare const Ollama_TextGeneration: AiProviderRunFn<TextGenerationTaskInput, TextGenerationTaskOutput, OllamaModelConfig>;
|
|
9
|
+
export declare const Ollama_TextEmbedding: AiProviderRunFn<TextEmbeddingTaskInput, TextEmbeddingTaskOutput, OllamaModelConfig>;
|
|
10
|
+
export declare const Ollama_TextRewriter: AiProviderRunFn<TextRewriterTaskInput, TextRewriterTaskOutput, OllamaModelConfig>;
|
|
11
|
+
export declare const Ollama_TextSummary: AiProviderRunFn<TextSummaryTaskInput, TextSummaryTaskOutput, OllamaModelConfig>;
|
|
12
|
+
export declare const Ollama_TextGeneration_Stream: AiProviderStreamFn<TextGenerationTaskInput, TextGenerationTaskOutput, OllamaModelConfig>;
|
|
13
|
+
export declare const Ollama_TextRewriter_Stream: AiProviderStreamFn<TextRewriterTaskInput, TextRewriterTaskOutput, OllamaModelConfig>;
|
|
14
|
+
export declare const Ollama_TextSummary_Stream: AiProviderStreamFn<TextSummaryTaskInput, TextSummaryTaskOutput, OllamaModelConfig>;
|
|
15
|
+
export declare const OLLAMA_TASKS: Record<string, AiProviderRunFn<any, any, OllamaModelConfig>>;
|
|
16
|
+
export declare const OLLAMA_STREAM_TASKS: Record<string, AiProviderStreamFn<any, any, OllamaModelConfig>>;
|
|
17
|
+
//# sourceMappingURL=Ollama_JobRunFns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ollama_JobRunFns.d.ts","sourceRoot":"","sources":["../../../src/provider-ollama/common/Ollama_JobRunFns.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AA4B9D,eAAO,MAAM,qBAAqB,EAAE,eAAe,CACjD,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,CAoBlB,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,eAAe,CAChD,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,CAqBlB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,eAAe,CAC/C,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,CAgBlB,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,CAgBlB,CAAC;AAMF,eAAO,MAAM,4BAA4B,EAAE,kBAAkB,CAC3D,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,CAyBlB,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,kBAAkB,CACzD,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,CAqBlB,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,kBAAkB,CACxD,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,CAqBlB,CAAC;AAMF,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAKrF,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CACtC,MAAM,EACN,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAKhD,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { FromSchema } from "@workglow/util";
|
|
7
|
+
export declare const OllamaModelSchema: {
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly provider: {
|
|
11
|
+
readonly const: "OLLAMA";
|
|
12
|
+
readonly description: "Discriminator: Ollama local LLM server.";
|
|
13
|
+
};
|
|
14
|
+
readonly provider_config: {
|
|
15
|
+
readonly type: "object";
|
|
16
|
+
readonly description: "Ollama-specific configuration.";
|
|
17
|
+
readonly properties: {
|
|
18
|
+
readonly model_name: {
|
|
19
|
+
readonly type: "string";
|
|
20
|
+
readonly description: "The Ollama model identifier (e.g., 'llama3.2', 'nomic-embed-text').";
|
|
21
|
+
};
|
|
22
|
+
readonly base_url: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
readonly description: "Base URL for the Ollama server.";
|
|
25
|
+
readonly default: "http://localhost:11434";
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
readonly required: readonly ["model_name"];
|
|
29
|
+
readonly additionalProperties: false;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
readonly required: readonly ["provider", "provider_config"];
|
|
33
|
+
readonly additionalProperties: true;
|
|
34
|
+
};
|
|
35
|
+
export declare const OllamaModelRecordSchema: {
|
|
36
|
+
readonly type: "object";
|
|
37
|
+
readonly properties: {
|
|
38
|
+
readonly provider: {
|
|
39
|
+
readonly const: "OLLAMA";
|
|
40
|
+
readonly description: "Discriminator: Ollama local LLM server.";
|
|
41
|
+
};
|
|
42
|
+
readonly provider_config: {
|
|
43
|
+
readonly type: "object";
|
|
44
|
+
readonly description: "Ollama-specific configuration.";
|
|
45
|
+
readonly properties: {
|
|
46
|
+
readonly model_name: {
|
|
47
|
+
readonly type: "string";
|
|
48
|
+
readonly description: "The Ollama model identifier (e.g., 'llama3.2', 'nomic-embed-text').";
|
|
49
|
+
};
|
|
50
|
+
readonly base_url: {
|
|
51
|
+
readonly type: "string";
|
|
52
|
+
readonly description: "Base URL for the Ollama server.";
|
|
53
|
+
readonly default: "http://localhost:11434";
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
readonly required: readonly ["model_name"];
|
|
57
|
+
readonly additionalProperties: false;
|
|
58
|
+
};
|
|
59
|
+
readonly model_id: {
|
|
60
|
+
readonly type: "string";
|
|
61
|
+
};
|
|
62
|
+
readonly tasks: {
|
|
63
|
+
readonly type: "array";
|
|
64
|
+
readonly items: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
};
|
|
67
|
+
readonly "x-ui-editor": "multiselect";
|
|
68
|
+
};
|
|
69
|
+
readonly title: {
|
|
70
|
+
readonly type: "string";
|
|
71
|
+
};
|
|
72
|
+
readonly description: {
|
|
73
|
+
readonly type: "string";
|
|
74
|
+
readonly "x-ui-editor": "textarea";
|
|
75
|
+
};
|
|
76
|
+
readonly metadata: {
|
|
77
|
+
readonly type: "object";
|
|
78
|
+
readonly default: {};
|
|
79
|
+
readonly "x-ui-hidden": true;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
readonly required: readonly ["model_id", "tasks", "provider", "title", "description", "provider_config", "metadata", "provider", "provider_config"];
|
|
83
|
+
readonly additionalProperties: false;
|
|
84
|
+
};
|
|
85
|
+
export type OllamaModelRecord = FromSchema<typeof OllamaModelRecordSchema>;
|
|
86
|
+
export declare const OllamaModelConfigSchema: {
|
|
87
|
+
readonly type: "object";
|
|
88
|
+
readonly properties: {
|
|
89
|
+
readonly provider: {
|
|
90
|
+
readonly const: "OLLAMA";
|
|
91
|
+
readonly description: "Discriminator: Ollama local LLM server.";
|
|
92
|
+
};
|
|
93
|
+
readonly provider_config: {
|
|
94
|
+
readonly type: "object";
|
|
95
|
+
readonly description: "Ollama-specific configuration.";
|
|
96
|
+
readonly properties: {
|
|
97
|
+
readonly model_name: {
|
|
98
|
+
readonly type: "string";
|
|
99
|
+
readonly description: "The Ollama model identifier (e.g., 'llama3.2', 'nomic-embed-text').";
|
|
100
|
+
};
|
|
101
|
+
readonly base_url: {
|
|
102
|
+
readonly type: "string";
|
|
103
|
+
readonly description: "Base URL for the Ollama server.";
|
|
104
|
+
readonly default: "http://localhost:11434";
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
readonly required: readonly ["model_name"];
|
|
108
|
+
readonly additionalProperties: false;
|
|
109
|
+
};
|
|
110
|
+
readonly model_id: {
|
|
111
|
+
readonly type: "string";
|
|
112
|
+
};
|
|
113
|
+
readonly tasks: {
|
|
114
|
+
readonly type: "array";
|
|
115
|
+
readonly items: {
|
|
116
|
+
readonly type: "string";
|
|
117
|
+
};
|
|
118
|
+
readonly "x-ui-editor": "multiselect";
|
|
119
|
+
};
|
|
120
|
+
readonly title: {
|
|
121
|
+
readonly type: "string";
|
|
122
|
+
};
|
|
123
|
+
readonly description: {
|
|
124
|
+
readonly type: "string";
|
|
125
|
+
readonly "x-ui-editor": "textarea";
|
|
126
|
+
};
|
|
127
|
+
readonly metadata: {
|
|
128
|
+
readonly type: "object";
|
|
129
|
+
readonly default: {};
|
|
130
|
+
readonly "x-ui-hidden": true;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
readonly required: readonly ["provider", "provider_config", "provider", "provider_config"];
|
|
134
|
+
readonly additionalProperties: false;
|
|
135
|
+
};
|
|
136
|
+
export type OllamaModelConfig = FromSchema<typeof OllamaModelConfigSchema>;
|
|
137
|
+
//# sourceMappingURL=Ollama_ModelSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ollama_ModelSchema.d.ts","sourceRoot":"","sources":["../../../src/provider-ollama/common/Ollama_ModelSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAwB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGlE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BW,CAAC;AAE1C,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQK,CAAC;AAE1C,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE3E,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQK,CAAC;AAE1C,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export * from "./common/Ollama_Constants";
|
|
7
|
+
export * from "./common/Ollama_JobRunFns";
|
|
8
|
+
export * from "./common/Ollama_ModelSchema";
|
|
9
|
+
export * from "./Ollama_Worker";
|
|
10
|
+
export * from "./OllamaProvider";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider-ollama/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,274 @@
|
|
|
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/provider-ollama/common/Ollama_Constants.ts
|
|
21
|
+
var OLLAMA = "OLLAMA";
|
|
22
|
+
var OLLAMA_DEFAULT_BASE_URL = "http://localhost:11434";
|
|
23
|
+
// src/provider-ollama/common/Ollama_JobRunFns.ts
|
|
24
|
+
var _sdk;
|
|
25
|
+
async function loadOllamaSDK() {
|
|
26
|
+
if (!_sdk) {
|
|
27
|
+
try {
|
|
28
|
+
_sdk = await import("ollama/browser");
|
|
29
|
+
} catch {
|
|
30
|
+
throw new Error("ollama is required for Ollama tasks. Install it with: bun add ollama");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return _sdk.Ollama;
|
|
34
|
+
}
|
|
35
|
+
async function getClient(model) {
|
|
36
|
+
const Ollama = await loadOllamaSDK();
|
|
37
|
+
const host = model?.provider_config?.base_url || OLLAMA_DEFAULT_BASE_URL;
|
|
38
|
+
return new Ollama({ host });
|
|
39
|
+
}
|
|
40
|
+
function getModelName(model) {
|
|
41
|
+
const name = model?.provider_config?.model_name;
|
|
42
|
+
if (!name) {
|
|
43
|
+
throw new Error("Missing model name in provider_config.model_name.");
|
|
44
|
+
}
|
|
45
|
+
return name;
|
|
46
|
+
}
|
|
47
|
+
var Ollama_TextGeneration = async (input, model, update_progress, signal) => {
|
|
48
|
+
update_progress(0, "Starting Ollama text generation");
|
|
49
|
+
const client = await getClient(model);
|
|
50
|
+
const modelName = getModelName(model);
|
|
51
|
+
const response = await client.chat({
|
|
52
|
+
model: modelName,
|
|
53
|
+
messages: [{ role: "user", content: input.prompt }],
|
|
54
|
+
options: {
|
|
55
|
+
temperature: input.temperature,
|
|
56
|
+
top_p: input.topP,
|
|
57
|
+
num_predict: input.maxTokens,
|
|
58
|
+
frequency_penalty: input.frequencyPenalty,
|
|
59
|
+
presence_penalty: input.presencePenalty
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
update_progress(100, "Completed Ollama text generation");
|
|
63
|
+
return { text: response.message.content };
|
|
64
|
+
};
|
|
65
|
+
var Ollama_TextEmbedding = async (input, model, update_progress, signal) => {
|
|
66
|
+
update_progress(0, "Starting Ollama text embedding");
|
|
67
|
+
const client = await getClient(model);
|
|
68
|
+
const modelName = getModelName(model);
|
|
69
|
+
const texts = Array.isArray(input.text) ? input.text : [input.text];
|
|
70
|
+
const response = await client.embed({
|
|
71
|
+
model: modelName,
|
|
72
|
+
input: texts
|
|
73
|
+
});
|
|
74
|
+
update_progress(100, "Completed Ollama text embedding");
|
|
75
|
+
if (Array.isArray(input.text)) {
|
|
76
|
+
return {
|
|
77
|
+
vector: response.embeddings.map((e) => new Float32Array(e))
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return { vector: new Float32Array(response.embeddings[0]) };
|
|
81
|
+
};
|
|
82
|
+
var Ollama_TextRewriter = async (input, model, update_progress, signal) => {
|
|
83
|
+
update_progress(0, "Starting Ollama text rewriting");
|
|
84
|
+
const client = await getClient(model);
|
|
85
|
+
const modelName = getModelName(model);
|
|
86
|
+
const response = await client.chat({
|
|
87
|
+
model: modelName,
|
|
88
|
+
messages: [
|
|
89
|
+
{ role: "system", content: input.prompt },
|
|
90
|
+
{ role: "user", content: input.text }
|
|
91
|
+
]
|
|
92
|
+
});
|
|
93
|
+
update_progress(100, "Completed Ollama text rewriting");
|
|
94
|
+
return { text: response.message.content };
|
|
95
|
+
};
|
|
96
|
+
var Ollama_TextSummary = async (input, model, update_progress, signal) => {
|
|
97
|
+
update_progress(0, "Starting Ollama text summarization");
|
|
98
|
+
const client = await getClient(model);
|
|
99
|
+
const modelName = getModelName(model);
|
|
100
|
+
const response = await client.chat({
|
|
101
|
+
model: modelName,
|
|
102
|
+
messages: [
|
|
103
|
+
{ role: "system", content: "Summarize the following text concisely." },
|
|
104
|
+
{ role: "user", content: input.text }
|
|
105
|
+
]
|
|
106
|
+
});
|
|
107
|
+
update_progress(100, "Completed Ollama text summarization");
|
|
108
|
+
return { text: response.message.content };
|
|
109
|
+
};
|
|
110
|
+
var Ollama_TextGeneration_Stream = async function* (input, model, signal) {
|
|
111
|
+
const client = await getClient(model);
|
|
112
|
+
const modelName = getModelName(model);
|
|
113
|
+
const stream = await client.chat({
|
|
114
|
+
model: modelName,
|
|
115
|
+
messages: [{ role: "user", content: input.prompt }],
|
|
116
|
+
options: {
|
|
117
|
+
temperature: input.temperature,
|
|
118
|
+
top_p: input.topP,
|
|
119
|
+
num_predict: input.maxTokens,
|
|
120
|
+
frequency_penalty: input.frequencyPenalty,
|
|
121
|
+
presence_penalty: input.presencePenalty
|
|
122
|
+
},
|
|
123
|
+
stream: true
|
|
124
|
+
});
|
|
125
|
+
for await (const chunk of stream) {
|
|
126
|
+
const delta = chunk.message.content;
|
|
127
|
+
if (delta) {
|
|
128
|
+
yield { type: "text-delta", textDelta: delta };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
yield { type: "finish", data: {} };
|
|
132
|
+
};
|
|
133
|
+
var Ollama_TextRewriter_Stream = async function* (input, model, signal) {
|
|
134
|
+
const client = await getClient(model);
|
|
135
|
+
const modelName = getModelName(model);
|
|
136
|
+
const stream = await client.chat({
|
|
137
|
+
model: modelName,
|
|
138
|
+
messages: [
|
|
139
|
+
{ role: "system", content: input.prompt },
|
|
140
|
+
{ role: "user", content: input.text }
|
|
141
|
+
],
|
|
142
|
+
stream: true
|
|
143
|
+
});
|
|
144
|
+
for await (const chunk of stream) {
|
|
145
|
+
const delta = chunk.message.content;
|
|
146
|
+
if (delta) {
|
|
147
|
+
yield { type: "text-delta", textDelta: delta };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
yield { type: "finish", data: {} };
|
|
151
|
+
};
|
|
152
|
+
var Ollama_TextSummary_Stream = async function* (input, model, signal) {
|
|
153
|
+
const client = await getClient(model);
|
|
154
|
+
const modelName = getModelName(model);
|
|
155
|
+
const stream = await client.chat({
|
|
156
|
+
model: modelName,
|
|
157
|
+
messages: [
|
|
158
|
+
{ role: "system", content: "Summarize the following text concisely." },
|
|
159
|
+
{ role: "user", content: input.text }
|
|
160
|
+
],
|
|
161
|
+
stream: true
|
|
162
|
+
});
|
|
163
|
+
for await (const chunk of stream) {
|
|
164
|
+
const delta = chunk.message.content;
|
|
165
|
+
if (delta) {
|
|
166
|
+
yield { type: "text-delta", textDelta: delta };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
yield { type: "finish", data: {} };
|
|
170
|
+
};
|
|
171
|
+
var OLLAMA_TASKS = {
|
|
172
|
+
TextGenerationTask: Ollama_TextGeneration,
|
|
173
|
+
TextEmbeddingTask: Ollama_TextEmbedding,
|
|
174
|
+
TextRewriterTask: Ollama_TextRewriter,
|
|
175
|
+
TextSummaryTask: Ollama_TextSummary
|
|
176
|
+
};
|
|
177
|
+
var OLLAMA_STREAM_TASKS = {
|
|
178
|
+
TextGenerationTask: Ollama_TextGeneration_Stream,
|
|
179
|
+
TextRewriterTask: Ollama_TextRewriter_Stream,
|
|
180
|
+
TextSummaryTask: Ollama_TextSummary_Stream
|
|
181
|
+
};
|
|
182
|
+
// src/provider-ollama/common/Ollama_ModelSchema.ts
|
|
183
|
+
import { ModelConfigSchema, ModelRecordSchema } from "@workglow/ai";
|
|
184
|
+
var OllamaModelSchema = {
|
|
185
|
+
type: "object",
|
|
186
|
+
properties: {
|
|
187
|
+
provider: {
|
|
188
|
+
const: OLLAMA,
|
|
189
|
+
description: "Discriminator: Ollama local LLM server."
|
|
190
|
+
},
|
|
191
|
+
provider_config: {
|
|
192
|
+
type: "object",
|
|
193
|
+
description: "Ollama-specific configuration.",
|
|
194
|
+
properties: {
|
|
195
|
+
model_name: {
|
|
196
|
+
type: "string",
|
|
197
|
+
description: "The Ollama model identifier (e.g., 'llama3.2', 'nomic-embed-text')."
|
|
198
|
+
},
|
|
199
|
+
base_url: {
|
|
200
|
+
type: "string",
|
|
201
|
+
description: "Base URL for the Ollama server.",
|
|
202
|
+
default: OLLAMA_DEFAULT_BASE_URL
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
required: ["model_name"],
|
|
206
|
+
additionalProperties: false
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
required: ["provider", "provider_config"],
|
|
210
|
+
additionalProperties: true
|
|
211
|
+
};
|
|
212
|
+
var OllamaModelRecordSchema = {
|
|
213
|
+
type: "object",
|
|
214
|
+
properties: {
|
|
215
|
+
...ModelRecordSchema.properties,
|
|
216
|
+
...OllamaModelSchema.properties
|
|
217
|
+
},
|
|
218
|
+
required: [...ModelRecordSchema.required, ...OllamaModelSchema.required],
|
|
219
|
+
additionalProperties: false
|
|
220
|
+
};
|
|
221
|
+
var OllamaModelConfigSchema = {
|
|
222
|
+
type: "object",
|
|
223
|
+
properties: {
|
|
224
|
+
...ModelConfigSchema.properties,
|
|
225
|
+
...OllamaModelSchema.properties
|
|
226
|
+
},
|
|
227
|
+
required: [...ModelConfigSchema.required, ...OllamaModelSchema.required],
|
|
228
|
+
additionalProperties: false
|
|
229
|
+
};
|
|
230
|
+
// src/provider-ollama/Ollama_Worker.ts
|
|
231
|
+
import { globalServiceRegistry, parentPort, WORKER_SERVER } from "@workglow/util";
|
|
232
|
+
|
|
233
|
+
// src/provider-ollama/OllamaProvider.ts
|
|
234
|
+
import { AiProvider } from "@workglow/ai";
|
|
235
|
+
class OllamaProvider extends AiProvider {
|
|
236
|
+
name = OLLAMA;
|
|
237
|
+
taskTypes = [
|
|
238
|
+
"TextGenerationTask",
|
|
239
|
+
"TextEmbeddingTask",
|
|
240
|
+
"TextRewriterTask",
|
|
241
|
+
"TextSummaryTask"
|
|
242
|
+
];
|
|
243
|
+
constructor(tasks, streamTasks) {
|
|
244
|
+
super(tasks, streamTasks);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/provider-ollama/Ollama_Worker.ts
|
|
249
|
+
function OLLAMA_WORKER_JOBRUN_REGISTER() {
|
|
250
|
+
const workerServer = globalServiceRegistry.get(WORKER_SERVER);
|
|
251
|
+
new OllamaProvider(OLLAMA_TASKS, OLLAMA_STREAM_TASKS).registerOnWorkerServer(workerServer);
|
|
252
|
+
parentPort.postMessage({ type: "ready" });
|
|
253
|
+
console.log("OLLAMA_WORKER_JOBRUN registered");
|
|
254
|
+
}
|
|
255
|
+
export {
|
|
256
|
+
Ollama_TextSummary_Stream,
|
|
257
|
+
Ollama_TextSummary,
|
|
258
|
+
Ollama_TextRewriter_Stream,
|
|
259
|
+
Ollama_TextRewriter,
|
|
260
|
+
Ollama_TextGeneration_Stream,
|
|
261
|
+
Ollama_TextGeneration,
|
|
262
|
+
Ollama_TextEmbedding,
|
|
263
|
+
OllamaProvider,
|
|
264
|
+
OllamaModelSchema,
|
|
265
|
+
OllamaModelRecordSchema,
|
|
266
|
+
OllamaModelConfigSchema,
|
|
267
|
+
OLLAMA_WORKER_JOBRUN_REGISTER,
|
|
268
|
+
OLLAMA_TASKS,
|
|
269
|
+
OLLAMA_STREAM_TASKS,
|
|
270
|
+
OLLAMA_DEFAULT_BASE_URL,
|
|
271
|
+
OLLAMA
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
//# debugId=75DCC231FAFD3E6364756E2164756E21
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/provider-ollama/common/Ollama_Constants.ts", "../src/provider-ollama/common/Ollama_JobRunFns.ts", "../src/provider-ollama/common/Ollama_ModelSchema.ts", "../src/provider-ollama/Ollama_Worker.ts", "../src/provider-ollama/OllamaProvider.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport const OLLAMA = \"OLLAMA\";\nexport const OLLAMA_DEFAULT_BASE_URL = \"http://localhost:11434\";\n",
|
|
6
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AiProviderRunFn,\n AiProviderStreamFn,\n TextEmbeddingTaskInput,\n TextEmbeddingTaskOutput,\n TextGenerationTaskInput,\n TextGenerationTaskOutput,\n TextRewriterTaskInput,\n TextRewriterTaskOutput,\n TextSummaryTaskInput,\n TextSummaryTaskOutput,\n} from \"@workglow/ai\";\nimport type { StreamEvent } from \"@workglow/task-graph\";\nimport { OLLAMA_DEFAULT_BASE_URL } from \"./Ollama_Constants\";\nimport type { OllamaModelConfig } from \"./Ollama_ModelSchema\";\n\nlet _sdk: typeof import(\"ollama/browser\") | undefined;\nasync function loadOllamaSDK() {\n if (!_sdk) {\n try {\n _sdk = await import(\"ollama/browser\");\n } catch {\n throw new Error(\"ollama is required for Ollama tasks. Install it with: bun add ollama\");\n }\n }\n return _sdk.Ollama;\n}\n\nasync function getClient(model: OllamaModelConfig | undefined) {\n const Ollama = await loadOllamaSDK();\n const host = model?.provider_config?.base_url || OLLAMA_DEFAULT_BASE_URL;\n return new Ollama({ host });\n}\n\nfunction getModelName(model: OllamaModelConfig | undefined): string {\n const name = model?.provider_config?.model_name;\n if (!name) {\n throw new Error(\"Missing model name in provider_config.model_name.\");\n }\n return name;\n}\n\nexport const Ollama_TextGeneration: AiProviderRunFn<\n TextGenerationTaskInput,\n TextGenerationTaskOutput,\n OllamaModelConfig\n> = async (input, model, update_progress, signal) => {\n update_progress(0, \"Starting Ollama text generation\");\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const response = await client.chat({\n model: modelName,\n messages: [{ role: \"user\", content: input.prompt }],\n options: {\n temperature: input.temperature,\n top_p: input.topP,\n num_predict: input.maxTokens,\n frequency_penalty: input.frequencyPenalty,\n presence_penalty: input.presencePenalty,\n },\n });\n\n update_progress(100, \"Completed Ollama text generation\");\n return { text: response.message.content };\n};\n\nexport const Ollama_TextEmbedding: AiProviderRunFn<\n TextEmbeddingTaskInput,\n TextEmbeddingTaskOutput,\n OllamaModelConfig\n> = async (input, model, update_progress, signal) => {\n update_progress(0, \"Starting Ollama text embedding\");\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const texts = Array.isArray(input.text) ? input.text : [input.text];\n\n const response = await client.embed({\n model: modelName,\n input: texts,\n });\n\n update_progress(100, \"Completed Ollama text embedding\");\n\n if (Array.isArray(input.text)) {\n return {\n vector: response.embeddings.map((e) => new Float32Array(e)),\n };\n }\n return { vector: new Float32Array(response.embeddings[0]) };\n};\n\nexport const Ollama_TextRewriter: AiProviderRunFn<\n TextRewriterTaskInput,\n TextRewriterTaskOutput,\n OllamaModelConfig\n> = async (input, model, update_progress, signal) => {\n update_progress(0, \"Starting Ollama text rewriting\");\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const response = await client.chat({\n model: modelName,\n messages: [\n { role: \"system\", content: input.prompt },\n { role: \"user\", content: input.text },\n ],\n });\n\n update_progress(100, \"Completed Ollama text rewriting\");\n return { text: response.message.content };\n};\n\nexport const Ollama_TextSummary: AiProviderRunFn<\n TextSummaryTaskInput,\n TextSummaryTaskOutput,\n OllamaModelConfig\n> = async (input, model, update_progress, signal) => {\n update_progress(0, \"Starting Ollama text summarization\");\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const response = await client.chat({\n model: modelName,\n messages: [\n { role: \"system\", content: \"Summarize the following text concisely.\" },\n { role: \"user\", content: input.text },\n ],\n });\n\n update_progress(100, \"Completed Ollama text summarization\");\n return { text: response.message.content };\n};\n\n// ========================================================================\n// Streaming implementations (append mode)\n// ========================================================================\n\nexport const Ollama_TextGeneration_Stream: AiProviderStreamFn<\n TextGenerationTaskInput,\n TextGenerationTaskOutput,\n OllamaModelConfig\n> = async function* (input, model, signal): AsyncIterable<StreamEvent<TextGenerationTaskOutput>> {\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const stream = await client.chat({\n model: modelName,\n messages: [{ role: \"user\", content: input.prompt }],\n options: {\n temperature: input.temperature,\n top_p: input.topP,\n num_predict: input.maxTokens,\n frequency_penalty: input.frequencyPenalty,\n presence_penalty: input.presencePenalty,\n },\n stream: true,\n });\n\n for await (const chunk of stream) {\n const delta = chunk.message.content;\n if (delta) {\n yield { type: \"text-delta\", textDelta: delta };\n }\n }\n yield { type: \"finish\", data: {} as TextGenerationTaskOutput };\n};\n\nexport const Ollama_TextRewriter_Stream: AiProviderStreamFn<\n TextRewriterTaskInput,\n TextRewriterTaskOutput,\n OllamaModelConfig\n> = async function* (input, model, signal): AsyncIterable<StreamEvent<TextRewriterTaskOutput>> {\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const stream = await client.chat({\n model: modelName,\n messages: [\n { role: \"system\", content: input.prompt },\n { role: \"user\", content: input.text },\n ],\n stream: true,\n });\n\n for await (const chunk of stream) {\n const delta = chunk.message.content;\n if (delta) {\n yield { type: \"text-delta\", textDelta: delta };\n }\n }\n yield { type: \"finish\", data: {} as TextRewriterTaskOutput };\n};\n\nexport const Ollama_TextSummary_Stream: AiProviderStreamFn<\n TextSummaryTaskInput,\n TextSummaryTaskOutput,\n OllamaModelConfig\n> = async function* (input, model, signal): AsyncIterable<StreamEvent<TextSummaryTaskOutput>> {\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const stream = await client.chat({\n model: modelName,\n messages: [\n { role: \"system\", content: \"Summarize the following text concisely.\" },\n { role: \"user\", content: input.text },\n ],\n stream: true,\n });\n\n for await (const chunk of stream) {\n const delta = chunk.message.content;\n if (delta) {\n yield { type: \"text-delta\", textDelta: delta };\n }\n }\n yield { type: \"finish\", data: {} as TextSummaryTaskOutput };\n};\n\n// ========================================================================\n// Task registries\n// ========================================================================\n\nexport const OLLAMA_TASKS: Record<string, AiProviderRunFn<any, any, OllamaModelConfig>> = {\n TextGenerationTask: Ollama_TextGeneration,\n TextEmbeddingTask: Ollama_TextEmbedding,\n TextRewriterTask: Ollama_TextRewriter,\n TextSummaryTask: Ollama_TextSummary,\n};\n\nexport const OLLAMA_STREAM_TASKS: Record<\n string,\n AiProviderStreamFn<any, any, OllamaModelConfig>\n> = {\n TextGenerationTask: Ollama_TextGeneration_Stream,\n TextRewriterTask: Ollama_TextRewriter_Stream,\n TextSummaryTask: Ollama_TextSummary_Stream,\n};\n",
|
|
7
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ModelConfigSchema, ModelRecordSchema } from \"@workglow/ai\";\nimport { DataPortSchemaObject, FromSchema } from \"@workglow/util\";\nimport { OLLAMA, OLLAMA_DEFAULT_BASE_URL } from \"./Ollama_Constants\";\n\nexport const OllamaModelSchema = {\n type: \"object\",\n properties: {\n provider: {\n const: OLLAMA,\n description: \"Discriminator: Ollama local LLM server.\",\n },\n provider_config: {\n type: \"object\",\n description: \"Ollama-specific configuration.\",\n properties: {\n model_name: {\n type: \"string\",\n description: \"The Ollama model identifier (e.g., 'llama3.2', 'nomic-embed-text').\",\n },\n base_url: {\n type: \"string\",\n description: \"Base URL for the Ollama server.\",\n default: OLLAMA_DEFAULT_BASE_URL,\n },\n },\n required: [\"model_name\"],\n additionalProperties: false,\n },\n },\n required: [\"provider\", \"provider_config\"],\n additionalProperties: true,\n} as const satisfies DataPortSchemaObject;\n\nexport const OllamaModelRecordSchema = {\n type: \"object\",\n properties: {\n ...ModelRecordSchema.properties,\n ...OllamaModelSchema.properties,\n },\n required: [...ModelRecordSchema.required, ...OllamaModelSchema.required],\n additionalProperties: false,\n} as const satisfies DataPortSchemaObject;\n\nexport type OllamaModelRecord = FromSchema<typeof OllamaModelRecordSchema>;\n\nexport const OllamaModelConfigSchema = {\n type: \"object\",\n properties: {\n ...ModelConfigSchema.properties,\n ...OllamaModelSchema.properties,\n },\n required: [...ModelConfigSchema.required, ...OllamaModelSchema.required],\n additionalProperties: false,\n} as const satisfies DataPortSchemaObject;\n\nexport type OllamaModelConfig = FromSchema<typeof OllamaModelConfigSchema>;\n",
|
|
8
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { globalServiceRegistry, parentPort, WORKER_SERVER } from \"@workglow/util\";\nimport { OLLAMA_STREAM_TASKS, OLLAMA_TASKS } from \"./common/Ollama_JobRunFns\";\nimport { OllamaProvider } from \"./OllamaProvider\";\n\nexport function OLLAMA_WORKER_JOBRUN_REGISTER() {\n const workerServer = globalServiceRegistry.get(WORKER_SERVER);\n new OllamaProvider(OLLAMA_TASKS, OLLAMA_STREAM_TASKS).registerOnWorkerServer(workerServer);\n parentPort.postMessage({ type: \"ready\" });\n console.log(\"OLLAMA_WORKER_JOBRUN registered\");\n}\n",
|
|
9
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { AiProvider, type AiProviderRunFn, type AiProviderStreamFn } from \"@workglow/ai\";\nimport { OLLAMA } from \"./common/Ollama_Constants\";\nimport type { OllamaModelConfig } from \"./common/Ollama_ModelSchema\";\n\n/**\n * AI provider for Ollama local LLM server.\n *\n * Supports text generation, text embedding, text rewriting, and text summarization\n * via the Ollama API using the `ollama` SDK.\n *\n * Ollama runs locally and does not require an API key -- only a `base_url`\n * (defaults to `http://localhost:11434`).\n *\n * Task run functions are injected via the constructor so that the `ollama` SDK\n * is only imported where actually needed (inline mode, worker server), not on\n * the main thread in worker mode.\n *\n * @example\n * ```typescript\n * // Worker mode (main thread) -- lightweight, no SDK import:\n * await new OllamaProvider().register({\n * mode: \"worker\",\n * worker: new Worker(new URL(\"./worker_ollama.ts\", import.meta.url), { type: \"module\" }),\n * });\n *\n * // Inline mode -- caller provides the tasks:\n * import { OLLAMA_TASKS } from \"@workglow/ai-provider/ollama\";\n * await new OllamaProvider(OLLAMA_TASKS).register({ mode: \"inline\" });\n * ```\n */\nexport class OllamaProvider extends AiProvider<OllamaModelConfig> {\n readonly name = OLLAMA;\n\n readonly taskTypes = [\n \"TextGenerationTask\",\n \"TextEmbeddingTask\",\n \"TextRewriterTask\",\n \"TextSummaryTask\",\n ] as const;\n\n constructor(\n tasks?: Record<string, AiProviderRunFn<any, any, OllamaModelConfig>>,\n streamTasks?: Record<string, AiProviderStreamFn<any, any, OllamaModelConfig>>\n ) {\n super(tasks, streamTasks);\n }\n}\n"
|
|
10
|
+
],
|
|
11
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAMO,IAAM,SAAS;AACf,IAAM,0BAA0B;;ACevC,IAAI;AACJ,eAAe,aAAa,GAAG;AAAA,EAC7B,IAAI,CAAC,MAAM;AAAA,IACT,IAAI;AAAA,MACF,OAAO,MAAa;A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AU,CAAC,YAAY;AAAA,MACvB,sBAAsB;AAAA,IACxB;AAAA,EACF;AAAA,EACA,UAAU,CAAC,YAAY,iBAAiB;AAAA,EACxC,sBAAsB;AACxB;AAEO,IAAM,0BAA0B;AAAA,EACrC,MAAM;AAAA,EACN,YAAY;AAAA,OACP,kBAAkB;AAAA,OAClB,kBAAkB;AAAA,EACvB;AAAA,EACA,UAAU,CAAC,GAAG,kBAAkB,UAAU,GAAG,kBAAkB,QAAQ;AAAA,EACvE,sBAAsB;AACxB;AAIO,IAAM,0BAA0B;AAAA,EACrC,MAAM;AAAA,EACN,YAAY;AAAA,OACP,kBAAkB;AAAA,OAClB,kBAAkB;AAAA,EACvB;AAAA,EACA,UAAU,CAAC,GAAG,kBAAkB,UAAU,GAAG,kBAAkB,QAAQ;AAAA,EACvE,sBAAsB;AACxB;;ACrDA;;;ACAA;AA8BO,MAAM,uBAAuB,WAA8B;AAAA,EACvD,OAAO;AAAA,EAEP,YAAY;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,WAAW,CACT,OACA,aACA;AAAA,IACA,MAAM,OAAO,WAAW;AAAA;AAE5B;;;AD1CO,SAAS,6BAA6B,GAAG;AAAA,EAC9C,MAAM,eAAe,sBAAsB,IAAI,aAAa;AAAA,EAC5D,IAAI,eAAe,cAAc,mBAAmB,EAAE,uBAAuB,YAAY;AAAA,EACzF,WAAW,YAAY,EAAE,MAAM,QAAQ,CAAC;AAAA,EACxC,QAAQ,IAAI,iCAAiC;AAAA;",
|
|
12
|
+
"debugId": "75DCC231FAFD3E6364756E2164756E21",
|
|
13
|
+
"names": []
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAI_Worker.d.ts","sourceRoot":"","sources":["../../src/provider-openai/OpenAI_Worker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,wBAAgB,6BAA6B,SAK5C"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { AiProvider, type AiProviderRunFn, type AiProviderStreamFn } from "@workglow/ai";
|
|
7
|
+
import type { OpenAiModelConfig } from "./common/OpenAI_ModelSchema";
|
|
8
|
+
/**
|
|
9
|
+
* AI provider for OpenAI cloud models.
|
|
10
|
+
*
|
|
11
|
+
* Supports text generation, text embedding, text rewriting, and text summarization
|
|
12
|
+
* via the OpenAI API using the `openai` SDK.
|
|
13
|
+
*
|
|
14
|
+
* Task run functions are injected via the constructor so that the `openai` SDK
|
|
15
|
+
* is only imported where actually needed (inline mode, worker server), not on
|
|
16
|
+
* the main thread in worker mode.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Worker mode (main thread) -- lightweight, no SDK import:
|
|
21
|
+
* await new OpenAiProvider().register({
|
|
22
|
+
* mode: "worker",
|
|
23
|
+
* worker: new Worker(new URL("./worker_openai.ts", import.meta.url), { type: "module" }),
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Inline mode -- caller provides the tasks:
|
|
27
|
+
* import { OPENAI_TASKS } from "@workglow/ai-provider/openai";
|
|
28
|
+
* await new OpenAiProvider(OPENAI_TASKS).register({ mode: "inline" });
|
|
29
|
+
*
|
|
30
|
+
* // Worker side -- caller provides the tasks:
|
|
31
|
+
* import { OPENAI_TASKS } from "@workglow/ai-provider/openai";
|
|
32
|
+
* new OpenAiProvider(OPENAI_TASKS).registerOnWorkerServer(workerServer);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class OpenAiProvider extends AiProvider<OpenAiModelConfig> {
|
|
36
|
+
readonly name = "OPENAI";
|
|
37
|
+
readonly taskTypes: readonly ["TextGenerationTask", "TextEmbeddingTask", "TextRewriterTask", "TextSummaryTask"];
|
|
38
|
+
constructor(tasks?: Record<string, AiProviderRunFn<any, any, OpenAiModelConfig>>, streamTasks?: Record<string, AiProviderStreamFn<any, any, OpenAiModelConfig>>);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=OpenAiProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAiProvider.d.ts","sourceRoot":"","sources":["../../src/provider-openai/OpenAiProvider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEzF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,cAAe,SAAQ,UAAU,CAAC,iBAAiB,CAAC;IAC/D,QAAQ,CAAC,IAAI,YAAU;IAEvB,QAAQ,CAAC,SAAS,8FAKP;gBAGT,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC,EACpE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC;CAIhF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAI_Constants.d.ts","sourceRoot":"","sources":["../../../src/provider-openai/common/OpenAI_Constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,MAAM,WAAW,CAAC"}
|