@workglow/ai 0.0.57 → 0.0.59
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 +44 -9
- package/dist/browser.js +89 -104
- package/dist/browser.js.map +13 -13
- package/dist/bun.js +89 -130
- package/dist/bun.js.map +13 -15
- package/dist/common.d.ts +2 -1
- package/dist/common.d.ts.map +1 -1
- package/dist/model/{storage/InMemoryModelRepository.d.ts → InMemoryModelRepository.d.ts} +2 -2
- package/dist/model/InMemoryModelRepository.d.ts.map +1 -0
- package/dist/model/ModelRegistry.d.ts +12 -0
- package/dist/model/ModelRegistry.d.ts.map +1 -1
- package/dist/model/ModelRepository.d.ts +59 -60
- package/dist/model/ModelRepository.d.ts.map +1 -1
- package/dist/model/ModelSchema.d.ts +42 -0
- package/dist/model/ModelSchema.d.ts.map +1 -0
- package/dist/node.js +89 -130
- package/dist/node.js.map +13 -15
- package/dist/provider/AiProviderRegistry.d.ts +15 -3
- package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
- package/dist/task/DownloadModelTask.d.ts +179 -19
- package/dist/task/DownloadModelTask.d.ts.map +1 -1
- package/dist/task/TextEmbeddingTask.d.ts +77 -9
- package/dist/task/TextEmbeddingTask.d.ts.map +1 -1
- package/dist/task/TextGenerationTask.d.ts +77 -9
- package/dist/task/TextGenerationTask.d.ts.map +1 -1
- package/dist/task/TextQuestionAnswerTask.d.ts +77 -9
- package/dist/task/TextQuestionAnswerTask.d.ts.map +1 -1
- package/dist/task/TextRewriterTask.d.ts +77 -9
- package/dist/task/TextRewriterTask.d.ts.map +1 -1
- package/dist/task/TextSummaryTask.d.ts +77 -9
- package/dist/task/TextSummaryTask.d.ts.map +1 -1
- package/dist/task/TextTranslationTask.d.ts +77 -9
- package/dist/task/TextTranslationTask.d.ts.map +1 -1
- package/dist/task/base/AiTask.d.ts +15 -6
- package/dist/task/base/AiTask.d.ts.map +1 -1
- package/dist/task/base/AiTaskSchemas.d.ts +43 -2
- package/dist/task/base/AiTaskSchemas.d.ts.map +1 -1
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -12
- package/dist/model/Model.d.ts +0 -26
- package/dist/model/Model.d.ts.map +0 -1
- package/dist/model/storage/InMemoryModelRepository.d.ts.map +0 -1
- package/dist/model/storage/IndexedDbModelRepository.d.ts +0 -18
- package/dist/model/storage/IndexedDbModelRepository.d.ts.map +0 -1
- package/dist/model/storage/PostgresModelRepository.d.ts +0 -19
- package/dist/model/storage/PostgresModelRepository.d.ts.map +0 -1
- package/dist/model/storage/SqliteModelRepository.d.ts +0 -18
- package/dist/model/storage/SqliteModelRepository.d.ts.map +0 -1
|
@@ -5,51 +5,18 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { type TabularRepository } from "@workglow/storage";
|
|
7
7
|
import { EventEmitter, EventParameters } from "@workglow/util";
|
|
8
|
-
import {
|
|
8
|
+
import { ModelPrimaryKeyNames, ModelRecord, ModelSchema } from "./ModelSchema";
|
|
9
9
|
/**
|
|
10
10
|
* Events that can be emitted by the ModelRepository
|
|
11
11
|
*/
|
|
12
12
|
export type ModelEventListeners = {
|
|
13
|
-
model_added: (model:
|
|
14
|
-
model_removed: (model:
|
|
15
|
-
|
|
16
|
-
task_model_disconnected: (task: string, model: string) => void;
|
|
17
|
-
model_updated: (model: Model) => void;
|
|
13
|
+
model_added: (model: ModelRecord) => void;
|
|
14
|
+
model_removed: (model: ModelRecord) => void;
|
|
15
|
+
model_updated: (model: ModelRecord) => void;
|
|
18
16
|
};
|
|
19
17
|
export type ModelEvents = keyof ModelEventListeners;
|
|
20
18
|
export type ModelEventListener<Event extends ModelEvents> = ModelEventListeners[Event];
|
|
21
19
|
export type ModelEventParameters<Event extends ModelEvents> = EventParameters<ModelEventListeners, Event>;
|
|
22
|
-
export declare const ModelSchema: {
|
|
23
|
-
readonly type: "object";
|
|
24
|
-
readonly properties: {
|
|
25
|
-
readonly name: {
|
|
26
|
-
readonly type: "string";
|
|
27
|
-
};
|
|
28
|
-
readonly details: {
|
|
29
|
-
readonly type: "string";
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
readonly required: readonly ["name", "details"];
|
|
33
|
-
readonly additionalProperties: false;
|
|
34
|
-
};
|
|
35
|
-
export declare const ModelPrimaryKeyNames: readonly ["name"];
|
|
36
|
-
/**
|
|
37
|
-
* Represents the structure for mapping tasks to models
|
|
38
|
-
*/
|
|
39
|
-
export declare const Task2ModelSchema: {
|
|
40
|
-
readonly type: "object";
|
|
41
|
-
readonly properties: {
|
|
42
|
-
readonly task: {
|
|
43
|
-
readonly type: "string";
|
|
44
|
-
};
|
|
45
|
-
readonly model: {
|
|
46
|
-
readonly type: "string";
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
readonly required: readonly ["task", "model"];
|
|
50
|
-
readonly additionalProperties: false;
|
|
51
|
-
};
|
|
52
|
-
export declare const Task2ModelPrimaryKeyNames: readonly ["task", "model"];
|
|
53
20
|
/**
|
|
54
21
|
* Abstract base class for managing AI models and their relationships with tasks.
|
|
55
22
|
* Provides functionality for storing, retrieving, and managing the lifecycle of models
|
|
@@ -62,10 +29,6 @@ export declare abstract class ModelRepository {
|
|
|
62
29
|
* Repository for storing and managing Model instances
|
|
63
30
|
*/
|
|
64
31
|
abstract modelTabularRepository: TabularRepository<typeof ModelSchema, typeof ModelPrimaryKeyNames>;
|
|
65
|
-
/**
|
|
66
|
-
* Repository for managing relationships between tasks and models
|
|
67
|
-
*/
|
|
68
|
-
abstract task2ModelTabularRepository: TabularRepository<typeof Task2ModelSchema, typeof Task2ModelPrimaryKeyNames>;
|
|
69
32
|
/** Event emitter for repository events */
|
|
70
33
|
protected events: EventEmitter<ModelEventListeners>;
|
|
71
34
|
/**
|
|
@@ -96,21 +59,43 @@ export declare abstract class ModelRepository {
|
|
|
96
59
|
* Adds a new model to the repository
|
|
97
60
|
* @param model - The model instance to add
|
|
98
61
|
*/
|
|
99
|
-
addModel(model:
|
|
62
|
+
addModel(model: ModelRecord): Promise<{
|
|
63
|
+
title: string;
|
|
64
|
+
description: string;
|
|
65
|
+
model_id: string;
|
|
66
|
+
tasks: string[];
|
|
67
|
+
provider: string;
|
|
68
|
+
providerConfig: {
|
|
69
|
+
[x: string]: unknown;
|
|
70
|
+
};
|
|
71
|
+
metadata: {
|
|
72
|
+
[x: string]: unknown;
|
|
73
|
+
};
|
|
74
|
+
}>;
|
|
100
75
|
/**
|
|
101
76
|
* Finds all models associated with a specific task
|
|
102
77
|
* @param task - The task identifier to search for
|
|
103
78
|
* @returns Promise resolving to an array of associated models, or undefined if none found
|
|
104
79
|
*/
|
|
105
|
-
findModelsByTask(task: string): Promise<
|
|
106
|
-
|
|
107
|
-
|
|
80
|
+
findModelsByTask(task: string): Promise<{
|
|
81
|
+
title: string;
|
|
82
|
+
description: string;
|
|
83
|
+
model_id: string;
|
|
84
|
+
tasks: string[];
|
|
85
|
+
provider: string;
|
|
86
|
+
providerConfig: {
|
|
87
|
+
[x: string]: unknown;
|
|
88
|
+
};
|
|
89
|
+
metadata: {
|
|
90
|
+
[x: string]: unknown;
|
|
91
|
+
};
|
|
92
|
+
}[] | undefined>;
|
|
108
93
|
/**
|
|
109
94
|
* Finds all tasks associated with a specific model
|
|
110
95
|
* @param model - The model identifier to search for
|
|
111
96
|
* @returns Promise resolving to an array of associated tasks, or undefined if none found
|
|
112
97
|
*/
|
|
113
|
-
findTasksByModel(
|
|
98
|
+
findTasksByModel(model_id: string): Promise<string[] | undefined>;
|
|
114
99
|
/**
|
|
115
100
|
* Enumerates all tasks in the repository
|
|
116
101
|
* @returns Promise resolving to an array of task identifiers
|
|
@@ -120,27 +105,41 @@ export declare abstract class ModelRepository {
|
|
|
120
105
|
* Enumerates all models in the repository
|
|
121
106
|
* @returns Promise resolving to an array of model instances
|
|
122
107
|
*/
|
|
123
|
-
enumerateAllModels(): Promise<
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
108
|
+
enumerateAllModels(): Promise<{
|
|
109
|
+
title: string;
|
|
110
|
+
description: string;
|
|
111
|
+
model_id: string;
|
|
112
|
+
tasks: string[];
|
|
113
|
+
provider: string;
|
|
114
|
+
providerConfig: {
|
|
115
|
+
[x: string]: unknown;
|
|
116
|
+
};
|
|
117
|
+
metadata: {
|
|
118
|
+
[x: string]: unknown;
|
|
119
|
+
};
|
|
120
|
+
}[] | undefined>;
|
|
130
121
|
/**
|
|
131
|
-
* Retrieves a model by its
|
|
132
|
-
* @param
|
|
122
|
+
* Retrieves a model by its identifier
|
|
123
|
+
* @param modelId - The model_id of the model to find
|
|
133
124
|
* @returns Promise resolving to the found model or undefined if not found
|
|
134
125
|
*/
|
|
135
|
-
findByName(
|
|
126
|
+
findByName(model_id: string): Promise<{
|
|
127
|
+
title: string;
|
|
128
|
+
description: string;
|
|
129
|
+
model_id: string;
|
|
130
|
+
tasks: string[];
|
|
131
|
+
provider: string;
|
|
132
|
+
providerConfig: {
|
|
133
|
+
[x: string]: unknown;
|
|
134
|
+
};
|
|
135
|
+
metadata: {
|
|
136
|
+
[x: string]: unknown;
|
|
137
|
+
};
|
|
138
|
+
} | undefined>;
|
|
136
139
|
/**
|
|
137
140
|
* Gets the total number of models in the repository
|
|
138
141
|
* @returns Promise resolving to the number of stored models
|
|
139
142
|
*/
|
|
140
143
|
size(): Promise<number>;
|
|
141
|
-
/**
|
|
142
|
-
* Clears all models from the repository
|
|
143
|
-
*/
|
|
144
|
-
clear(): Promise<void>;
|
|
145
144
|
}
|
|
146
145
|
//# sourceMappingURL=ModelRepository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelRepository.d.ts","sourceRoot":"","sources":["../../src/model/ModelRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,
|
|
1
|
+
{"version":3,"file":"ModelRepository.d.ts","sourceRoot":"","sources":["../../src/model/ModelRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE/E;;GAEG;AAEH,MAAM,MAAM,mBAAmB,GAAG;IAChC,WAAW,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC1C,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC5C,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC;AAEpD,MAAM,MAAM,kBAAkB,CAAC,KAAK,SAAS,WAAW,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAEvF,MAAM,MAAM,oBAAoB,CAAC,KAAK,SAAS,WAAW,IAAI,eAAe,CAC3E,mBAAmB,EACnB,KAAK,CACN,CAAC;AAEF;;;;GAIG;AACH,8BAAsB,eAAe;IACnC,iCAAiC;IAC1B,IAAI,SAAqB;IAEhC;;OAEG;IACH,QAAQ,CAAC,sBAAsB,EAAE,iBAAiB,CAChD,OAAO,WAAW,EAClB,OAAO,oBAAoB,CAC5B,CAAC;IAEF,0CAA0C;IAC1C,SAAS,CAAC,MAAM,oCAA2C;IAE3D;;;;OAIG;IACH,EAAE,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,kBAAkB,CAAC,KAAK,CAAC;IAIxE;;;;OAIG;IACH,GAAG,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,kBAAkB,CAAC,KAAK,CAAC;IAIzE;;;;OAIG;IACH,IAAI,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,kBAAkB,CAAC,KAAK,CAAC;IAI1E;;;;OAIG;IACH,MAAM,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK;IAI7C;;;OAGG;IACG,QAAQ,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;IAMjC;;;;OAIG;IACG,gBAAgB,CAAC,IAAI,EAAE,MAAM;;;;;;;;;;;;;IASnC;;;;OAIG;IACG,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAOvC;;;OAGG;IACG,iBAAiB;IAcvB;;;OAGG;IACG,kBAAkB;;;;;;;;;;;;;IAMxB;;;;OAIG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;IAMjC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;CAG9B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 ModelSchema: {
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly model_id: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
};
|
|
13
|
+
readonly tasks: {
|
|
14
|
+
readonly type: "array";
|
|
15
|
+
readonly items: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
readonly title: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
};
|
|
22
|
+
readonly description: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
};
|
|
25
|
+
readonly provider: {
|
|
26
|
+
readonly type: "string";
|
|
27
|
+
};
|
|
28
|
+
readonly providerConfig: {
|
|
29
|
+
readonly type: "object";
|
|
30
|
+
readonly default: {};
|
|
31
|
+
};
|
|
32
|
+
readonly metadata: {
|
|
33
|
+
readonly type: "object";
|
|
34
|
+
readonly default: {};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
readonly required: readonly ["model_id", "tasks", "provider", "title", "description", "providerConfig", "metadata"];
|
|
38
|
+
readonly additionalProperties: false;
|
|
39
|
+
};
|
|
40
|
+
export type ModelRecord = FromSchema<typeof ModelSchema>;
|
|
41
|
+
export declare const ModelPrimaryKeyNames: readonly ["model_id"];
|
|
42
|
+
//# sourceMappingURL=ModelSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelSchema.d.ts","sourceRoot":"","sources":["../../src/model/ModelSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAwB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAElE,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAaiB,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AACzD,eAAO,MAAM,oBAAoB,uBAAwB,CAAC"}
|
package/dist/node.js
CHANGED
|
@@ -6,31 +6,14 @@ import {
|
|
|
6
6
|
PermanentJobError
|
|
7
7
|
} from "@workglow/job-queue";
|
|
8
8
|
|
|
9
|
-
// src/model/
|
|
9
|
+
// src/model/ModelRegistry.ts
|
|
10
|
+
import { createServiceToken, globalServiceRegistry } from "@workglow/util";
|
|
11
|
+
|
|
12
|
+
// src/model/InMemoryModelRepository.ts
|
|
10
13
|
import { InMemoryTabularRepository } from "@workglow/storage";
|
|
11
14
|
|
|
12
15
|
// src/model/ModelRepository.ts
|
|
13
16
|
import { EventEmitter } from "@workglow/util";
|
|
14
|
-
var ModelSchema = {
|
|
15
|
-
type: "object",
|
|
16
|
-
properties: {
|
|
17
|
-
name: { type: "string" },
|
|
18
|
-
details: { type: "string" }
|
|
19
|
-
},
|
|
20
|
-
required: ["name", "details"],
|
|
21
|
-
additionalProperties: false
|
|
22
|
-
};
|
|
23
|
-
var ModelPrimaryKeyNames = ["name"];
|
|
24
|
-
var Task2ModelSchema = {
|
|
25
|
-
type: "object",
|
|
26
|
-
properties: {
|
|
27
|
-
task: { type: "string" },
|
|
28
|
-
model: { type: "string" }
|
|
29
|
-
},
|
|
30
|
-
required: ["task", "model"],
|
|
31
|
-
additionalProperties: false
|
|
32
|
-
};
|
|
33
|
-
var Task2ModelPrimaryKeyNames = ["task", "model"];
|
|
34
17
|
|
|
35
18
|
class ModelRepository {
|
|
36
19
|
type = "ModelRepository";
|
|
@@ -48,101 +31,101 @@ class ModelRepository {
|
|
|
48
31
|
return this.events.waitOn(name);
|
|
49
32
|
}
|
|
50
33
|
async addModel(model) {
|
|
51
|
-
await this.modelTabularRepository.put(
|
|
52
|
-
this.models.set(model.name, model);
|
|
34
|
+
await this.modelTabularRepository.put(model);
|
|
53
35
|
this.events.emit("model_added", model);
|
|
54
36
|
return model;
|
|
55
37
|
}
|
|
56
38
|
async findModelsByTask(task) {
|
|
57
39
|
if (typeof task != "string")
|
|
58
40
|
return;
|
|
59
|
-
const
|
|
60
|
-
if (!
|
|
41
|
+
const allModels = await this.modelTabularRepository.getAll();
|
|
42
|
+
if (!allModels || allModels.length === 0)
|
|
43
|
+
return;
|
|
44
|
+
const models = allModels.filter((model) => model.tasks?.includes(task));
|
|
45
|
+
if (models.length === 0)
|
|
61
46
|
return;
|
|
62
|
-
const models = [];
|
|
63
|
-
for (const junction of junctions) {
|
|
64
|
-
const model = await this.modelTabularRepository.get({ name: junction.model });
|
|
65
|
-
if (model)
|
|
66
|
-
models.push(JSON.parse(model.details));
|
|
67
|
-
}
|
|
68
|
-
models.forEach((m) => this.models.set(m.name, m));
|
|
69
|
-
this.taskModels.set(task, models);
|
|
70
47
|
return models;
|
|
71
48
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
async findTasksByModel(model) {
|
|
75
|
-
if (typeof model != "string")
|
|
49
|
+
async findTasksByModel(model_id) {
|
|
50
|
+
if (typeof model_id != "string")
|
|
76
51
|
return;
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
52
|
+
const modelRecord = await this.modelTabularRepository.get({ model_id });
|
|
53
|
+
if (!modelRecord)
|
|
79
54
|
return;
|
|
80
|
-
return
|
|
55
|
+
return modelRecord.tasks && modelRecord.tasks.length > 0 ? modelRecord.tasks : undefined;
|
|
81
56
|
}
|
|
82
57
|
async enumerateAllTasks() {
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
58
|
+
const allModels = await this.modelTabularRepository.getAll();
|
|
59
|
+
if (!allModels || allModels.length === 0)
|
|
85
60
|
return;
|
|
86
|
-
const uniqueTasks =
|
|
87
|
-
|
|
61
|
+
const uniqueTasks = new Set;
|
|
62
|
+
for (const model of allModels) {
|
|
63
|
+
if (model.tasks) {
|
|
64
|
+
for (const task of model.tasks) {
|
|
65
|
+
uniqueTasks.add(task);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return uniqueTasks.size > 0 ? Array.from(uniqueTasks) : undefined;
|
|
88
70
|
}
|
|
89
71
|
async enumerateAllModels() {
|
|
90
72
|
const models = await this.modelTabularRepository.getAll();
|
|
91
73
|
if (!models || models.length === 0)
|
|
92
74
|
return;
|
|
93
|
-
|
|
94
|
-
parsedModels.forEach((m) => this.models.set(m.name, m));
|
|
95
|
-
return parsedModels;
|
|
96
|
-
}
|
|
97
|
-
async connectTaskToModel(task, model) {
|
|
98
|
-
await this.task2ModelTabularRepository.put({ task, model });
|
|
99
|
-
this.events.emit("task_model_connected", task, model);
|
|
75
|
+
return models;
|
|
100
76
|
}
|
|
101
|
-
async findByName(
|
|
102
|
-
if (typeof
|
|
77
|
+
async findByName(model_id) {
|
|
78
|
+
if (typeof model_id != "string")
|
|
103
79
|
return;
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
return;
|
|
107
|
-
const model = JSON.parse(modelstr.details);
|
|
108
|
-
this.models.set(model.name, model);
|
|
109
|
-
return model;
|
|
80
|
+
const model = await this.modelTabularRepository.get({ model_id });
|
|
81
|
+
return model ?? undefined;
|
|
110
82
|
}
|
|
111
83
|
async size() {
|
|
112
84
|
return await this.modelTabularRepository.size();
|
|
113
85
|
}
|
|
114
|
-
async clear() {
|
|
115
|
-
await this.modelTabularRepository.deleteAll();
|
|
116
|
-
}
|
|
117
86
|
}
|
|
118
87
|
|
|
119
|
-
// src/model/
|
|
88
|
+
// src/model/ModelSchema.ts
|
|
89
|
+
var ModelSchema = {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: {
|
|
92
|
+
model_id: { type: "string" },
|
|
93
|
+
tasks: { type: "array", items: { type: "string" } },
|
|
94
|
+
title: { type: "string" },
|
|
95
|
+
description: { type: "string" },
|
|
96
|
+
provider: { type: "string" },
|
|
97
|
+
providerConfig: { type: "object", default: {} },
|
|
98
|
+
metadata: { type: "object", default: {} }
|
|
99
|
+
},
|
|
100
|
+
required: ["model_id", "tasks", "provider", "title", "description", "providerConfig", "metadata"],
|
|
101
|
+
additionalProperties: false
|
|
102
|
+
};
|
|
103
|
+
var ModelPrimaryKeyNames = ["model_id"];
|
|
104
|
+
|
|
105
|
+
// src/model/InMemoryModelRepository.ts
|
|
120
106
|
class InMemoryModelRepository extends ModelRepository {
|
|
121
107
|
modelTabularRepository;
|
|
122
|
-
task2ModelTabularRepository;
|
|
123
108
|
type = "InMemoryModelRepository";
|
|
124
109
|
constructor() {
|
|
125
110
|
super();
|
|
126
111
|
this.modelTabularRepository = new InMemoryTabularRepository(ModelSchema, ModelPrimaryKeyNames);
|
|
127
|
-
this.task2ModelTabularRepository = new InMemoryTabularRepository(Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
128
112
|
}
|
|
129
113
|
}
|
|
130
114
|
|
|
131
115
|
// src/model/ModelRegistry.ts
|
|
132
|
-
|
|
116
|
+
var MODEL_REPOSITORY = createServiceToken("model.repository");
|
|
117
|
+
if (!globalServiceRegistry.has(MODEL_REPOSITORY)) {
|
|
118
|
+
globalServiceRegistry.register(MODEL_REPOSITORY, () => new InMemoryModelRepository, true);
|
|
133
119
|
}
|
|
134
|
-
var modelRegistry;
|
|
135
120
|
function getGlobalModelRepository() {
|
|
136
|
-
|
|
137
|
-
modelRegistry = new FallbackModelRegistry;
|
|
138
|
-
return modelRegistry;
|
|
121
|
+
return globalServiceRegistry.get(MODEL_REPOSITORY);
|
|
139
122
|
}
|
|
140
123
|
function setGlobalModelRepository(pr) {
|
|
141
|
-
|
|
124
|
+
globalServiceRegistry.registerInstance(MODEL_REPOSITORY, pr);
|
|
142
125
|
}
|
|
143
126
|
|
|
144
127
|
// src/provider/AiProviderRegistry.ts
|
|
145
|
-
import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util";
|
|
128
|
+
import { globalServiceRegistry as globalServiceRegistry2, WORKER_MANAGER } from "@workglow/util";
|
|
146
129
|
|
|
147
130
|
class AiProviderRegistry {
|
|
148
131
|
runFnRegistry = new Map;
|
|
@@ -154,7 +137,7 @@ class AiProviderRegistry {
|
|
|
154
137
|
}
|
|
155
138
|
registerAsWorkerRunFn(modelProvider, taskType) {
|
|
156
139
|
const workerFn = async (input, model, update_progress, signal) => {
|
|
157
|
-
const workerManager =
|
|
140
|
+
const workerManager = globalServiceRegistry2.get(WORKER_MANAGER);
|
|
158
141
|
const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model], {
|
|
159
142
|
signal,
|
|
160
143
|
onProgress: update_progress
|
|
@@ -475,25 +458,29 @@ class AiTask extends JobQueueTask {
|
|
|
475
458
|
config.name ||= `${new.target.type || new.target.name}${input.model ? " with model " + input.model : ""}`;
|
|
476
459
|
super(input, config);
|
|
477
460
|
}
|
|
478
|
-
async
|
|
461
|
+
async getJobInput(input) {
|
|
479
462
|
if (typeof input.model !== "string") {
|
|
480
463
|
console.error("AiTask: Model is not a string", input);
|
|
481
464
|
throw new TaskConfigurationError("AiTask: Model is not a string, only create job for single model tasks");
|
|
482
465
|
}
|
|
483
466
|
const runtype = this.constructor.runtype ?? this.constructor.type;
|
|
484
467
|
const model = await this.getModelForInput(input);
|
|
485
|
-
|
|
486
|
-
|
|
468
|
+
return {
|
|
469
|
+
taskType: runtype,
|
|
470
|
+
aiProvider: model.provider,
|
|
471
|
+
taskInput: input
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
async createJob(input, queueName) {
|
|
475
|
+
const jobInput = await this.getJobInput(input);
|
|
476
|
+
const resolvedQueueName = queueName ?? await this.getDefaultQueueName(input);
|
|
477
|
+
if (!resolvedQueueName) {
|
|
487
478
|
throw new TaskConfigurationError("JobQueueTask: Unable to determine queue for AI provider");
|
|
488
479
|
}
|
|
489
480
|
const job = new AiJob({
|
|
490
|
-
queueName,
|
|
481
|
+
queueName: resolvedQueueName,
|
|
491
482
|
jobRunId: this.config.runnerId,
|
|
492
|
-
input:
|
|
493
|
-
taskType: runtype,
|
|
494
|
-
aiProvider: model.provider,
|
|
495
|
-
taskInput: input
|
|
496
|
-
}
|
|
483
|
+
input: jobInput
|
|
497
484
|
});
|
|
498
485
|
return job;
|
|
499
486
|
}
|
|
@@ -532,7 +519,7 @@ class AiTask extends JobQueueTask {
|
|
|
532
519
|
for (const [key, propSchema] of modelTaskProperties) {
|
|
533
520
|
let requestedModels = Array.isArray(input[key]) ? input[key] : [input[key]];
|
|
534
521
|
for (const model of requestedModels) {
|
|
535
|
-
const foundModel = taskModels?.find((m) => m.
|
|
522
|
+
const foundModel = taskModels?.find((m) => m.model_id === model);
|
|
536
523
|
if (!foundModel) {
|
|
537
524
|
throw new TaskConfigurationError(`AiTask: Missing model for '${key}' named '${model}' for task '${this.type}'`);
|
|
538
525
|
}
|
|
@@ -566,7 +553,7 @@ class AiTask extends JobQueueTask {
|
|
|
566
553
|
const taskModels = await getGlobalModelRepository().findModelsByTask(this.type);
|
|
567
554
|
for (const [key, propSchema] of modelTaskProperties) {
|
|
568
555
|
let requestedModels = Array.isArray(input[key]) ? input[key] : [input[key]];
|
|
569
|
-
let usingModels = requestedModels.filter((model) => taskModels?.find((m) => m.
|
|
556
|
+
let usingModels = requestedModels.filter((model) => taskModels?.find((m) => m.model_id === model));
|
|
570
557
|
usingModels = usingModels.length > 1 ? usingModels : usingModels[0];
|
|
571
558
|
input[key] = usingModels;
|
|
572
559
|
}
|
|
@@ -663,7 +650,7 @@ var TypeLanguage = (annotations = {}) => ({
|
|
|
663
650
|
minLength: 2,
|
|
664
651
|
...annotations
|
|
665
652
|
});
|
|
666
|
-
function
|
|
653
|
+
function TypeModelAsString(semantic = "model", options = {}) {
|
|
667
654
|
if (semantic !== "model" && !semantic.startsWith("model:")) {
|
|
668
655
|
throw new Error("Invalid semantic value");
|
|
669
656
|
}
|
|
@@ -676,6 +663,11 @@ function TypeModel(semantic = "model", options = {}) {
|
|
|
676
663
|
type: "string"
|
|
677
664
|
};
|
|
678
665
|
}
|
|
666
|
+
function TypeModel(semantic = "model", options = {}) {
|
|
667
|
+
return {
|
|
668
|
+
oneOf: [TypeModelAsString(semantic, options), ModelSchema]
|
|
669
|
+
};
|
|
670
|
+
}
|
|
679
671
|
var TypeReplicateArray = (type, annotations = {}) => ({
|
|
680
672
|
oneOf: [type, { type: "array", items: type }],
|
|
681
673
|
title: type.title,
|
|
@@ -1117,11 +1109,15 @@ var TextTranslationInputSchema = {
|
|
|
1117
1109
|
}),
|
|
1118
1110
|
source_lang: TypeReplicateArray(TypeLanguage({
|
|
1119
1111
|
title: "Source Language",
|
|
1120
|
-
description: "The source language"
|
|
1112
|
+
description: "The source language",
|
|
1113
|
+
minLength: 2,
|
|
1114
|
+
maxLength: 2
|
|
1121
1115
|
})),
|
|
1122
1116
|
target_lang: TypeReplicateArray(TypeLanguage({
|
|
1123
1117
|
title: "Target Language",
|
|
1124
|
-
description: "The target language"
|
|
1118
|
+
description: "The target language",
|
|
1119
|
+
minLength: 2,
|
|
1120
|
+
maxLength: 2
|
|
1125
1121
|
})),
|
|
1126
1122
|
model: modelSchema7
|
|
1127
1123
|
},
|
|
@@ -1138,7 +1134,9 @@ var TextTranslationOutputSchema = {
|
|
|
1138
1134
|
},
|
|
1139
1135
|
target_lang: TypeLanguage({
|
|
1140
1136
|
title: "Output Language",
|
|
1141
|
-
description: "The output language"
|
|
1137
|
+
description: "The output language",
|
|
1138
|
+
minLength: 2,
|
|
1139
|
+
maxLength: 2
|
|
1142
1140
|
})
|
|
1143
1141
|
},
|
|
1144
1142
|
required: ["text", "target_lang"],
|
|
@@ -1293,42 +1291,6 @@ function normalize(vector) {
|
|
|
1293
1291
|
}
|
|
1294
1292
|
return new Float32Array(normalized);
|
|
1295
1293
|
}
|
|
1296
|
-
// src/model/storage/IndexedDbModelRepository.ts
|
|
1297
|
-
import { IndexedDbTabularRepository } from "@workglow/storage";
|
|
1298
|
-
class IndexedDbModelRepository extends ModelRepository {
|
|
1299
|
-
modelTabularRepository;
|
|
1300
|
-
task2ModelTabularRepository;
|
|
1301
|
-
type = "IndexedDbModelRepository";
|
|
1302
|
-
constructor(tableModels = "models", tableTask2Models = "task2models") {
|
|
1303
|
-
super();
|
|
1304
|
-
this.modelTabularRepository = new IndexedDbTabularRepository(tableModels, ModelSchema, ModelPrimaryKeyNames);
|
|
1305
|
-
this.task2ModelTabularRepository = new IndexedDbTabularRepository(tableTask2Models, Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
// src/model/storage/PostgresModelRepository.ts
|
|
1309
|
-
import { PostgresTabularRepository } from "@workglow/storage";
|
|
1310
|
-
class PostgresModelRepository extends ModelRepository {
|
|
1311
|
-
type = "PostgresModelRepository";
|
|
1312
|
-
modelTabularRepository;
|
|
1313
|
-
task2ModelTabularRepository;
|
|
1314
|
-
constructor(db, tableModels = "aimodel", tableTask2Models = "aitask2aimodel") {
|
|
1315
|
-
super();
|
|
1316
|
-
this.modelTabularRepository = new PostgresTabularRepository(db, tableModels, ModelSchema, ModelPrimaryKeyNames);
|
|
1317
|
-
this.task2ModelTabularRepository = new PostgresTabularRepository(db, tableTask2Models, Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
// src/model/storage/SqliteModelRepository.ts
|
|
1321
|
-
import { SqliteTabularRepository } from "@workglow/storage";
|
|
1322
|
-
class SqliteModelRepository extends ModelRepository {
|
|
1323
|
-
type = "SqliteModelRepository";
|
|
1324
|
-
modelTabularRepository;
|
|
1325
|
-
task2ModelTabularRepository;
|
|
1326
|
-
constructor(dbOrPath, tableModels = "aimodel", tableTask2Models = "aitask2aimodel") {
|
|
1327
|
-
super();
|
|
1328
|
-
this.modelTabularRepository = new SqliteTabularRepository(dbOrPath, tableModels, ModelSchema, ModelPrimaryKeyNames);
|
|
1329
|
-
this.task2ModelTabularRepository = new SqliteTabularRepository(dbOrPath, tableTask2Models, Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
1294
|
export {
|
|
1333
1295
|
setGlobalModelRepository,
|
|
1334
1296
|
setAiProviderRegistry,
|
|
@@ -1340,6 +1302,7 @@ export {
|
|
|
1340
1302
|
VectorSimilarityTask,
|
|
1341
1303
|
TypedArraySchema,
|
|
1342
1304
|
TypeReplicateArray,
|
|
1305
|
+
TypeModelAsString,
|
|
1343
1306
|
TypeModel,
|
|
1344
1307
|
TypeLanguage,
|
|
1345
1308
|
TextTranslationTask,
|
|
@@ -1367,17 +1330,13 @@ export {
|
|
|
1367
1330
|
TextEmbeddingOutputSchema,
|
|
1368
1331
|
TextEmbeddingInputSchema,
|
|
1369
1332
|
TextEmbedding,
|
|
1370
|
-
Task2ModelSchema,
|
|
1371
|
-
Task2ModelPrimaryKeyNames,
|
|
1372
1333
|
TableFragment,
|
|
1373
|
-
SqliteModelRepository,
|
|
1374
1334
|
SimilarityFn,
|
|
1375
1335
|
Similarity,
|
|
1376
|
-
PostgresModelRepository,
|
|
1377
1336
|
ModelSchema,
|
|
1378
1337
|
ModelRepository,
|
|
1379
1338
|
ModelPrimaryKeyNames,
|
|
1380
|
-
|
|
1339
|
+
MODEL_REPOSITORY,
|
|
1381
1340
|
InMemoryModelRepository,
|
|
1382
1341
|
ImageFragment,
|
|
1383
1342
|
DownloadModelTask,
|
|
@@ -1394,4 +1353,4 @@ export {
|
|
|
1394
1353
|
AiJob
|
|
1395
1354
|
};
|
|
1396
1355
|
|
|
1397
|
-
//# debugId=
|
|
1356
|
+
//# debugId=1604FA9BA2C9A8BB64756E2164756E21
|