@hazeljs/ml 0.2.0-beta.37

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 (44) hide show
  1. package/LICENSE +192 -0
  2. package/dist/decorators/index.d.ts +4 -0
  3. package/dist/decorators/index.d.ts.map +1 -0
  4. package/dist/decorators/index.js +15 -0
  5. package/dist/decorators/model.decorator.d.ts +26 -0
  6. package/dist/decorators/model.decorator.d.ts.map +1 -0
  7. package/dist/decorators/model.decorator.js +48 -0
  8. package/dist/decorators/predict.decorator.d.ts +20 -0
  9. package/dist/decorators/predict.decorator.d.ts.map +1 -0
  10. package/dist/decorators/predict.decorator.js +40 -0
  11. package/dist/decorators/train.decorator.d.ts +21 -0
  12. package/dist/decorators/train.decorator.d.ts.map +1 -0
  13. package/dist/decorators/train.decorator.js +41 -0
  14. package/dist/evaluation/metrics.service.d.ts +30 -0
  15. package/dist/evaluation/metrics.service.d.ts.map +1 -0
  16. package/dist/evaluation/metrics.service.js +54 -0
  17. package/dist/index.d.ts +16 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +42 -0
  20. package/dist/inference/batch.service.d.ts +16 -0
  21. package/dist/inference/batch.service.d.ts.map +1 -0
  22. package/dist/inference/batch.service.js +47 -0
  23. package/dist/inference/predictor.service.d.ts +13 -0
  24. package/dist/inference/predictor.service.d.ts.map +1 -0
  25. package/dist/inference/predictor.service.js +65 -0
  26. package/dist/ml-model.base.d.ts +20 -0
  27. package/dist/ml-model.base.d.ts.map +1 -0
  28. package/dist/ml-model.base.js +33 -0
  29. package/dist/ml.module.d.ts +27 -0
  30. package/dist/ml.module.d.ts.map +1 -0
  31. package/dist/ml.module.js +126 -0
  32. package/dist/ml.types.d.ts +30 -0
  33. package/dist/ml.types.d.ts.map +1 -0
  34. package/dist/ml.types.js +5 -0
  35. package/dist/registry/model.registry.d.ts +21 -0
  36. package/dist/registry/model.registry.d.ts.map +1 -0
  37. package/dist/registry/model.registry.js +64 -0
  38. package/dist/training/pipeline.service.d.ts +17 -0
  39. package/dist/training/pipeline.service.d.ts.map +1 -0
  40. package/dist/training/pipeline.service.js +49 -0
  41. package/dist/training/trainer.service.d.ts +13 -0
  42. package/dist/training/trainer.service.d.ts.map +1 -0
  43. package/dist/training/trainer.service.js +69 -0
  44. package/package.json +52 -0
