@carlonicora/nestjs-neo4jsonapi 1.79.0 → 1.81.0
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/dist/config/base.config.d.ts.map +1 -1
- package/dist/config/base.config.js +2 -0
- package/dist/config/base.config.js.map +1 -1
- package/dist/config/interfaces/config.ai.interface.d.ts +14 -0
- package/dist/config/interfaces/config.ai.interface.d.ts.map +1 -1
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +12 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/llm/services/audio/ffmpeg-transcode.d.ts +28 -1
- package/dist/core/llm/services/audio/ffmpeg-transcode.d.ts.map +1 -1
- package/dist/core/llm/services/audio/ffmpeg-transcode.js +27 -6
- package/dist/core/llm/services/audio/ffmpeg-transcode.js.map +1 -1
- package/dist/core/llm/services/audio.llm.service.d.ts +6 -0
- package/dist/core/llm/services/audio.llm.service.d.ts.map +1 -1
- package/dist/core/llm/services/audio.llm.service.js +43 -17
- package/dist/core/llm/services/audio.llm.service.js.map +1 -1
- package/dist/core/model-manager/index.d.ts +8 -0
- package/dist/core/model-manager/index.d.ts.map +1 -0
- package/dist/core/model-manager/index.js +26 -0
- package/dist/core/model-manager/index.js.map +1 -0
- package/dist/core/model-manager/model-loader.d.ts +22 -0
- package/dist/core/model-manager/model-loader.d.ts.map +1 -0
- package/dist/core/model-manager/model-loader.js +213 -0
- package/dist/core/model-manager/model-loader.js.map +1 -0
- package/dist/core/model-manager/model-manager.config.d.ts +81 -0
- package/dist/core/model-manager/model-manager.config.d.ts.map +1 -0
- package/dist/core/model-manager/model-manager.config.js +8 -0
- package/dist/core/model-manager/model-manager.config.js.map +1 -0
- package/dist/core/model-manager/model-manager.module.d.ts +12 -0
- package/dist/core/model-manager/model-manager.module.d.ts.map +1 -0
- package/dist/core/model-manager/model-manager.module.js +31 -0
- package/dist/core/model-manager/model-manager.module.js.map +1 -0
- package/dist/core/model-manager/model-manager.service.d.ts +65 -0
- package/dist/core/model-manager/model-manager.service.d.ts.map +1 -0
- package/dist/core/model-manager/model-manager.service.js +428 -0
- package/dist/core/model-manager/model-manager.service.js.map +1 -0
- package/dist/core/onnx-runtime/index.d.ts +5 -0
- package/dist/core/onnx-runtime/index.d.ts.map +1 -0
- package/dist/core/onnx-runtime/index.js +10 -0
- package/dist/core/onnx-runtime/index.js.map +1 -0
- package/dist/core/onnx-runtime/onnx-runtime.config.d.ts +72 -0
- package/dist/core/onnx-runtime/onnx-runtime.config.d.ts.map +1 -0
- package/dist/core/onnx-runtime/onnx-runtime.config.js +12 -0
- package/dist/core/onnx-runtime/onnx-runtime.config.js.map +1 -0
- package/dist/core/onnx-runtime/onnx-runtime.constants.d.ts +5 -0
- package/dist/core/onnx-runtime/onnx-runtime.constants.d.ts.map +1 -0
- package/dist/core/onnx-runtime/onnx-runtime.constants.js +8 -0
- package/dist/core/onnx-runtime/onnx-runtime.constants.js.map +1 -0
- package/dist/core/onnx-runtime/onnx-runtime.module.d.ts +67 -0
- package/dist/core/onnx-runtime/onnx-runtime.module.d.ts.map +1 -0
- package/dist/core/onnx-runtime/onnx-runtime.module.js +103 -0
- package/dist/core/onnx-runtime/onnx-runtime.module.js.map +1 -0
- package/dist/core/onnx-runtime/onnx-runtime.service.d.ts +58 -0
- package/dist/core/onnx-runtime/onnx-runtime.service.d.ts.map +1 -0
- package/dist/core/onnx-runtime/onnx-runtime.service.js +149 -0
- package/dist/core/onnx-runtime/onnx-runtime.service.js.map +1 -0
- package/package.json +6 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { OnnxRuntimeModuleOptions } from "./onnx-runtime.config";
|
|
3
|
+
interface OnnxRuntimeAsyncOptions {
|
|
4
|
+
imports?: any[];
|
|
5
|
+
inject?: any[];
|
|
6
|
+
useFactory: (...args: any[]) => Promise<OnnxRuntimeModuleOptions> | OnnxRuntimeModuleOptions;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Global NestJS module for ONNX Runtime session management.
|
|
10
|
+
*
|
|
11
|
+
* This module provides centralized ONNX model loading and session management.
|
|
12
|
+
* It uses OnApplicationBootstrap to load models AFTER @huggingface/transformers
|
|
13
|
+
* services (which use OnModuleInit), avoiding potential conflicts.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // In your root module (e.g., FeaturesModules)
|
|
18
|
+
* import { OnnxRuntimeModule } from 'src/common/onnx-runtime';
|
|
19
|
+
*
|
|
20
|
+
* const ONNX_MODELS: OnnxModelConfig[] = [
|
|
21
|
+
* { name: 'yolo-pose', path: 'models/yolo11l-pose.onnx', priority: 1, optional: false },
|
|
22
|
+
* { name: 'arcface', path: 'models/arcface.onnx', priority: 2, optional: false },
|
|
23
|
+
* ];
|
|
24
|
+
*
|
|
25
|
+
* @Module({
|
|
26
|
+
* imports: [
|
|
27
|
+
* OnnxRuntimeModule.forRoot({ models: ONNX_MODELS }),
|
|
28
|
+
* ],
|
|
29
|
+
* })
|
|
30
|
+
* export class FeaturesModules {}
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // In your service
|
|
36
|
+
* import { OnnxRuntimeService } from 'src/common/onnx-runtime';
|
|
37
|
+
*
|
|
38
|
+
* @Injectable()
|
|
39
|
+
* export class MyDetectionService {
|
|
40
|
+
* constructor(private readonly onnxService: OnnxRuntimeService) {}
|
|
41
|
+
*
|
|
42
|
+
* async detect(buffer: Buffer) {
|
|
43
|
+
* const session = this.onnxService.getSession('yolo-pose');
|
|
44
|
+
* if (!session) throw new Error('Model not loaded');
|
|
45
|
+
* // ... run inference
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare class OnnxRuntimeModule {
|
|
51
|
+
/**
|
|
52
|
+
* Configure the ONNX Runtime module with model definitions.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Configuration including models to load
|
|
55
|
+
* @returns Dynamic module configuration
|
|
56
|
+
*/
|
|
57
|
+
static forRoot(options: OnnxRuntimeModuleOptions): DynamicModule;
|
|
58
|
+
/**
|
|
59
|
+
* Configure the ONNX Runtime module asynchronously with ConfigService.
|
|
60
|
+
*
|
|
61
|
+
* @param options - Async configuration including factory function
|
|
62
|
+
* @returns Dynamic module configuration
|
|
63
|
+
*/
|
|
64
|
+
static forRootAsync(options: OnnxRuntimeAsyncOptions): DynamicModule;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=onnx-runtime.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onnx-runtime.module.d.ts","sourceRoot":"","sources":["../../../src/core/onnx-runtime/onnx-runtime.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAKjE,UAAU,uBAAuB;IAC/B,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,wBAAwB,CAAC,GAAG,wBAAwB,CAAC;CAC9F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBAEa,iBAAiB;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;IAchE;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,uBAAuB,GAAG,aAAa;CAerE"}
|
|
@@ -0,0 +1,103 @@
|
|
|
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 OnnxRuntimeModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.OnnxRuntimeModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const onnx_runtime_service_1 = require("./onnx-runtime.service");
|
|
13
|
+
const onnx_runtime_constants_1 = require("./onnx-runtime.constants");
|
|
14
|
+
/**
|
|
15
|
+
* Global NestJS module for ONNX Runtime session management.
|
|
16
|
+
*
|
|
17
|
+
* This module provides centralized ONNX model loading and session management.
|
|
18
|
+
* It uses OnApplicationBootstrap to load models AFTER @huggingface/transformers
|
|
19
|
+
* services (which use OnModuleInit), avoiding potential conflicts.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // In your root module (e.g., FeaturesModules)
|
|
24
|
+
* import { OnnxRuntimeModule } from 'src/common/onnx-runtime';
|
|
25
|
+
*
|
|
26
|
+
* const ONNX_MODELS: OnnxModelConfig[] = [
|
|
27
|
+
* { name: 'yolo-pose', path: 'models/yolo11l-pose.onnx', priority: 1, optional: false },
|
|
28
|
+
* { name: 'arcface', path: 'models/arcface.onnx', priority: 2, optional: false },
|
|
29
|
+
* ];
|
|
30
|
+
*
|
|
31
|
+
* @Module({
|
|
32
|
+
* imports: [
|
|
33
|
+
* OnnxRuntimeModule.forRoot({ models: ONNX_MODELS }),
|
|
34
|
+
* ],
|
|
35
|
+
* })
|
|
36
|
+
* export class FeaturesModules {}
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // In your service
|
|
42
|
+
* import { OnnxRuntimeService } from 'src/common/onnx-runtime';
|
|
43
|
+
*
|
|
44
|
+
* @Injectable()
|
|
45
|
+
* export class MyDetectionService {
|
|
46
|
+
* constructor(private readonly onnxService: OnnxRuntimeService) {}
|
|
47
|
+
*
|
|
48
|
+
* async detect(buffer: Buffer) {
|
|
49
|
+
* const session = this.onnxService.getSession('yolo-pose');
|
|
50
|
+
* if (!session) throw new Error('Model not loaded');
|
|
51
|
+
* // ... run inference
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
let OnnxRuntimeModule = OnnxRuntimeModule_1 = class OnnxRuntimeModule {
|
|
57
|
+
/**
|
|
58
|
+
* Configure the ONNX Runtime module with model definitions.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Configuration including models to load
|
|
61
|
+
* @returns Dynamic module configuration
|
|
62
|
+
*/
|
|
63
|
+
static forRoot(options) {
|
|
64
|
+
return {
|
|
65
|
+
module: OnnxRuntimeModule_1,
|
|
66
|
+
providers: [
|
|
67
|
+
{
|
|
68
|
+
provide: onnx_runtime_constants_1.ONNX_RUNTIME_OPTIONS,
|
|
69
|
+
useValue: options,
|
|
70
|
+
},
|
|
71
|
+
onnx_runtime_service_1.OnnxRuntimeService,
|
|
72
|
+
],
|
|
73
|
+
exports: [onnx_runtime_service_1.OnnxRuntimeService],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Configure the ONNX Runtime module asynchronously with ConfigService.
|
|
78
|
+
*
|
|
79
|
+
* @param options - Async configuration including factory function
|
|
80
|
+
* @returns Dynamic module configuration
|
|
81
|
+
*/
|
|
82
|
+
static forRootAsync(options) {
|
|
83
|
+
return {
|
|
84
|
+
module: OnnxRuntimeModule_1,
|
|
85
|
+
imports: options.imports || [],
|
|
86
|
+
providers: [
|
|
87
|
+
{
|
|
88
|
+
provide: onnx_runtime_constants_1.ONNX_RUNTIME_OPTIONS,
|
|
89
|
+
useFactory: options.useFactory,
|
|
90
|
+
inject: options.inject || [],
|
|
91
|
+
},
|
|
92
|
+
onnx_runtime_service_1.OnnxRuntimeService,
|
|
93
|
+
],
|
|
94
|
+
exports: [onnx_runtime_service_1.OnnxRuntimeService],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
exports.OnnxRuntimeModule = OnnxRuntimeModule;
|
|
99
|
+
exports.OnnxRuntimeModule = OnnxRuntimeModule = OnnxRuntimeModule_1 = __decorate([
|
|
100
|
+
(0, common_1.Global)(),
|
|
101
|
+
(0, common_1.Module)({})
|
|
102
|
+
], OnnxRuntimeModule);
|
|
103
|
+
//# sourceMappingURL=onnx-runtime.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onnx-runtime.module.js","sourceRoot":"","sources":["../../../src/core/onnx-runtime/onnx-runtime.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA+D;AAE/D,iEAA4D;AAC5D,qEAAgE;AAShE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAGI,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,OAAiC;QAC9C,OAAO;YACL,MAAM,EAAE,mBAAiB;YACzB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,6CAAoB;oBAC7B,QAAQ,EAAE,OAAO;iBAClB;gBACD,yCAAkB;aACnB;YACD,OAAO,EAAE,CAAC,yCAAkB,CAAC;SAC9B,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,OAAgC;QAClD,OAAO;YACL,MAAM,EAAE,mBAAiB;YACzB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;YAC9B,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,6CAAoB;oBAC7B,UAAU,EAAE,OAAO,CAAC,UAAU;oBAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;iBAC7B;gBACD,yCAAkB;aACnB;YACD,OAAO,EAAE,CAAC,yCAAkB,CAAC;SAC9B,CAAC;IACJ,CAAC;CACF,CAAA;AA1CY,8CAAiB;4BAAjB,iBAAiB;IAF7B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,iBAAiB,CA0C7B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as ort from "onnxruntime-node";
|
|
2
|
+
import { OnnxRuntimeModuleOptions } from "./onnx-runtime.config";
|
|
3
|
+
import { ModelManagerService } from "../model-manager/model-manager.service";
|
|
4
|
+
/**
|
|
5
|
+
* ONNX Runtime service for session configuration and access.
|
|
6
|
+
*
|
|
7
|
+
* This service now delegates to ModelManagerService for model loading.
|
|
8
|
+
* It maintains backward compatibility by providing session access methods.
|
|
9
|
+
*
|
|
10
|
+
* The service uses OnApplicationBootstrap instead of OnModuleInit to ensure
|
|
11
|
+
* @huggingface/transformers services (which use OnModuleInit) load their models first,
|
|
12
|
+
* avoiding potential conflicts with the shared native ONNX Runtime.
|
|
13
|
+
*/
|
|
14
|
+
export declare class OnnxRuntimeService {
|
|
15
|
+
private readonly modelManager;
|
|
16
|
+
private readonly logger;
|
|
17
|
+
private readonly sessionOptions;
|
|
18
|
+
private readonly options;
|
|
19
|
+
constructor(options: OnnxRuntimeModuleOptions, modelManager: ModelManagerService);
|
|
20
|
+
/**
|
|
21
|
+
* Configure the ONNX Runtime global environment.
|
|
22
|
+
* Called once during service construction.
|
|
23
|
+
*/
|
|
24
|
+
private configureRuntime;
|
|
25
|
+
/**
|
|
26
|
+
* Build session options from configuration.
|
|
27
|
+
* Note: These options are no longer used directly for loading
|
|
28
|
+
* (ModelManagerService handles that), but kept for backward compatibility.
|
|
29
|
+
*/
|
|
30
|
+
private buildSessionOptions;
|
|
31
|
+
/**
|
|
32
|
+
* Get a loaded session by name.
|
|
33
|
+
* Delegates to ModelManagerService.
|
|
34
|
+
*
|
|
35
|
+
* @param name - The model name as configured in models.config.yaml
|
|
36
|
+
* @returns The InferenceSession, or null if not loaded
|
|
37
|
+
*/
|
|
38
|
+
getSession(name: string): ort.InferenceSession | null;
|
|
39
|
+
/**
|
|
40
|
+
* Check if a model is loaded and ready.
|
|
41
|
+
* Delegates to ModelManagerService.
|
|
42
|
+
*
|
|
43
|
+
* @param name - The model name
|
|
44
|
+
* @returns true if the model is loaded
|
|
45
|
+
*/
|
|
46
|
+
isModelLoaded(name: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Wait for all models to be loaded.
|
|
49
|
+
* Services that depend on ONNX models should call this before accessing them.
|
|
50
|
+
*/
|
|
51
|
+
waitForReady(): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Get all loaded ONNX model names.
|
|
54
|
+
* Delegates to ModelManagerService.
|
|
55
|
+
*/
|
|
56
|
+
getLoadedModels(): string[];
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=onnx-runtime.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onnx-runtime.service.d.ts","sourceRoot":"","sources":["../../../src/core/onnx-runtime/onnx-runtime.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAgC,MAAM,uBAAuB,CAAC;AAE/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAE7E;;;;;;;;;GASG;AACH,qBACa,kBAAkB;IAQ3B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAP/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAsC;IACrE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqC;gBAI3D,OAAO,EAAE,wBAAwB,EAChB,YAAY,EAAE,mBAAmB;IAepD;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAW3B;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,gBAAgB,GAAG,IAAI;IAIrD;;;;;;OAMG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIpC;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC;;;OAGG;IACH,eAAe,IAAI,MAAM,EAAE;CAI5B"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
45
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
|
+
};
|
|
47
|
+
var OnnxRuntimeService_1;
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.OnnxRuntimeService = void 0;
|
|
50
|
+
const common_1 = require("@nestjs/common");
|
|
51
|
+
const ort = __importStar(require("onnxruntime-node"));
|
|
52
|
+
const onnx_runtime_config_1 = require("./onnx-runtime.config");
|
|
53
|
+
const onnx_runtime_constants_1 = require("./onnx-runtime.constants");
|
|
54
|
+
const model_manager_service_1 = require("../model-manager/model-manager.service");
|
|
55
|
+
/**
|
|
56
|
+
* ONNX Runtime service for session configuration and access.
|
|
57
|
+
*
|
|
58
|
+
* This service now delegates to ModelManagerService for model loading.
|
|
59
|
+
* It maintains backward compatibility by providing session access methods.
|
|
60
|
+
*
|
|
61
|
+
* The service uses OnApplicationBootstrap instead of OnModuleInit to ensure
|
|
62
|
+
* @huggingface/transformers services (which use OnModuleInit) load their models first,
|
|
63
|
+
* avoiding potential conflicts with the shared native ONNX Runtime.
|
|
64
|
+
*/
|
|
65
|
+
let OnnxRuntimeService = OnnxRuntimeService_1 = class OnnxRuntimeService {
|
|
66
|
+
constructor(options, modelManager) {
|
|
67
|
+
this.modelManager = modelManager;
|
|
68
|
+
this.logger = new common_1.Logger(OnnxRuntimeService_1.name);
|
|
69
|
+
// Merge with defaults
|
|
70
|
+
this.options = {
|
|
71
|
+
...onnx_runtime_config_1.DEFAULT_ONNX_RUNTIME_OPTIONS,
|
|
72
|
+
...options,
|
|
73
|
+
};
|
|
74
|
+
// Configure ONNX Runtime environment ONCE at construction
|
|
75
|
+
this.configureRuntime();
|
|
76
|
+
// Build session options for backward compatibility
|
|
77
|
+
this.sessionOptions = this.buildSessionOptions();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Configure the ONNX Runtime global environment.
|
|
81
|
+
* Called once during service construction.
|
|
82
|
+
*/
|
|
83
|
+
configureRuntime() {
|
|
84
|
+
// Disable telemetry
|
|
85
|
+
ort.env.telemetry = false;
|
|
86
|
+
// Set log level to 'fatal' to silence verbose BFCArena/memory allocation logs
|
|
87
|
+
// Only critical errors will be shown
|
|
88
|
+
ort.env.logLevel = "fatal";
|
|
89
|
+
this.logger.log(`ONNX Runtime configured: threads=${this.options.intraOpNumThreads}/${this.options.interOpNumThreads}, ` +
|
|
90
|
+
`optimization=${this.options.graphOptimizationLevel}`);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Build session options from configuration.
|
|
94
|
+
* Note: These options are no longer used directly for loading
|
|
95
|
+
* (ModelManagerService handles that), but kept for backward compatibility.
|
|
96
|
+
*/
|
|
97
|
+
buildSessionOptions() {
|
|
98
|
+
return {
|
|
99
|
+
executionProviders: ["cpu"],
|
|
100
|
+
graphOptimizationLevel: this.options.graphOptimizationLevel,
|
|
101
|
+
intraOpNumThreads: this.options.intraOpNumThreads,
|
|
102
|
+
interOpNumThreads: this.options.interOpNumThreads,
|
|
103
|
+
enableCpuMemArena: true,
|
|
104
|
+
enableMemPattern: true,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get a loaded session by name.
|
|
109
|
+
* Delegates to ModelManagerService.
|
|
110
|
+
*
|
|
111
|
+
* @param name - The model name as configured in models.config.yaml
|
|
112
|
+
* @returns The InferenceSession, or null if not loaded
|
|
113
|
+
*/
|
|
114
|
+
getSession(name) {
|
|
115
|
+
return this.modelManager.getOnnxSession(name);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if a model is loaded and ready.
|
|
119
|
+
* Delegates to ModelManagerService.
|
|
120
|
+
*
|
|
121
|
+
* @param name - The model name
|
|
122
|
+
* @returns true if the model is loaded
|
|
123
|
+
*/
|
|
124
|
+
isModelLoaded(name) {
|
|
125
|
+
return this.modelManager.isModelLoaded(name, "onnx");
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Wait for all models to be loaded.
|
|
129
|
+
* Services that depend on ONNX models should call this before accessing them.
|
|
130
|
+
*/
|
|
131
|
+
async waitForReady() {
|
|
132
|
+
return this.modelManager.waitForReady();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get all loaded ONNX model names.
|
|
136
|
+
* Delegates to ModelManagerService.
|
|
137
|
+
*/
|
|
138
|
+
getLoadedModels() {
|
|
139
|
+
const loaded = this.modelManager.getLoadedModels();
|
|
140
|
+
return loaded.onnx;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
exports.OnnxRuntimeService = OnnxRuntimeService;
|
|
144
|
+
exports.OnnxRuntimeService = OnnxRuntimeService = OnnxRuntimeService_1 = __decorate([
|
|
145
|
+
(0, common_1.Injectable)(),
|
|
146
|
+
__param(0, (0, common_1.Inject)(onnx_runtime_constants_1.ONNX_RUNTIME_OPTIONS)),
|
|
147
|
+
__metadata("design:paramtypes", [Object, model_manager_service_1.ModelManagerService])
|
|
148
|
+
], OnnxRuntimeService);
|
|
149
|
+
//# sourceMappingURL=onnx-runtime.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onnx-runtime.service.js","sourceRoot":"","sources":["../../../src/core/onnx-runtime/onnx-runtime.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,sDAAwC;AACxC,+DAA+F;AAC/F,qEAAgE;AAChE,kFAA6E;AAE7E;;;;;;;;;GASG;AAEI,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAK7B,YAEE,OAAiC,EAChB,YAAiC;QAAjC,iBAAY,GAAZ,YAAY,CAAqB;QAPnC,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;QAS5D,sBAAsB;QACtB,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,kDAA4B;YAC/B,GAAG,OAAO;SAC2B,CAAC;QAExC,0DAA0D;QAC1D,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAExB,mDAAmD;QACnD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;IACnD,CAAC;IAED;;;OAGG;IACK,gBAAgB;QACtB,oBAAoB;QACpB,GAAG,CAAC,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC;QAE1B,8EAA8E;QAC9E,qCAAqC;QACrC,GAAG,CAAC,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC;QAE3B,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,oCAAoC,IAAI,CAAC,OAAO,CAAC,iBAAiB,IAAI,IAAI,CAAC,OAAO,CAAC,iBAAiB,IAAI;YACtG,gBAAgB,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,CACxD,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACK,mBAAmB;QACzB,OAAO;YACL,kBAAkB,EAAE,CAAC,KAAK,CAAC;YAC3B,sBAAsB,EAAE,IAAI,CAAC,OAAO,CAAC,sBAAsB;YAC3D,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,iBAAiB;YACjD,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,iBAAiB;YACjD,iBAAiB,EAAE,IAAI;YACvB,gBAAgB,EAAE,IAAI;SACvB,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED;;;;;;OAMG;IACH,aAAa,CAAC,IAAY;QACxB,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACvD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,CAAC;QACnD,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;CACF,CAAA;AA/FY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,eAAM,EAAC,6CAAoB,CAAC,CAAA;6CAEE,2CAAmB;GARzC,kBAAkB,CA+F9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carlonicora/nestjs-neo4jsonapi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.81.0",
|
|
4
4
|
"description": "NestJS foundation package with JSON:API, Neo4j, Redis, LangChain agents, and common utilities",
|
|
5
5
|
"author": "Carlo Nicora",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -105,6 +105,7 @@
|
|
|
105
105
|
"fastify": "^5.8.5",
|
|
106
106
|
"handlebars": "^4.7.9",
|
|
107
107
|
"ioredis": "^5.10.1",
|
|
108
|
+
"js-yaml": "^4.1.1",
|
|
108
109
|
"jszip": "^3.10.1",
|
|
109
110
|
"libreoffice-convert": "^1.8.1",
|
|
110
111
|
"lodash": "^4.18.1",
|
|
@@ -151,6 +152,7 @@
|
|
|
151
152
|
"@swc/core": "^1.15.33",
|
|
152
153
|
"@types/bcrypt": "^6.0.0",
|
|
153
154
|
"@types/bcryptjs": "^3.0.0",
|
|
155
|
+
"@types/js-yaml": "^4.0.9",
|
|
154
156
|
"@types/mdast": "^4.0.4",
|
|
155
157
|
"@types/node": "^25.9.1",
|
|
156
158
|
"@types/uuid": "^10.0.0",
|
|
@@ -218,5 +220,8 @@
|
|
|
218
220
|
"zod": {
|
|
219
221
|
"optional": false
|
|
220
222
|
}
|
|
223
|
+
},
|
|
224
|
+
"optionalDependencies": {
|
|
225
|
+
"onnxruntime-node": "1.26.0"
|
|
221
226
|
}
|
|
222
227
|
}
|