package/LICENSE ADDED
@@ -0,0 +1,192 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2024 HazelJS Team
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ ---
20
+
21
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
22
+
23
+ 1. Definitions.
24
+
25
+ "License" shall mean the terms and conditions for use, reproduction,
26
+ and distribution as defined by Sections 1 through 9 of this document.
27
+
28
+ "Licensor" shall mean the copyright owner or entity authorized by
29
+ the copyright owner that is granting the License.
30
+
31
+ "Legal Entity" shall mean the union of the acting entity and all
32
+ other entities that control, are controlled by, or are under common
33
+ control with that entity. For the purposes of this definition,
34
+ "control" means (i) the power, direct or indirect, to cause the
35
+ direction or management of such entity, whether by contract or
36
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
37
+ outstanding shares, or (iii) beneficial ownership of such entity.
38
+
39
+ "You" (or "Your") shall mean an individual or Legal Entity
40
+ exercising permissions granted by this License.
41
+
42
+ "Source" form shall mean the preferred form for making modifications,
43
+ including but not limited to software source code, documentation
44
+ source, and configuration files.
45
+
46
+ "Object" form shall mean any form resulting from mechanical
47
+ transformation or translation of a Source form, including but
48
+ not limited to compiled object code, generated documentation,
49
+ and conversions to other media types.
50
+
51
+ "Work" shall mean the work of authorship, whether in Source or
52
+ Object form, made available under the License, as indicated by a
53
+ copyright notice that is included in or attached to the work
54
+ (an example is provided in the Appendix below).
55
+
56
+ "Derivative Works" shall mean any work, whether in Source or Object
57
+ form, that is based on (or derived from) the Work and for which the
58
+ editorial revisions, annotations, elaborations, or other modifications
59
+ represent, as a whole, an original work of authorship. For the purposes
60
+ of this License, Derivative Works shall not include works that remain
61
+ separable from, or merely link (or bind by name) to the interfaces of,
62
+ the Work and Derivative Works thereof.
63
+
64
+ "Contribution" shall mean any work of authorship, including
65
+ the original version of the Work and any modifications or additions
66
+ to that Work or Derivative Works thereof, that is intentionally
67
+ submitted to Licensor for inclusion in the Work by the copyright owner
68
+ or by an individual or Legal Entity authorized to submit on behalf of
69
+ the copyright owner. For the purposes of this definition, "submitted"
70
+ means any form of electronic, verbal, or written communication sent
71
+ to the Licensor or its representatives, including but not limited to
72
+ communication on electronic mailing lists, source code control systems,
73
+ and issue tracking systems that are managed by, or on behalf of, the
74
+ Licensor for the purpose of discussing and improving the Work, but
75
+ excluding communication that is conspicuously marked or otherwise
76
+ designated in writing by the copyright owner as "Not a Contribution."
77
+
78
+ "Contributor" shall mean Licensor and any individual or Legal Entity
79
+ on behalf of whom a Contribution has been received by Licensor and
80
+ subsequently incorporated within the Work.
81
+
82
+ 2. Grant of Copyright License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ copyright license to reproduce, prepare Derivative Works of,
86
+ publicly display, publicly perform, sublicense, and distribute the
87
+ Work and such Derivative Works in Source or Object form.
88
+
89
+ 3. Grant of Patent License. Subject to the terms and conditions of
90
+ this License, each Contributor hereby grants to You a perpetual,
91
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
92
+ (except as stated in this section) patent license to make, have made,
93
+ use, offer to sell, sell, import, and otherwise transfer the Work,
94
+ where such license applies only to those patent claims licensable
95
+ by such Contributor that are necessarily infringed by their
96
+ Contribution(s) alone or by combination of their Contribution(s)
97
+ with the Work to which such Contribution(s) was submitted. If You
98
+ institute patent litigation against any entity (including a
99
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
100
+ or a Contribution incorporated within the Work constitutes direct
101
+ or contributory patent infringement, then any patent licenses
102
+ granted to You under this License for that Work shall terminate
103
+ as of the date such litigation is filed.
104
+
105
+ 4. Redistribution. You may reproduce and distribute copies of the
106
+ Work or Derivative Works thereof in any medium, with or without
107
+ modifications, and in Source or Object form, provided that You
108
+ meet the following conditions:
109
+
110
+ (a) You must give any other recipients of the Work or
111
+ Derivative Works a copy of this License; and
112
+
113
+ (b) You must cause any modified files to carry prominent notices
114
+ stating that You changed the files; and
115
+
116
+ (c) You must retain, in the Source form of any Derivative Works
117
+ that You distribute, all copyright, patent, trademark, and
118
+ attribution notices from the Source form of the Work,
119
+ excluding those notices that do not pertain to any part of
120
+ the Derivative Works; and
121
+
122
+ (d) If the Work includes a "NOTICE" text file as part of its
123
+ distribution, then any Derivative Works that You distribute must
124
+ include a readable copy of the attribution notices contained
125
+ within such NOTICE file, excluding those notices that do not
126
+ pertain to any part of the Derivative Works, in at least one
127
+ of the following places: within a NOTICE text file distributed
128
+ as part of the Derivative Works; within the Source form or
129
+ documentation, if provided along with the Derivative Works; or,
130
+ within a display generated by the Derivative Works, if and
131
+ wherever such third-party notices normally appear. The contents
132
+ of the NOTICE file are for informational purposes only and
133
+ do not modify the License. You may add Your own attribution
134
+ notices within Derivative Works that You distribute, alongside
135
+ or as an addendum to the NOTICE text from the Work, provided
136
+ that such additional attribution notices cannot be construed
137
+ as modifying the License.
138
+
139
+ You may add Your own copyright statement to Your modifications and
140
+ may provide additional or different license terms and conditions
141
+ for use, reproduction, or distribution of Your modifications, or
142
+ for any such Derivative Works as a whole, provided Your use,
143
+ reproduction, and distribution of the Work otherwise complies with
144
+ the conditions stated in this License.
145
+
146
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
147
+ any Contribution intentionally submitted for inclusion in the Work
148
+ by You to the Licensor shall be under the terms and conditions of
149
+ this License, without any additional terms or conditions.
150
+ Notwithstanding the above, nothing herein shall supersede or modify
151
+ the terms of any separate license agreement you may have executed
152
+ with Licensor regarding such Contributions.
153
+
154
+ 6. Trademarks. This License does not grant permission to use the trade
155
+ names, trademarks, service marks, or product names of the Licensor,
156
+ except as required for reasonable and customary use in describing the
157
+ origin of the Work and reproducing the content of the NOTICE file.
158
+
159
+ 7. Disclaimer of Warranty. Unless required by applicable law or
160
+ agreed to in writing, Licensor provides the Work (and each
161
+ Contributor provides its Contributions) on an "AS IS" BASIS,
162
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
163
+ implied, including, without limitation, any warranties or conditions
164
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
165
+ PARTICULAR PURPOSE. You are solely responsible for determining the
166
+ appropriateness of using or redistributing the Work and assume any
167
+ risks associated with Your exercise of permissions under this License.
168
+
169
+ 8. Limitation of Liability. In no event and under no legal theory,
170
+ whether in tort (including negligence), contract, or otherwise,
171
+ unless required by applicable law (such as deliberate and grossly
172
+ negligent acts) or agreed to in writing, shall any Contributor be
173
+ liable to You for damages, including any direct, indirect, special,
174
+ incidental, or consequential damages of any character arising as a
175
+ result of this License or out of the use or inability to use the
176
+ Work (including but not limited to damages for loss of goodwill,
177
+ work stoppage, computer failure or malfunction, or any and all
178
+ other commercial damages or losses), even if such Contributor
179
+ has been advised of the possibility of such damages.
180
+
181
+ 9. Accepting Warranty or Additional Liability. While redistributing
182
+ the Work or Derivative Works thereof, You may choose to offer,
183
+ and charge a fee for, acceptance of support, warranty, indemnity,
184
+ or other liability obligations and/or rights consistent with this
185
+ License. However, in accepting such obligations, You may act only
186
+ on Your own behalf and on Your sole responsibility, not on behalf
187
+ of any other Contributor, and only if You agree to indemnify,
188
+ defend, and hold each Contributor harmless for any liability
189
+ incurred by, or claims asserted against, such Contributor by reason
190
+ of your accepting any such warranty or additional liability.
191
+
192
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,4 @@
1
+ export { Model, getModelMetadata, hasModelMetadata } from './model.decorator';
2
+ export { Train, getTrainMetadata, hasTrainMetadata, type TrainOptions } from './train.decorator';
3
+ export { Predict, getPredictMetadata, hasPredictMetadata, type PredictOptions, } from './predict.decorator';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjG,OAAO,EACL,OAAO,EACP,kBAAkB,EAClB,kBAAkB,EAClB,KAAK,cAAc,GACpB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasPredictMetadata = exports.getPredictMetadata = exports.Predict = exports.hasTrainMetadata = exports.getTrainMetadata = exports.Train = exports.hasModelMetadata = exports.getModelMetadata = exports.Model = void 0;
4
+ var model_decorator_1 = require("./model.decorator");
5
+ Object.defineProperty(exports, "Model", { enumerable: true, get: function () { return model_decorator_1.Model; } });
6
+ Object.defineProperty(exports, "getModelMetadata", { enumerable: true, get: function () { return model_decorator_1.getModelMetadata; } });
7
+ Object.defineProperty(exports, "hasModelMetadata", { enumerable: true, get: function () { return model_decorator_1.hasModelMetadata; } });
8
+ var train_decorator_1 = require("./train.decorator");
9
+ Object.defineProperty(exports, "Train", { enumerable: true, get: function () { return train_decorator_1.Train; } });
10
+ Object.defineProperty(exports, "getTrainMetadata", { enumerable: true, get: function () { return train_decorator_1.getTrainMetadata; } });
11
+ Object.defineProperty(exports, "hasTrainMetadata", { enumerable: true, get: function () { return train_decorator_1.hasTrainMetadata; } });
12
+ var predict_decorator_1 = require("./predict.decorator");
13
+ Object.defineProperty(exports, "Predict", { enumerable: true, get: function () { return predict_decorator_1.Predict; } });
14
+ Object.defineProperty(exports, "getPredictMetadata", { enumerable: true, get: function () { return predict_decorator_1.getPredictMetadata; } });
15
+ Object.defineProperty(exports, "hasPredictMetadata", { enumerable: true, get: function () { return predict_decorator_1.hasPredictMetadata; } });
@@ -0,0 +1,26 @@
1
+ import 'reflect-metadata';
2
+ import { ModelMetadata } from '../ml.types';
3
+ /**
4
+ * @Model decorator - Register ML models with the registry
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * @Model({
9
+ * name: 'sentiment-classifier',
10
+ * version: '1.0.0',
11
+ * framework: 'tensorflow',
12
+ * })
13
+ * @Injectable()
14
+ * export class SentimentModel {
15
+ * @Train()
16
+ * async train(data: TrainingData) { ... }
17
+ *
18
+ * @Predict()
19
+ * async predict(text: string) { ... }
20
+ * }
21
+ * ```
22
+ */
23
+ export declare function Model(config: ModelMetadata): ClassDecorator;
24
+ export declare function getModelMetadata(target: object): ModelMetadata | undefined;
25
+ export declare function hasModelMetadata(target: object): boolean;
26
+ //# sourceMappingURL=model.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/model.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc,CAW3D;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE1E;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAExD"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Model = Model;
7
+ exports.getModelMetadata = getModelMetadata;
8
+ exports.hasModelMetadata = hasModelMetadata;
9
+ require("reflect-metadata");
10
+ const core_1 = __importDefault(require("@hazeljs/core"));
11
+ const MODEL_METADATA_KEY = 'hazel:ml:model';
12
+ /**
13
+ * @Model decorator - Register ML models with the registry
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * @Model({
18
+ * name: 'sentiment-classifier',
19
+ * version: '1.0.0',
20
+ * framework: 'tensorflow',
21
+ * })
22
+ * @Injectable()
23
+ * export class SentimentModel {
24
+ * @Train()
25
+ * async train(data: TrainingData) { ... }
26
+ *
27
+ * @Predict()
28
+ * async predict(text: string) { ... }
29
+ * }
30
+ * ```
31
+ */
32
+ function Model(config) {
33
+ return (target) => {
34
+ const metadata = {
35
+ description: '',
36
+ tags: [],
37
+ ...config,
38
+ };
39
+ Reflect.defineMetadata(MODEL_METADATA_KEY, metadata, target);
40
+ core_1.default.debug(`Model decorator applied: ${metadata.name}@${metadata.version}`);
41
+ };
42
+ }
43
+ function getModelMetadata(target) {
44
+ return Reflect.getMetadata(MODEL_METADATA_KEY, target);
45
+ }
46
+ function hasModelMetadata(target) {
47
+ return Reflect.hasMetadata(MODEL_METADATA_KEY, target);
48
+ }
@@ -0,0 +1,20 @@
1
+ import 'reflect-metadata';
2
+ export interface PredictOptions {
3
+ batch?: boolean;
4
+ endpoint?: string;
5
+ }
6
+ /**
7
+ * @Predict decorator - Mark a method as the inference endpoint
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * @Predict({ endpoint: '/predict' })
12
+ * async predict(text: string) {
13
+ * return { sentiment: 'positive', confidence: 0.92 };
14
+ * }
15
+ * ```
16
+ */
17
+ export declare function Predict(options?: PredictOptions): MethodDecorator;
18
+ export declare function getPredictMetadata(target: object, propertyKey: string | symbol): PredictOptions | undefined;
19
+ export declare function hasPredictMetadata(target: object, propertyKey: string | symbol): boolean;
20
+ //# sourceMappingURL=predict.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predict.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/predict.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAK1B,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,eAAe,CAarE;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,cAAc,GAAG,SAAS,CAE5B;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAExF"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Predict = Predict;
7
+ exports.getPredictMetadata = getPredictMetadata;
8
+ exports.hasPredictMetadata = hasPredictMetadata;
9
+ require("reflect-metadata");
10
+ const core_1 = __importDefault(require("@hazeljs/core"));
11
+ const PREDICT_METADATA_KEY = 'hazel:ml:predict';
12
+ /**
13
+ * @Predict decorator - Mark a method as the inference endpoint
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * @Predict({ endpoint: '/predict' })
18
+ * async predict(text: string) {
19
+ * return { sentiment: 'positive', confidence: 0.92 };
20
+ * }
21
+ * ```
22
+ */
23
+ function Predict(options = {}) {
24
+ return (target, propertyKey, descriptor) => {
25
+ const metadata = {
26
+ batch: false,
27
+ endpoint: '/predict',
28
+ ...options,
29
+ };
30
+ Reflect.defineMetadata(PREDICT_METADATA_KEY, metadata, target, propertyKey);
31
+ core_1.default.debug(`Predict decorator applied to ${target.constructor.name}.${String(propertyKey)}`);
32
+ return descriptor;
33
+ };
34
+ }
35
+ function getPredictMetadata(target, propertyKey) {
36
+ return Reflect.getMetadata(PREDICT_METADATA_KEY, target, propertyKey);
37
+ }
38
+ function hasPredictMetadata(target, propertyKey) {
39
+ return Reflect.hasMetadata(PREDICT_METADATA_KEY, target, propertyKey);
40
+ }
@@ -0,0 +1,21 @@
1
+ import 'reflect-metadata';
2
+ export interface TrainOptions {
3
+ pipeline?: string;
4
+ batchSize?: number;
5
+ epochs?: number;
6
+ }
7
+ /**
8
+ * @Train decorator - Mark a method as the training pipeline
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * @Train({ pipeline: 'default', epochs: 10 })
13
+ * async train(data: TrainingData) {
14
+ * return { accuracy: 0.95, loss: 0.05 };
15
+ * }
16
+ * ```
17
+ */
18
+ export declare function Train(options?: TrainOptions): MethodDecorator;
19
+ export declare function getTrainMetadata(target: object, propertyKey: string | symbol): TrainOptions | undefined;
20
+ export declare function hasTrainMetadata(target: object, propertyKey: string | symbol): boolean;
21
+ //# sourceMappingURL=train.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"train.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/train.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAK1B,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,eAAe,CAcjE;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,YAAY,GAAG,SAAS,CAE1B;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAEtF"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Train = Train;
7
+ exports.getTrainMetadata = getTrainMetadata;
8
+ exports.hasTrainMetadata = hasTrainMetadata;
9
+ require("reflect-metadata");
10
+ const core_1 = __importDefault(require("@hazeljs/core"));
11
+ const TRAIN_METADATA_KEY = 'hazel:ml:train';
12
+ /**
13
+ * @Train decorator - Mark a method as the training pipeline
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * @Train({ pipeline: 'default', epochs: 10 })
18
+ * async train(data: TrainingData) {
19
+ * return { accuracy: 0.95, loss: 0.05 };
20
+ * }
21
+ * ```
22
+ */
23
+ function Train(options = {}) {
24
+ return (target, propertyKey, descriptor) => {
25
+ const metadata = {
26
+ pipeline: 'default',
27
+ batchSize: 32,
28
+ epochs: 10,
29
+ ...options,
30
+ };
31
+ Reflect.defineMetadata(TRAIN_METADATA_KEY, metadata, target, propertyKey);
32
+ core_1.default.debug(`Train decorator applied to ${target.constructor.name}.${String(propertyKey)}`);
33
+ return descriptor;
34
+ };
35
+ }
36
+ function getTrainMetadata(target, propertyKey) {
37
+ return Reflect.getMetadata(TRAIN_METADATA_KEY, target, propertyKey);
38
+ }
39
+ function hasTrainMetadata(target, propertyKey) {
40
+ return Reflect.hasMetadata(TRAIN_METADATA_KEY, target, propertyKey);
41
+ }
@@ -0,0 +1,30 @@
1
+ export interface ModelMetrics {
2
+ accuracy?: number;
3
+ precision?: number;
4
+ recall?: number;
5
+ f1Score?: number;
6
+ loss?: number;
7
+ [key: string]: number | undefined;
8
+ }
9
+ export interface EvaluationResult {
10
+ modelName: string;
11
+ version: string;
12
+ metrics: ModelMetrics;
13
+ evaluatedAt: Date;
14
+ }
15
+ /**
16
+ * Metrics Service - Model evaluation and metrics
17
+ * Tracks model performance for A/B testing and monitoring
18
+ */
19
+ export declare class MetricsService {
20
+ private metrics;
21
+ recordEvaluation(result: EvaluationResult): void;
22
+ getMetrics(modelName: string, version?: string): EvaluationResult | undefined;
23
+ getHistory(modelName: string): EvaluationResult[];
24
+ compareVersions(modelName: string, versionA: string, versionB: string): {
25
+ a: EvaluationResult | undefined;
26
+ b: EvaluationResult | undefined;
27
+ winner?: string;
28
+ };
29
+ }
30
+ //# sourceMappingURL=metrics.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.service.d.ts","sourceRoot":"","sources":["../../src/evaluation/metrics.service.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,YAAY,CAAC;IACtB,WAAW,EAAE,IAAI,CAAC;CACnB;AAED;;;GAGG;AACH,qBACa,cAAc;IACzB,OAAO,CAAC,OAAO,CAA8C;IAE7D,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI;IAQhD,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAQ7E,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAIjD,eAAe,CACb,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf;QACD,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;QAChC,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;QAChC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;CAYF"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MetricsService = void 0;
13
+ const core_1 = require("@hazeljs/core");
14
+ const core_2 = __importDefault(require("@hazeljs/core"));
15
+ /**
16
+ * Metrics Service - Model evaluation and metrics
17
+ * Tracks model performance for A/B testing and monitoring
18
+ */
19
+ let MetricsService = class MetricsService {
20
+ constructor() {
21
+ this.metrics = new Map();
22
+ }
23
+ recordEvaluation(result) {
24
+ const key = result.modelName;
25
+ const existing = this.metrics.get(key) || [];
26
+ existing.push(result);
27
+ this.metrics.set(key, existing);
28
+ core_2.default.debug(`Recorded evaluation for ${key}@${result.version}`);
29
+ }
30
+ getMetrics(modelName, version) {
31
+ const results = this.metrics.get(modelName) || [];
32
+ if (version) {
33
+ return results.find((r) => r.version === version);
34
+ }
35
+ return results[results.length - 1];
36
+ }
37
+ getHistory(modelName) {
38
+ return this.metrics.get(modelName) || [];
39
+ }
40
+ compareVersions(modelName, versionA, versionB) {
41
+ const results = this.metrics.get(modelName) || [];
42
+ const a = results.find((r) => r.version === versionA);
43
+ const b = results.find((r) => r.version === versionB);
44
+ let winner;
45
+ if (a?.metrics.accuracy !== undefined && b?.metrics.accuracy !== undefined) {
46
+ winner = a.metrics.accuracy >= b.metrics.accuracy ? versionA : versionB;
47
+ }
48
+ return { a, b, winner };
49
+ }
50
+ };
51
+ exports.MetricsService = MetricsService;
52
+ exports.MetricsService = MetricsService = __decorate([
53
+ (0, core_1.Injectable)()
54
+ ], MetricsService);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @hazeljs/ml - Machine Learning & Model Management for HazelJS
3
+ */
4
+ import 'reflect-metadata';
5
+ export { MLModule, ML_MODELS, type MLModuleOptions } from './ml.module';
6
+ export { Model, Train, Predict, getModelMetadata, hasModelMetadata, getTrainMetadata, hasTrainMetadata, getPredictMetadata, hasPredictMetadata, type TrainOptions, type PredictOptions, } from './decorators';
7
+ export { ModelRegistry, type RegisteredModel } from './registry/model.registry';
8
+ export { TrainerService } from './training/trainer.service';
9
+ export { PipelineService, type PipelineStep } from './training/pipeline.service';
10
+ export { PredictorService } from './inference/predictor.service';
11
+ export { BatchService, type BatchPredictionOptions } from './inference/batch.service';
12
+ export { MetricsService, type ModelMetrics, type EvaluationResult, } from './evaluation/metrics.service';
13
+ export { registerMLModel } from './ml-model.base';
14
+ export { Injectable } from '@hazeljs/core';
15
+ export type { MLFramework, ModelMetadata, TrainingData, TrainingResult, PredictionResult, ModelVersion, } from './ml.types';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,kBAAkB,CAAC;AAG1B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAGxE,OAAO,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAGhF,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,KAAK,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EACL,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,gBAAgB,GACtB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,YAAY,EACV,WAAW,EACX,aAAa,EACb,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,YAAY,GACb,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /**
3
+ * @hazeljs/ml - Machine Learning & Model Management for HazelJS
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Injectable = exports.registerMLModel = exports.MetricsService = exports.BatchService = exports.PredictorService = exports.PipelineService = exports.TrainerService = exports.ModelRegistry = exports.hasPredictMetadata = exports.getPredictMetadata = exports.hasTrainMetadata = exports.getTrainMetadata = exports.hasModelMetadata = exports.getModelMetadata = exports.Predict = exports.Train = exports.Model = exports.ML_MODELS = exports.MLModule = void 0;
7
+ require("reflect-metadata");
8
+ // Module
9
+ var ml_module_1 = require("./ml.module");
10
+ Object.defineProperty(exports, "MLModule", { enumerable: true, get: function () { return ml_module_1.MLModule; } });
11
+ Object.defineProperty(exports, "ML_MODELS", { enumerable: true, get: function () { return ml_module_1.ML_MODELS; } });
12
+ // Decorators
13
+ var decorators_1 = require("./decorators");
14
+ Object.defineProperty(exports, "Model", { enumerable: true, get: function () { return decorators_1.Model; } });
15
+ Object.defineProperty(exports, "Train", { enumerable: true, get: function () { return decorators_1.Train; } });
16
+ Object.defineProperty(exports, "Predict", { enumerable: true, get: function () { return decorators_1.Predict; } });
17
+ Object.defineProperty(exports, "getModelMetadata", { enumerable: true, get: function () { return decorators_1.getModelMetadata; } });
18
+ Object.defineProperty(exports, "hasModelMetadata", { enumerable: true, get: function () { return decorators_1.hasModelMetadata; } });
19
+ Object.defineProperty(exports, "getTrainMetadata", { enumerable: true, get: function () { return decorators_1.getTrainMetadata; } });
20
+ Object.defineProperty(exports, "hasTrainMetadata", { enumerable: true, get: function () { return decorators_1.hasTrainMetadata; } });
21
+ Object.defineProperty(exports, "getPredictMetadata", { enumerable: true, get: function () { return decorators_1.getPredictMetadata; } });
22
+ Object.defineProperty(exports, "hasPredictMetadata", { enumerable: true, get: function () { return decorators_1.hasPredictMetadata; } });
23
+ // Registry
24
+ var model_registry_1 = require("./registry/model.registry");
25
+ Object.defineProperty(exports, "ModelRegistry", { enumerable: true, get: function () { return model_registry_1.ModelRegistry; } });
26
+ // Services
27
+ var trainer_service_1 = require("./training/trainer.service");
28
+ Object.defineProperty(exports, "TrainerService", { enumerable: true, get: function () { return trainer_service_1.TrainerService; } });
29
+ var pipeline_service_1 = require("./training/pipeline.service");
30
+ Object.defineProperty(exports, "PipelineService", { enumerable: true, get: function () { return pipeline_service_1.PipelineService; } });
31
+ var predictor_service_1 = require("./inference/predictor.service");
32
+ Object.defineProperty(exports, "PredictorService", { enumerable: true, get: function () { return predictor_service_1.PredictorService; } });
33
+ var batch_service_1 = require("./inference/batch.service");
34
+ Object.defineProperty(exports, "BatchService", { enumerable: true, get: function () { return batch_service_1.BatchService; } });
35
+ var metrics_service_1 = require("./evaluation/metrics.service");
36
+ Object.defineProperty(exports, "MetricsService", { enumerable: true, get: function () { return metrics_service_1.MetricsService; } });
37
+ // Model registration helper
38
+ var ml_model_base_1 = require("./ml-model.base");
39
+ Object.defineProperty(exports, "registerMLModel", { enumerable: true, get: function () { return ml_model_base_1.registerMLModel; } });
40
+ // Re-export Injectable from core for convenience
41
+ var core_1 = require("@hazeljs/core");
42
+ Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return core_1.Injectable; } });
@@ -0,0 +1,16 @@
1
+ import { PredictorService } from './predictor.service';
2
+ import { PredictionResult } from '../ml.types';
3
+ export interface BatchPredictionOptions {
4
+ batchSize?: number;
5
+ concurrency?: number;
6
+ }
7
+ /**
8
+ * Batch Service - Batch processing for inference
9
+ * Handles bulk prediction requests efficiently
10
+ */
11
+ export declare class BatchService {
12
+ private readonly predictorService;
13
+ constructor(predictorService: PredictorService);
14
+ predictBatch<T = unknown>(modelName: string, inputs: unknown[], options?: BatchPredictionOptions, version?: string): Promise<PredictionResult<T>[]>;
15
+ }
16
+ //# sourceMappingURL=batch.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.service.d.ts","sourceRoot":"","sources":["../../src/inference/batch.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,qBACa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBAAhB,gBAAgB,EAAE,gBAAgB;IAEzD,YAAY,CAAC,CAAC,GAAG,OAAO,EAC5B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,EAAE,EACjB,OAAO,GAAE,sBAA2B,EACpC,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;CAwBlC"}