From 69a02a0a10d6393a0a88cca6e2c19de7178f6f2f Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 17:35:52 +0700 Subject: [PATCH 01/64] debug ps command --- cortex-js/src/infrastructure/commanders/ps.command.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cortex-js/src/infrastructure/commanders/ps.command.ts b/cortex-js/src/infrastructure/commanders/ps.command.ts index c00bbed2c..0bdd9aacd 100644 --- a/cortex-js/src/infrastructure/commanders/ps.command.ts +++ b/cortex-js/src/infrastructure/commanders/ps.command.ts @@ -16,9 +16,15 @@ export class PSCommand extends CommandRunner { super(); } async run(): Promise { + console.log('Running ps command'); + console.time('ps'); return this.usecases .getModels() - .then(console.table) + .then((models) => { + console.table(models); + console.timeEnd('ps'); + } + ) .then(() => this.usecases.isAPIServerOnline()) .then((isOnline) => { if (isOnline) console.log('API server is online'); From c85031ce0ddddf5da22238098f54cca9dc73faf3 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 17:40:41 +0700 Subject: [PATCH 02/64] debug ps command --- cortex-js/src/command.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index e85d7050f..d17438ffa 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -11,27 +11,29 @@ export const asyncLocalStorage = new AsyncLocalStorage(); async function bootstrap() { let telemetryUseCase: TelemetryUsecases | null = null; let contextService: ContextService | null = null; + console.time('CLI'); const app = await CommandFactory.createWithoutRunning(CommandModule, { logger: ['warn', 'error'], - errorHandler: async (error) => { - await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - process.exit(1); - }, - serviceErrorHandler: async (error) => { - await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - process.exit(1); - }, + // errorHandler: async (error) => { + // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // process.exit(1); + // }, + // serviceErrorHandler: async (error) => { + // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // process.exit(1); + // }, }); - telemetryUseCase = await app.resolve(TelemetryUsecases); - contextService = await app.resolve(ContextService); + // telemetryUseCase = await app.resolve(TelemetryUsecases); + // contextService = await app.resolve(ContextService); - telemetryUseCase!.sendCrashReport(); + // telemetryUseCase!.sendCrashReport(); - await contextService!.init(async () => { - contextService!.set('source', TelemetrySource.CLI); - return CommandFactory.runApplication(app); - }); + // await contextService!.init(async () => { + // contextService!.set('source', TelemetrySource.CLI); + await CommandFactory.runApplication(app); + console.timeEnd('CLI'); + // }); } bootstrap(); From 6a9927032c0a732a87a6a7d7097bbf206e6e7992 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 17:41:23 +0700 Subject: [PATCH 03/64] debug ps command --- cortex-js/src/infrastructure/commanders/ps.command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cortex-js/src/infrastructure/commanders/ps.command.ts b/cortex-js/src/infrastructure/commanders/ps.command.ts index 0bdd9aacd..f9e6e1358 100644 --- a/cortex-js/src/infrastructure/commanders/ps.command.ts +++ b/cortex-js/src/infrastructure/commanders/ps.command.ts @@ -7,7 +7,7 @@ import { ContextService } from '../services/context/context.service'; name: 'ps', description: 'Show running models and their status', }) -@SetCommandContext() +// @SetCommandContext() export class PSCommand extends CommandRunner { constructor( private readonly usecases: PSCliUsecases, From 6b25c4e1ac81d0dd408d441a39f01e6533968f3f Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 17:51:06 +0700 Subject: [PATCH 04/64] debug ps command --- cortex-js/src/command.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index d17438ffa..730ffa8e2 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -12,17 +12,17 @@ async function bootstrap() { let telemetryUseCase: TelemetryUsecases | null = null; let contextService: ContextService | null = null; console.time('CLI'); - const app = await CommandFactory.createWithoutRunning(CommandModule, { - logger: ['warn', 'error'], - // errorHandler: async (error) => { - // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // process.exit(1); - // }, - // serviceErrorHandler: async (error) => { - // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // process.exit(1); - // }, - }); + // const app = await CommandFactory.createWithoutRunning(CommandModule, { + // logger: ['warn', 'error'], + // // errorHandler: async (error) => { + // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // // process.exit(1); + // // }, + // // serviceErrorHandler: async (error) => { + // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // // process.exit(1); + // // }, + // }); // telemetryUseCase = await app.resolve(TelemetryUsecases); // contextService = await app.resolve(ContextService); @@ -31,7 +31,8 @@ async function bootstrap() { // await contextService!.init(async () => { // contextService!.set('source', TelemetrySource.CLI); - await CommandFactory.runApplication(app); + // await CommandFactory.runApplication(app); + await CommandFactory.run(CommandModule, ['warn', 'error']); console.timeEnd('CLI'); // }); } From 92d12ae6d681f76e5a16ac763db49d6b13e45c9f Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 18:01:18 +0700 Subject: [PATCH 05/64] debug ps command --- cortex-js/src/command.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index 730ffa8e2..79bd8370c 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -7,7 +7,8 @@ import { AsyncLocalStorage } from 'async_hooks'; import { ContextService } from '@/infrastructure/services/context/context.service'; export const asyncLocalStorage = new AsyncLocalStorage(); - +console.time('test'); +console.log('Running CLI'); async function bootstrap() { let telemetryUseCase: TelemetryUsecases | null = null; let contextService: ContextService | null = null; @@ -34,6 +35,7 @@ async function bootstrap() { // await CommandFactory.runApplication(app); await CommandFactory.run(CommandModule, ['warn', 'error']); console.timeEnd('CLI'); + console.timeEnd('test'); // }); } From 355201957edd0c8aee8e884adb52aa5c32af1980 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 18:55:55 +0700 Subject: [PATCH 06/64] debug ps command --- cortex-js/src/command.module.ts | 198 +++++++++--------- cortex-js/src/command.ts | 4 +- .../infrastructure/commanders/ps.command.ts | 16 +- 3 files changed, 104 insertions(+), 114 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 097590ce4..b538d6b71 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,117 +1,117 @@ import { Module } from '@nestjs/common'; -import { ModelsModule } from './usecases/models/models.module'; -import { DatabaseModule } from './infrastructure/database/database.module'; -import { ConfigModule } from '@nestjs/config'; -import { CortexModule } from './usecases/cortex/cortex.module'; -import { ServeCommand } from './infrastructure/commanders/serve.command'; -import { ModelsCommand } from './infrastructure/commanders/models.command'; -import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; -import { InitCommand } from './infrastructure/commanders/init.command'; -import { HttpModule } from '@nestjs/axios'; -import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; -import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; -import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; -import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; -import { ChatCommand } from './infrastructure/commanders/chat.command'; -import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; -import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; -import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; -import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; -import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; -import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; -import { AssistantsModule } from './usecases/assistants/assistants.module'; -import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; -import { MessagesModule } from './usecases/messages/messages.module'; -import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; +// import { ModelsModule } from './usecases/models/models.module'; +// import { DatabaseModule } from './infrastructure/database/database.module'; +// import { ConfigModule } from '@nestjs/config'; +// import { CortexModule } from './usecases/cortex/cortex.module'; +// import { ServeCommand } from './infrastructure/commanders/serve.command'; +// import { ModelsCommand } from './infrastructure/commanders/models.command'; +// import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; +// import { InitCommand } from './infrastructure/commanders/init.command'; +// import { HttpModule } from '@nestjs/axios'; +// import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; +// import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; +// import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; +// import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; +// import { ChatCommand } from './infrastructure/commanders/chat.command'; +// import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; +// import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; +// import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; +// import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; +// import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; +// import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; +// import { AssistantsModule } from './usecases/assistants/assistants.module'; +// import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; +// import { MessagesModule } from './usecases/messages/messages.module'; +// import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; import { PSCommand } from './infrastructure/commanders/ps.command'; -import { KillCommand } from './infrastructure/commanders/kill.command'; -import { PresetCommand } from './infrastructure/commanders/presets.command'; -import { TelemetryModule } from './usecases/telemetry/telemetry.module'; -import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; -import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; -import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; -import { EventEmitterModule } from '@nestjs/event-emitter'; -import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; -import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; -import { ContextModule } from './infrastructure/services/context/context.module'; -import { ExtensionsModule } from './extensions/extensions.module'; -import { ConfigsCommand } from './infrastructure/commanders/configs.command'; -import { EnginesCommand } from './infrastructure/commanders/engines.command'; -import { ConfigsModule } from './usecases/configs/configs.module'; -import { EnginesModule } from './usecases/engines/engines.module'; -import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; -import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; -import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; -import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; -import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; +// import { KillCommand } from './infrastructure/commanders/kill.command'; +// import { PresetCommand } from './infrastructure/commanders/presets.command'; +// import { TelemetryModule } from './usecases/telemetry/telemetry.module'; +// import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; +// import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; +// import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; +// import { EventEmitterModule } from '@nestjs/event-emitter'; +// import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; +// import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; +// import { ContextModule } from './infrastructure/services/context/context.module'; +// import { ExtensionsModule } from './extensions/extensions.module'; +// import { ConfigsCommand } from './infrastructure/commanders/configs.command'; +// import { EnginesCommand } from './infrastructure/commanders/engines.command'; +// import { ConfigsModule } from './usecases/configs/configs.module'; +// import { EnginesModule } from './usecases/engines/engines.module'; +// import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; +// import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; +// import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; +// import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; +// import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; @Module({ imports: [ - ConfigModule.forRoot({ - isGlobal: true, - envFilePath: - process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', - }), - EventEmitterModule.forRoot(), - DatabaseModule, - ModelsModule, - CortexModule, - ExtensionModule, - HttpModule, - CliUsecasesModule, - AssistantsModule, - MessagesModule, - FileManagerModule, - TelemetryModule, - ContextModule, - DownloadManagerModule, - ExtensionsModule, - ConfigsModule, - EnginesModule, + // ConfigModule.forRoot({ + // isGlobal: true, + // envFilePath: + // process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', + // }), + // EventEmitterModule.forRoot(), + // DatabaseModule, + // ModelsModule, + // CortexModule, + // ExtensionModule, + // HttpModule, + // CliUsecasesModule, + // AssistantsModule, + // MessagesModule, + // FileManagerModule, + // TelemetryModule, + // ContextModule, + // DownloadManagerModule, + // ExtensionsModule, + // ConfigsModule, + // EnginesModule, ], providers: [ - CortexCommand, - ModelsCommand, - ServeCommand, - ChatCommand, - InitCommand, + // CortexCommand, + // ModelsCommand, + // ServeCommand, + // ChatCommand, + // InitCommand, PSCommand, - KillCommand, - PresetCommand, - EmbeddingCommand, - BenchmarkCommand, - EnginesCommand, + // KillCommand, + // PresetCommand, + // EmbeddingCommand, + // BenchmarkCommand, + // EnginesCommand, - // Questions - InitRunModeQuestions, + // // Questions + // InitRunModeQuestions, - // Model commands - ModelStartCommand, - ModelStopCommand, - ModelListCommand, - ModelGetCommand, - ModelRemoveCommand, - ModelPullCommand, - ModelUpdateCommand, + // // Model commands + // ModelStartCommand, + // ModelStopCommand, + // ModelListCommand, + // ModelGetCommand, + // ModelRemoveCommand, + // ModelPullCommand, + // ModelUpdateCommand, - // Shortcuts - RunCommand, + // // Shortcuts + // RunCommand, - // Telemetry - TelemetryCommand, + // // Telemetry + // TelemetryCommand, - // Serve - ServeStopCommand, + // // Serve + // ServeStopCommand, - // Configs - ConfigsCommand, - ConfigsGetCommand, - ConfigsListCommand, - ConfigsSetCommand, + // // Configs + // ConfigsCommand, + // ConfigsGetCommand, + // ConfigsListCommand, + // ConfigsSetCommand, - // Engines - EnginesListCommand, - EnginesGetCommand, + // // Engines + // EnginesListCommand, + // EnginesGetCommand, ], }) export class CommandModule {} diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index 79bd8370c..c538f509a 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -3,10 +3,10 @@ import { CommandFactory } from 'nest-commander'; import { CommandModule } from './command.module'; import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; import { TelemetrySource } from './domain/telemetry/telemetry.interface'; -import { AsyncLocalStorage } from 'async_hooks'; +// import { AsyncLocalStorage } from 'async_hooks'; import { ContextService } from '@/infrastructure/services/context/context.service'; -export const asyncLocalStorage = new AsyncLocalStorage(); +// export const asyncLocalStorage = new AsyncLocalStorage(); console.time('test'); console.log('Running CLI'); async function bootstrap() { diff --git a/cortex-js/src/infrastructure/commanders/ps.command.ts b/cortex-js/src/infrastructure/commanders/ps.command.ts index f9e6e1358..7bf0449fd 100644 --- a/cortex-js/src/infrastructure/commanders/ps.command.ts +++ b/cortex-js/src/infrastructure/commanders/ps.command.ts @@ -10,24 +10,14 @@ import { ContextService } from '../services/context/context.service'; // @SetCommandContext() export class PSCommand extends CommandRunner { constructor( - private readonly usecases: PSCliUsecases, - readonly contextService: ContextService, + // private readonly usecases: PSCliUsecases, + // readonly contextService: ContextService, ) { super(); } async run(): Promise { console.log('Running ps command'); console.time('ps'); - return this.usecases - .getModels() - .then((models) => { - console.table(models); - console.timeEnd('ps'); - } - ) - .then(() => this.usecases.isAPIServerOnline()) - .then((isOnline) => { - if (isOnline) console.log('API server is online'); - }); + return; } } From 112b3ac05fdfb34a73622643bd5a6fab1c2a84e1 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 20:47:53 +0700 Subject: [PATCH 07/64] revert debug --- cortex-js/src/command.module.ts | 198 +++++++++--------- cortex-js/src/command.ts | 38 ++-- .../infrastructure/commanders/ps.command.ts | 18 +- 3 files changed, 129 insertions(+), 125 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index b538d6b71..097590ce4 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,117 +1,117 @@ import { Module } from '@nestjs/common'; -// import { ModelsModule } from './usecases/models/models.module'; -// import { DatabaseModule } from './infrastructure/database/database.module'; -// import { ConfigModule } from '@nestjs/config'; -// import { CortexModule } from './usecases/cortex/cortex.module'; -// import { ServeCommand } from './infrastructure/commanders/serve.command'; -// import { ModelsCommand } from './infrastructure/commanders/models.command'; -// import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; -// import { InitCommand } from './infrastructure/commanders/init.command'; -// import { HttpModule } from '@nestjs/axios'; -// import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; -// import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; -// import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; -// import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; -// import { ChatCommand } from './infrastructure/commanders/chat.command'; -// import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; -// import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; -// import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; -// import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; -// import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; -// import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; -// import { AssistantsModule } from './usecases/assistants/assistants.module'; -// import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; -// import { MessagesModule } from './usecases/messages/messages.module'; -// import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; +import { ModelsModule } from './usecases/models/models.module'; +import { DatabaseModule } from './infrastructure/database/database.module'; +import { ConfigModule } from '@nestjs/config'; +import { CortexModule } from './usecases/cortex/cortex.module'; +import { ServeCommand } from './infrastructure/commanders/serve.command'; +import { ModelsCommand } from './infrastructure/commanders/models.command'; +import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; +import { InitCommand } from './infrastructure/commanders/init.command'; +import { HttpModule } from '@nestjs/axios'; +import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; +import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; +import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; +import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; +import { ChatCommand } from './infrastructure/commanders/chat.command'; +import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; +import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; +import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; +import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; +import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; +import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; +import { AssistantsModule } from './usecases/assistants/assistants.module'; +import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; +import { MessagesModule } from './usecases/messages/messages.module'; +import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; import { PSCommand } from './infrastructure/commanders/ps.command'; -// import { KillCommand } from './infrastructure/commanders/kill.command'; -// import { PresetCommand } from './infrastructure/commanders/presets.command'; -// import { TelemetryModule } from './usecases/telemetry/telemetry.module'; -// import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; -// import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; -// import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; -// import { EventEmitterModule } from '@nestjs/event-emitter'; -// import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; -// import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; -// import { ContextModule } from './infrastructure/services/context/context.module'; -// import { ExtensionsModule } from './extensions/extensions.module'; -// import { ConfigsCommand } from './infrastructure/commanders/configs.command'; -// import { EnginesCommand } from './infrastructure/commanders/engines.command'; -// import { ConfigsModule } from './usecases/configs/configs.module'; -// import { EnginesModule } from './usecases/engines/engines.module'; -// import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; -// import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; -// import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; -// import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; -// import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; +import { KillCommand } from './infrastructure/commanders/kill.command'; +import { PresetCommand } from './infrastructure/commanders/presets.command'; +import { TelemetryModule } from './usecases/telemetry/telemetry.module'; +import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; +import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; +import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; +import { EventEmitterModule } from '@nestjs/event-emitter'; +import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; +import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; +import { ContextModule } from './infrastructure/services/context/context.module'; +import { ExtensionsModule } from './extensions/extensions.module'; +import { ConfigsCommand } from './infrastructure/commanders/configs.command'; +import { EnginesCommand } from './infrastructure/commanders/engines.command'; +import { ConfigsModule } from './usecases/configs/configs.module'; +import { EnginesModule } from './usecases/engines/engines.module'; +import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; +import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; +import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; +import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; +import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; @Module({ imports: [ - // ConfigModule.forRoot({ - // isGlobal: true, - // envFilePath: - // process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', - // }), - // EventEmitterModule.forRoot(), - // DatabaseModule, - // ModelsModule, - // CortexModule, - // ExtensionModule, - // HttpModule, - // CliUsecasesModule, - // AssistantsModule, - // MessagesModule, - // FileManagerModule, - // TelemetryModule, - // ContextModule, - // DownloadManagerModule, - // ExtensionsModule, - // ConfigsModule, - // EnginesModule, + ConfigModule.forRoot({ + isGlobal: true, + envFilePath: + process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', + }), + EventEmitterModule.forRoot(), + DatabaseModule, + ModelsModule, + CortexModule, + ExtensionModule, + HttpModule, + CliUsecasesModule, + AssistantsModule, + MessagesModule, + FileManagerModule, + TelemetryModule, + ContextModule, + DownloadManagerModule, + ExtensionsModule, + ConfigsModule, + EnginesModule, ], providers: [ - // CortexCommand, - // ModelsCommand, - // ServeCommand, - // ChatCommand, - // InitCommand, + CortexCommand, + ModelsCommand, + ServeCommand, + ChatCommand, + InitCommand, PSCommand, - // KillCommand, - // PresetCommand, - // EmbeddingCommand, - // BenchmarkCommand, - // EnginesCommand, + KillCommand, + PresetCommand, + EmbeddingCommand, + BenchmarkCommand, + EnginesCommand, - // // Questions - // InitRunModeQuestions, + // Questions + InitRunModeQuestions, - // // Model commands - // ModelStartCommand, - // ModelStopCommand, - // ModelListCommand, - // ModelGetCommand, - // ModelRemoveCommand, - // ModelPullCommand, - // ModelUpdateCommand, + // Model commands + ModelStartCommand, + ModelStopCommand, + ModelListCommand, + ModelGetCommand, + ModelRemoveCommand, + ModelPullCommand, + ModelUpdateCommand, - // // Shortcuts - // RunCommand, + // Shortcuts + RunCommand, - // // Telemetry - // TelemetryCommand, + // Telemetry + TelemetryCommand, - // // Serve - // ServeStopCommand, + // Serve + ServeStopCommand, - // // Configs - // ConfigsCommand, - // ConfigsGetCommand, - // ConfigsListCommand, - // ConfigsSetCommand, + // Configs + ConfigsCommand, + ConfigsGetCommand, + ConfigsListCommand, + ConfigsSetCommand, - // // Engines - // EnginesListCommand, - // EnginesGetCommand, + // Engines + EnginesListCommand, + EnginesGetCommand, ], }) export class CommandModule {} diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index c538f509a..abd09dc25 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -13,30 +13,30 @@ async function bootstrap() { let telemetryUseCase: TelemetryUsecases | null = null; let contextService: ContextService | null = null; console.time('CLI'); - // const app = await CommandFactory.createWithoutRunning(CommandModule, { - // logger: ['warn', 'error'], - // // errorHandler: async (error) => { - // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // // process.exit(1); - // // }, - // // serviceErrorHandler: async (error) => { - // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // // process.exit(1); - // // }, - // }); + const app = await CommandFactory.createWithoutRunning(CommandModule, { + logger: ['warn', 'error'], + errorHandler: async (error) => { + await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + process.exit(1); + }, + serviceErrorHandler: async (error) => { + await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + process.exit(1); + }, + }); - // telemetryUseCase = await app.resolve(TelemetryUsecases); - // contextService = await app.resolve(ContextService); + telemetryUseCase = await app.resolve(TelemetryUsecases); + contextService = await app.resolve(ContextService); - // telemetryUseCase!.sendCrashReport(); + telemetryUseCase!.sendCrashReport(); - // await contextService!.init(async () => { - // contextService!.set('source', TelemetrySource.CLI); - // await CommandFactory.runApplication(app); - await CommandFactory.run(CommandModule, ['warn', 'error']); + await contextService!.init(async () => { + contextService!.set('source', TelemetrySource.CLI); + await CommandFactory.runApplication(app); + // await CommandFactory.run(CommandModule, ['warn', 'error']); console.timeEnd('CLI'); console.timeEnd('test'); - // }); + }); } bootstrap(); diff --git a/cortex-js/src/infrastructure/commanders/ps.command.ts b/cortex-js/src/infrastructure/commanders/ps.command.ts index 7bf0449fd..1f803e6e4 100644 --- a/cortex-js/src/infrastructure/commanders/ps.command.ts +++ b/cortex-js/src/infrastructure/commanders/ps.command.ts @@ -7,17 +7,21 @@ import { ContextService } from '../services/context/context.service'; name: 'ps', description: 'Show running models and their status', }) -// @SetCommandContext() +@SetCommandContext() export class PSCommand extends CommandRunner { constructor( - // private readonly usecases: PSCliUsecases, - // readonly contextService: ContextService, + private readonly usecases: PSCliUsecases, + readonly contextService: ContextService, ) { super(); } async run(): Promise { - console.log('Running ps command'); - console.time('ps'); - return; + return this.usecases + .getModels() + .then(console.table) + .then(() => this.usecases.isAPIServerOnline()) + .then((isOnline) => { + if (isOnline) console.log('API server is online'); + }); } -} +} \ No newline at end of file From 5b83a7aeec19f283c2ea96903cc7cc80534ad222 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 20:53:53 +0700 Subject: [PATCH 08/64] revert debug --- cortex-js/src/infrastructure/commanders/ps.command.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/cortex-js/src/infrastructure/commanders/ps.command.ts b/cortex-js/src/infrastructure/commanders/ps.command.ts index 1f803e6e4..78c8cf703 100644 --- a/cortex-js/src/infrastructure/commanders/ps.command.ts +++ b/cortex-js/src/infrastructure/commanders/ps.command.ts @@ -10,18 +10,10 @@ import { ContextService } from '../services/context/context.service'; @SetCommandContext() export class PSCommand extends CommandRunner { constructor( - private readonly usecases: PSCliUsecases, - readonly contextService: ContextService, ) { super(); } async run(): Promise { - return this.usecases - .getModels() - .then(console.table) - .then(() => this.usecases.isAPIServerOnline()) - .then((isOnline) => { - if (isOnline) console.log('API server is online'); - }); + return; } } \ No newline at end of file From 2aa52763c100f61ee9d07f21527ee41ed6dd1ef4 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 20:57:53 +0700 Subject: [PATCH 09/64] remove database module --- cortex-js/src/command.module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 097590ce4..c93e5ab16 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,6 +1,6 @@ import { Module } from '@nestjs/common'; import { ModelsModule } from './usecases/models/models.module'; -import { DatabaseModule } from './infrastructure/database/database.module'; +// import { DatabaseModule } from './infrastructure/database/database.module'; import { ConfigModule } from '@nestjs/config'; import { CortexModule } from './usecases/cortex/cortex.module'; import { ServeCommand } from './infrastructure/commanders/serve.command'; @@ -53,7 +53,7 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', }), EventEmitterModule.forRoot(), - DatabaseModule, + // DatabaseModule, ModelsModule, CortexModule, ExtensionModule, From 7e664a4df06fa5f23de0ade43ac2fede51ad47ac Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 21:02:34 +0700 Subject: [PATCH 10/64] remove database module --- cortex-js/src/command.module.ts | 106 ++++++++++++++++---------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index c93e5ab16..8a5112863 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -47,71 +47,71 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g @Module({ imports: [ - ConfigModule.forRoot({ - isGlobal: true, - envFilePath: - process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', - }), - EventEmitterModule.forRoot(), - // DatabaseModule, - ModelsModule, - CortexModule, - ExtensionModule, - HttpModule, - CliUsecasesModule, - AssistantsModule, - MessagesModule, - FileManagerModule, + // ConfigModule.forRoot({ + // isGlobal: true, + // envFilePath: + // process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', + // }), + // EventEmitterModule.forRoot(), + // // DatabaseModule, + // ModelsModule, + // CortexModule, + // ExtensionModule, + // HttpModule, + // CliUsecasesModule, + // AssistantsModule, + // MessagesModule, + // FileManagerModule, TelemetryModule, ContextModule, - DownloadManagerModule, - ExtensionsModule, - ConfigsModule, - EnginesModule, + // DownloadManagerModule, + // ExtensionsModule, + // ConfigsModule, + // EnginesModule, ], providers: [ - CortexCommand, - ModelsCommand, - ServeCommand, - ChatCommand, - InitCommand, + // CortexCommand, + // ModelsCommand, + // ServeCommand, + // ChatCommand, + // InitCommand, PSCommand, - KillCommand, - PresetCommand, - EmbeddingCommand, - BenchmarkCommand, - EnginesCommand, + // KillCommand, + // PresetCommand, + // EmbeddingCommand, + // BenchmarkCommand, + // EnginesCommand, - // Questions - InitRunModeQuestions, + // // Questions + // InitRunModeQuestions, - // Model commands - ModelStartCommand, - ModelStopCommand, - ModelListCommand, - ModelGetCommand, - ModelRemoveCommand, - ModelPullCommand, - ModelUpdateCommand, + // // Model commands + // ModelStartCommand, + // ModelStopCommand, + // ModelListCommand, + // ModelGetCommand, + // ModelRemoveCommand, + // ModelPullCommand, + // ModelUpdateCommand, - // Shortcuts - RunCommand, + // // Shortcuts + // RunCommand, - // Telemetry - TelemetryCommand, + // // Telemetry + // TelemetryCommand, - // Serve - ServeStopCommand, + // // Serve + // ServeStopCommand, - // Configs - ConfigsCommand, - ConfigsGetCommand, - ConfigsListCommand, - ConfigsSetCommand, + // // Configs + // ConfigsCommand, + // ConfigsGetCommand, + // ConfigsListCommand, + // ConfigsSetCommand, - // Engines - EnginesListCommand, - EnginesGetCommand, + // // Engines + // EnginesListCommand, + // EnginesGetCommand, ], }) export class CommandModule {} From 582e4e62ebfea55d7e3fbbbe97fd43ecda177afd Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 21:04:49 +0700 Subject: [PATCH 11/64] remove telemetry --- cortex-js/src/command.module.ts | 108 ++++++++++++++++---------------- cortex-js/src/command.ts | 38 +++++------ 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 8a5112863..097590ce4 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,6 +1,6 @@ import { Module } from '@nestjs/common'; import { ModelsModule } from './usecases/models/models.module'; -// import { DatabaseModule } from './infrastructure/database/database.module'; +import { DatabaseModule } from './infrastructure/database/database.module'; import { ConfigModule } from '@nestjs/config'; import { CortexModule } from './usecases/cortex/cortex.module'; import { ServeCommand } from './infrastructure/commanders/serve.command'; @@ -47,71 +47,71 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g @Module({ imports: [ - // ConfigModule.forRoot({ - // isGlobal: true, - // envFilePath: - // process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', - // }), - // EventEmitterModule.forRoot(), - // // DatabaseModule, - // ModelsModule, - // CortexModule, - // ExtensionModule, - // HttpModule, - // CliUsecasesModule, - // AssistantsModule, - // MessagesModule, - // FileManagerModule, + ConfigModule.forRoot({ + isGlobal: true, + envFilePath: + process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', + }), + EventEmitterModule.forRoot(), + DatabaseModule, + ModelsModule, + CortexModule, + ExtensionModule, + HttpModule, + CliUsecasesModule, + AssistantsModule, + MessagesModule, + FileManagerModule, TelemetryModule, ContextModule, - // DownloadManagerModule, - // ExtensionsModule, - // ConfigsModule, - // EnginesModule, + DownloadManagerModule, + ExtensionsModule, + ConfigsModule, + EnginesModule, ], providers: [ - // CortexCommand, - // ModelsCommand, - // ServeCommand, - // ChatCommand, - // InitCommand, + CortexCommand, + ModelsCommand, + ServeCommand, + ChatCommand, + InitCommand, PSCommand, - // KillCommand, - // PresetCommand, - // EmbeddingCommand, - // BenchmarkCommand, - // EnginesCommand, + KillCommand, + PresetCommand, + EmbeddingCommand, + BenchmarkCommand, + EnginesCommand, - // // Questions - // InitRunModeQuestions, + // Questions + InitRunModeQuestions, - // // Model commands - // ModelStartCommand, - // ModelStopCommand, - // ModelListCommand, - // ModelGetCommand, - // ModelRemoveCommand, - // ModelPullCommand, - // ModelUpdateCommand, + // Model commands + ModelStartCommand, + ModelStopCommand, + ModelListCommand, + ModelGetCommand, + ModelRemoveCommand, + ModelPullCommand, + ModelUpdateCommand, - // // Shortcuts - // RunCommand, + // Shortcuts + RunCommand, - // // Telemetry - // TelemetryCommand, + // Telemetry + TelemetryCommand, - // // Serve - // ServeStopCommand, + // Serve + ServeStopCommand, - // // Configs - // ConfigsCommand, - // ConfigsGetCommand, - // ConfigsListCommand, - // ConfigsSetCommand, + // Configs + ConfigsCommand, + ConfigsGetCommand, + ConfigsListCommand, + ConfigsSetCommand, - // // Engines - // EnginesListCommand, - // EnginesGetCommand, + // Engines + EnginesListCommand, + EnginesGetCommand, ], }) export class CommandModule {} diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index abd09dc25..c538f509a 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -13,30 +13,30 @@ async function bootstrap() { let telemetryUseCase: TelemetryUsecases | null = null; let contextService: ContextService | null = null; console.time('CLI'); - const app = await CommandFactory.createWithoutRunning(CommandModule, { - logger: ['warn', 'error'], - errorHandler: async (error) => { - await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - process.exit(1); - }, - serviceErrorHandler: async (error) => { - await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - process.exit(1); - }, - }); + // const app = await CommandFactory.createWithoutRunning(CommandModule, { + // logger: ['warn', 'error'], + // // errorHandler: async (error) => { + // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // // process.exit(1); + // // }, + // // serviceErrorHandler: async (error) => { + // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // // process.exit(1); + // // }, + // }); - telemetryUseCase = await app.resolve(TelemetryUsecases); - contextService = await app.resolve(ContextService); + // telemetryUseCase = await app.resolve(TelemetryUsecases); + // contextService = await app.resolve(ContextService); - telemetryUseCase!.sendCrashReport(); + // telemetryUseCase!.sendCrashReport(); - await contextService!.init(async () => { - contextService!.set('source', TelemetrySource.CLI); - await CommandFactory.runApplication(app); - // await CommandFactory.run(CommandModule, ['warn', 'error']); + // await contextService!.init(async () => { + // contextService!.set('source', TelemetrySource.CLI); + // await CommandFactory.runApplication(app); + await CommandFactory.run(CommandModule, ['warn', 'error']); console.timeEnd('CLI'); console.timeEnd('test'); - }); + // }); } bootstrap(); From 6c0d5dbc6bdb11efce9a0579601d7bf351200d06 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 21:05:13 +0700 Subject: [PATCH 12/64] remove telemetry --- cortex-js/src/infrastructure/commanders/ps.command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cortex-js/src/infrastructure/commanders/ps.command.ts b/cortex-js/src/infrastructure/commanders/ps.command.ts index 78c8cf703..198bfaf77 100644 --- a/cortex-js/src/infrastructure/commanders/ps.command.ts +++ b/cortex-js/src/infrastructure/commanders/ps.command.ts @@ -7,7 +7,7 @@ import { ContextService } from '../services/context/context.service'; name: 'ps', description: 'Show running models and their status', }) -@SetCommandContext() +// @SetCommandContext() export class PSCommand extends CommandRunner { constructor( ) { From a5e67f757fd7b988eb821ad0d85c2e68e5db63e2 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 21:08:04 +0700 Subject: [PATCH 13/64] remove telemetry --- cortex-js/src/command.module.ts | 190 ++++++++++++++++---------------- cortex-js/src/command.ts | 38 +++---- 2 files changed, 114 insertions(+), 114 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 097590ce4..49f0b28cd 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,117 +1,117 @@ import { Module } from '@nestjs/common'; -import { ModelsModule } from './usecases/models/models.module'; -import { DatabaseModule } from './infrastructure/database/database.module'; -import { ConfigModule } from '@nestjs/config'; -import { CortexModule } from './usecases/cortex/cortex.module'; -import { ServeCommand } from './infrastructure/commanders/serve.command'; -import { ModelsCommand } from './infrastructure/commanders/models.command'; -import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; -import { InitCommand } from './infrastructure/commanders/init.command'; -import { HttpModule } from '@nestjs/axios'; -import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; -import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; -import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; -import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; -import { ChatCommand } from './infrastructure/commanders/chat.command'; -import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; -import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; -import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; -import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; -import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; -import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; -import { AssistantsModule } from './usecases/assistants/assistants.module'; -import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; -import { MessagesModule } from './usecases/messages/messages.module'; -import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; +// import { ModelsModule } from './usecases/models/models.module'; +// // import { DatabaseModule } from './infrastructure/database/database.module'; +// import { ConfigModule } from '@nestjs/config'; +// import { CortexModule } from './usecases/cortex/cortex.module'; +// import { ServeCommand } from './infrastructure/commanders/serve.command'; +// import { ModelsCommand } from './infrastructure/commanders/models.command'; +// import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; +// import { InitCommand } from './infrastructure/commanders/init.command'; +// import { HttpModule } from '@nestjs/axios'; +// import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; +// import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; +// import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; +// import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; +// import { ChatCommand } from './infrastructure/commanders/chat.command'; +// import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; +// import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; +// import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; +// import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; +// import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; +// import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; +// import { AssistantsModule } from './usecases/assistants/assistants.module'; +// import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; +// import { MessagesModule } from './usecases/messages/messages.module'; +// import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; import { PSCommand } from './infrastructure/commanders/ps.command'; -import { KillCommand } from './infrastructure/commanders/kill.command'; -import { PresetCommand } from './infrastructure/commanders/presets.command'; +// import { KillCommand } from './infrastructure/commanders/kill.command'; +// import { PresetCommand } from './infrastructure/commanders/presets.command'; import { TelemetryModule } from './usecases/telemetry/telemetry.module'; -import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; -import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; -import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; -import { EventEmitterModule } from '@nestjs/event-emitter'; -import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; -import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; +// import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; +// import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; +// import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; +// import { EventEmitterModule } from '@nestjs/event-emitter'; +// import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; +// import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; import { ContextModule } from './infrastructure/services/context/context.module'; -import { ExtensionsModule } from './extensions/extensions.module'; -import { ConfigsCommand } from './infrastructure/commanders/configs.command'; -import { EnginesCommand } from './infrastructure/commanders/engines.command'; -import { ConfigsModule } from './usecases/configs/configs.module'; -import { EnginesModule } from './usecases/engines/engines.module'; -import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; -import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; -import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; -import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; -import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; +// import { ExtensionsModule } from './extensions/extensions.module'; +// import { ConfigsCommand } from './infrastructure/commanders/configs.command'; +// import { EnginesCommand } from './infrastructure/commanders/engines.command'; +// import { ConfigsModule } from './usecases/configs/configs.module'; +// import { EnginesModule } from './usecases/engines/engines.module'; +// import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; +// import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; +// import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; +// import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; +// import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; @Module({ imports: [ - ConfigModule.forRoot({ - isGlobal: true, - envFilePath: - process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', - }), - EventEmitterModule.forRoot(), - DatabaseModule, - ModelsModule, - CortexModule, - ExtensionModule, - HttpModule, - CliUsecasesModule, - AssistantsModule, - MessagesModule, - FileManagerModule, + // ConfigModule.forRoot({ + // isGlobal: true, + // envFilePath: + // process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', + // }), + // EventEmitterModule.forRoot(), + // // DatabaseModule, + // ModelsModule, + // CortexModule, + // ExtensionModule, + // HttpModule, + // CliUsecasesModule, + // AssistantsModule, + // MessagesModule, + // FileManagerModule, TelemetryModule, ContextModule, - DownloadManagerModule, - ExtensionsModule, - ConfigsModule, - EnginesModule, + // DownloadManagerModule, + // ExtensionsModule, + // ConfigsModule, + // EnginesModule, ], providers: [ - CortexCommand, - ModelsCommand, - ServeCommand, - ChatCommand, - InitCommand, + // CortexCommand, + // ModelsCommand, + // ServeCommand, + // ChatCommand, + // InitCommand, PSCommand, - KillCommand, - PresetCommand, - EmbeddingCommand, - BenchmarkCommand, - EnginesCommand, + // KillCommand, + // PresetCommand, + // EmbeddingCommand, + // BenchmarkCommand, + // EnginesCommand, - // Questions - InitRunModeQuestions, + // // Questions + // InitRunModeQuestions, - // Model commands - ModelStartCommand, - ModelStopCommand, - ModelListCommand, - ModelGetCommand, - ModelRemoveCommand, - ModelPullCommand, - ModelUpdateCommand, + // // Model commands + // ModelStartCommand, + // ModelStopCommand, + // ModelListCommand, + // ModelGetCommand, + // ModelRemoveCommand, + // ModelPullCommand, + // ModelUpdateCommand, - // Shortcuts - RunCommand, + // // Shortcuts + // RunCommand, - // Telemetry - TelemetryCommand, + // // Telemetry + // TelemetryCommand, - // Serve - ServeStopCommand, + // // Serve + // ServeStopCommand, - // Configs - ConfigsCommand, - ConfigsGetCommand, - ConfigsListCommand, - ConfigsSetCommand, + // // Configs + // ConfigsCommand, + // ConfigsGetCommand, + // ConfigsListCommand, + // ConfigsSetCommand, - // Engines - EnginesListCommand, - EnginesGetCommand, + // // Engines + // EnginesListCommand, + // EnginesGetCommand, ], }) export class CommandModule {} diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index c538f509a..abd09dc25 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -13,30 +13,30 @@ async function bootstrap() { let telemetryUseCase: TelemetryUsecases | null = null; let contextService: ContextService | null = null; console.time('CLI'); - // const app = await CommandFactory.createWithoutRunning(CommandModule, { - // logger: ['warn', 'error'], - // // errorHandler: async (error) => { - // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // // process.exit(1); - // // }, - // // serviceErrorHandler: async (error) => { - // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // // process.exit(1); - // // }, - // }); + const app = await CommandFactory.createWithoutRunning(CommandModule, { + logger: ['warn', 'error'], + errorHandler: async (error) => { + await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + process.exit(1); + }, + serviceErrorHandler: async (error) => { + await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + process.exit(1); + }, + }); - // telemetryUseCase = await app.resolve(TelemetryUsecases); - // contextService = await app.resolve(ContextService); + telemetryUseCase = await app.resolve(TelemetryUsecases); + contextService = await app.resolve(ContextService); - // telemetryUseCase!.sendCrashReport(); + telemetryUseCase!.sendCrashReport(); - // await contextService!.init(async () => { - // contextService!.set('source', TelemetrySource.CLI); - // await CommandFactory.runApplication(app); - await CommandFactory.run(CommandModule, ['warn', 'error']); + await contextService!.init(async () => { + contextService!.set('source', TelemetrySource.CLI); + await CommandFactory.runApplication(app); + // await CommandFactory.run(CommandModule, ['warn', 'error']); console.timeEnd('CLI'); console.timeEnd('test'); - // }); + }); } bootstrap(); From 400be006f46facffea5a403f4fc1118ec593ca9c Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 21:10:07 +0700 Subject: [PATCH 14/64] remove telemetry --- cortex-js/src/command.module.ts | 4 +-- cortex-js/src/command.ts | 46 ++++++++++++++++----------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 49f0b28cd..ec6ead6a2 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -62,8 +62,8 @@ import { ContextModule } from './infrastructure/services/context/context.module' // AssistantsModule, // MessagesModule, // FileManagerModule, - TelemetryModule, - ContextModule, + // TelemetryModule, + // ContextModule, // DownloadManagerModule, // ExtensionsModule, // ConfigsModule, diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index abd09dc25..f60330de4 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -1,42 +1,42 @@ #!/usr/bin/env node --no-warnings import { CommandFactory } from 'nest-commander'; import { CommandModule } from './command.module'; -import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; +// import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; import { TelemetrySource } from './domain/telemetry/telemetry.interface'; // import { AsyncLocalStorage } from 'async_hooks'; -import { ContextService } from '@/infrastructure/services/context/context.service'; +// import { ContextService } from '@/infrastructure/services/context/context.service'; // export const asyncLocalStorage = new AsyncLocalStorage(); console.time('test'); console.log('Running CLI'); async function bootstrap() { - let telemetryUseCase: TelemetryUsecases | null = null; - let contextService: ContextService | null = null; + // let telemetryUseCase: TelemetryUsecases | null = null; + // let contextService: ContextService | null = null; console.time('CLI'); - const app = await CommandFactory.createWithoutRunning(CommandModule, { - logger: ['warn', 'error'], - errorHandler: async (error) => { - await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - process.exit(1); - }, - serviceErrorHandler: async (error) => { - await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - process.exit(1); - }, - }); + // const app = await CommandFactory.createWithoutRunning(CommandModule, { + // logger: ['warn', 'error'], + // // errorHandler: async (error) => { + // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // // process.exit(1); + // // }, + // // serviceErrorHandler: async (error) => { + // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // // process.exit(1); + // // }, + // }); - telemetryUseCase = await app.resolve(TelemetryUsecases); - contextService = await app.resolve(ContextService); + // telemetryUseCase = await app.resolve(TelemetryUsecases); + // contextService = await app.resolve(ContextService); - telemetryUseCase!.sendCrashReport(); + // telemetryUseCase!.sendCrashReport(); - await contextService!.init(async () => { - contextService!.set('source', TelemetrySource.CLI); - await CommandFactory.runApplication(app); - // await CommandFactory.run(CommandModule, ['warn', 'error']); + // await contextService!.init(async () => { + // contextService!.set('source', TelemetrySource.CLI); + // await CommandFactory.runApplication(app); + await CommandFactory.run(CommandModule, ['warn', 'error']); console.timeEnd('CLI'); console.timeEnd('test'); - }); + // }); } bootstrap(); From 740b208a6a00af8926d662f7f2393024c61e17f4 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 21:22:15 +0700 Subject: [PATCH 15/64] remove telemetry --- cortex-js/src/command.module.ts | 2 +- cortex-js/src/command.ts | 44 ++++++++++++++++----------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index ec6ead6a2..5a336c919 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -63,7 +63,7 @@ import { ContextModule } from './infrastructure/services/context/context.module' // MessagesModule, // FileManagerModule, // TelemetryModule, - // ContextModule, + ContextModule, // DownloadManagerModule, // ExtensionsModule, // ConfigsModule, diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index f60330de4..3c61f045f 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -1,42 +1,40 @@ #!/usr/bin/env node --no-warnings import { CommandFactory } from 'nest-commander'; import { CommandModule } from './command.module'; -// import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; +import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; import { TelemetrySource } from './domain/telemetry/telemetry.interface'; -// import { AsyncLocalStorage } from 'async_hooks'; -// import { ContextService } from '@/infrastructure/services/context/context.service'; +import { ContextService } from '@/infrastructure/services/context/context.service'; -// export const asyncLocalStorage = new AsyncLocalStorage(); console.time('test'); console.log('Running CLI'); async function bootstrap() { - // let telemetryUseCase: TelemetryUsecases | null = null; - // let contextService: ContextService | null = null; + let telemetryUseCase: TelemetryUsecases | null = null; + let contextService: ContextService | null = null; console.time('CLI'); - // const app = await CommandFactory.createWithoutRunning(CommandModule, { - // logger: ['warn', 'error'], - // // errorHandler: async (error) => { - // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // // process.exit(1); - // // }, - // // serviceErrorHandler: async (error) => { - // // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // // process.exit(1); - // // }, - // }); + const app = await CommandFactory.createWithoutRunning(CommandModule, { + logger: ['warn', 'error'], + // errorHandler: async (error) => { + // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // process.exit(1); + // }, + // serviceErrorHandler: async (error) => { + // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // process.exit(1); + // }, + }); // telemetryUseCase = await app.resolve(TelemetryUsecases); - // contextService = await app.resolve(ContextService); + contextService = await app.resolve(ContextService); // telemetryUseCase!.sendCrashReport(); - // await contextService!.init(async () => { - // contextService!.set('source', TelemetrySource.CLI); - // await CommandFactory.runApplication(app); - await CommandFactory.run(CommandModule, ['warn', 'error']); + await contextService!.init(async () => { + contextService!.set('source', TelemetrySource.CLI); + await CommandFactory.runApplication(app); + // await CommandFactory.run(CommandModule, ['warn', 'error']); console.timeEnd('CLI'); console.timeEnd('test'); - // }); + }); } bootstrap(); From 32e6a8b260cf32ce382a7cd5ff8be289cfadedbb Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 21:54:13 +0700 Subject: [PATCH 16/64] test --- cortex-js/src/command.module.ts | 2 +- cortex-js/src/command.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 5a336c919..49f0b28cd 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -62,7 +62,7 @@ import { ContextModule } from './infrastructure/services/context/context.module' // AssistantsModule, // MessagesModule, // FileManagerModule, - // TelemetryModule, + TelemetryModule, ContextModule, // DownloadManagerModule, // ExtensionsModule, diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index 3c61f045f..c9c5de408 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -23,15 +23,15 @@ async function bootstrap() { // }, }); - // telemetryUseCase = await app.resolve(TelemetryUsecases); + telemetryUseCase = await app.resolve(TelemetryUsecases); contextService = await app.resolve(ContextService); - // telemetryUseCase!.sendCrashReport(); + telemetryUseCase!.sendCrashReport(); await contextService!.init(async () => { contextService!.set('source', TelemetrySource.CLI); await CommandFactory.runApplication(app); - // await CommandFactory.run(CommandModule, ['warn', 'error']); + await CommandFactory.run(CommandModule, ['warn', 'error']); console.timeEnd('CLI'); console.timeEnd('test'); }); From 000bdf9caf6ca3fd5e6549bfb4cfb9b512dd2878 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 21:59:38 +0700 Subject: [PATCH 17/64] test --- .../src/infrastructure/database/database.module.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index 2e7b3ae85..56f30a770 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -9,16 +9,16 @@ import { FileManagerModule } from '@/infrastructure/services/file-manager/file-m @Module({ imports: [FileManagerModule], providers: [ - ...sqliteDatabaseProviders, - ...threadProviders, - ...assistantProviders, - ...messageProviders, + // ...sqliteDatabaseProviders, + // ...threadProviders, + // ...assistantProviders, + // ...messageProviders, ...telemetryProviders, ], exports: [ - ...threadProviders, - ...assistantProviders, - ...messageProviders, + // ...threadProviders, + // ...assistantProviders, + // ...messageProviders, ...telemetryProviders, ], }) From 120e6657a8cde6a23a40de8e247f4f31b009af64 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 22:01:40 +0700 Subject: [PATCH 18/64] test --- .../src/infrastructure/database/database.module.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index 56f30a770..1332f21ef 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -10,15 +10,15 @@ import { FileManagerModule } from '@/infrastructure/services/file-manager/file-m imports: [FileManagerModule], providers: [ // ...sqliteDatabaseProviders, - // ...threadProviders, - // ...assistantProviders, - // ...messageProviders, + ...threadProviders, + ...assistantProviders, + ...messageProviders, ...telemetryProviders, ], exports: [ - // ...threadProviders, - // ...assistantProviders, - // ...messageProviders, + ...threadProviders, + ...assistantProviders, + ...messageProviders, ...telemetryProviders, ], }) From 093fb3e393ab4aebd9dd9b2807840cc82d3aee5e Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 22:09:28 +0700 Subject: [PATCH 19/64] test --- cortex-js/src/infrastructure/database/database.module.ts | 2 +- .../infrastructure/database/providers/assistant.providers.ts | 2 +- .../src/infrastructure/database/providers/message.providers.ts | 2 +- .../src/infrastructure/database/providers/thread.providers.ts | 2 +- .../src/infrastructure/database/sqlite-database.providers.ts | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index 1332f21ef..2e7b3ae85 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -9,7 +9,7 @@ import { FileManagerModule } from '@/infrastructure/services/file-manager/file-m @Module({ imports: [FileManagerModule], providers: [ - // ...sqliteDatabaseProviders, + ...sqliteDatabaseProviders, ...threadProviders, ...assistantProviders, ...messageProviders, diff --git a/cortex-js/src/infrastructure/database/providers/assistant.providers.ts b/cortex-js/src/infrastructure/database/providers/assistant.providers.ts index fcd341209..e8bea02d4 100644 --- a/cortex-js/src/infrastructure/database/providers/assistant.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/assistant.providers.ts @@ -5,7 +5,7 @@ export const assistantProviders = [ { provide: 'ASSISTANT_REPOSITORY', useFactory: (dataSource: DataSource) => - dataSource.getRepository(AssistantEntity), + dataSource?.getRepository(AssistantEntity), inject: ['DATA_SOURCE'], }, ]; diff --git a/cortex-js/src/infrastructure/database/providers/message.providers.ts b/cortex-js/src/infrastructure/database/providers/message.providers.ts index 51730e5dc..388515aa1 100644 --- a/cortex-js/src/infrastructure/database/providers/message.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/message.providers.ts @@ -5,7 +5,7 @@ export const messageProviders = [ { provide: 'MESSAGE_REPOSITORY', useFactory: (dataSource: DataSource) => - dataSource.getRepository(MessageEntity), + dataSource?.getRepository(MessageEntity), inject: ['DATA_SOURCE'], }, ]; diff --git a/cortex-js/src/infrastructure/database/providers/thread.providers.ts b/cortex-js/src/infrastructure/database/providers/thread.providers.ts index fbe0c4eeb..cc5a84916 100644 --- a/cortex-js/src/infrastructure/database/providers/thread.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/thread.providers.ts @@ -5,7 +5,7 @@ export const threadProviders = [ { provide: 'THREAD_REPOSITORY', useFactory: (dataSource: DataSource) => - dataSource.getRepository(ThreadEntity), + dataSource?.getRepository(ThreadEntity), inject: ['DATA_SOURCE'], }, ]; diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index e76b49b91..bb7bf7781 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -11,6 +11,7 @@ export const sqliteDatabaseProviders = [ provide: 'DATA_SOURCE', inject: [FileManagerService], useFactory: async (fileManagerService: FileManagerService) => { + return null; const dataFolderPath = await fileManagerService.getDataFolderPath(); const sqlitePath = join(dataFolderPath, databaseFile); const dataSource = new DataSource({ From 53827652fe292c11d81f891dc3cb8a512df4cc77 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 22:10:40 +0700 Subject: [PATCH 20/64] test --- .../src/infrastructure/database/sqlite-database.providers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index bb7bf7781..e76b49b91 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -11,7 +11,6 @@ export const sqliteDatabaseProviders = [ provide: 'DATA_SOURCE', inject: [FileManagerService], useFactory: async (fileManagerService: FileManagerService) => { - return null; const dataFolderPath = await fileManagerService.getDataFolderPath(); const sqlitePath = join(dataFolderPath, databaseFile); const dataSource = new DataSource({ From 21ba088fe0e9f2f338a2f3aad5eb90940e4557c6 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 22:16:29 +0700 Subject: [PATCH 21/64] test --- cortex-js/src/command.ts | 16 ++++++++-------- .../src/infrastructure/commanders/ps.command.ts | 12 ++++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index c9c5de408..2c0c912ae 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -13,14 +13,14 @@ async function bootstrap() { console.time('CLI'); const app = await CommandFactory.createWithoutRunning(CommandModule, { logger: ['warn', 'error'], - // errorHandler: async (error) => { - // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // process.exit(1); - // }, - // serviceErrorHandler: async (error) => { - // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // process.exit(1); - // }, + errorHandler: async (error) => { + await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + process.exit(1); + }, + serviceErrorHandler: async (error) => { + await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + process.exit(1); + }, }); telemetryUseCase = await app.resolve(TelemetryUsecases); diff --git a/cortex-js/src/infrastructure/commanders/ps.command.ts b/cortex-js/src/infrastructure/commanders/ps.command.ts index 198bfaf77..1f803e6e4 100644 --- a/cortex-js/src/infrastructure/commanders/ps.command.ts +++ b/cortex-js/src/infrastructure/commanders/ps.command.ts @@ -7,13 +7,21 @@ import { ContextService } from '../services/context/context.service'; name: 'ps', description: 'Show running models and their status', }) -// @SetCommandContext() +@SetCommandContext() export class PSCommand extends CommandRunner { constructor( + private readonly usecases: PSCliUsecases, + readonly contextService: ContextService, ) { super(); } async run(): Promise { - return; + return this.usecases + .getModels() + .then(console.table) + .then(() => this.usecases.isAPIServerOnline()) + .then((isOnline) => { + if (isOnline) console.log('API server is online'); + }); } } \ No newline at end of file From bbacb4481153809d420446feff58b54dc3514f9e Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 22:28:54 +0700 Subject: [PATCH 22/64] test --- cortex-js/src/command.module.ts | 190 ++++++++++++++++---------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 49f0b28cd..fca8b9597 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,117 +1,117 @@ import { Module } from '@nestjs/common'; -// import { ModelsModule } from './usecases/models/models.module'; -// // import { DatabaseModule } from './infrastructure/database/database.module'; -// import { ConfigModule } from '@nestjs/config'; -// import { CortexModule } from './usecases/cortex/cortex.module'; -// import { ServeCommand } from './infrastructure/commanders/serve.command'; -// import { ModelsCommand } from './infrastructure/commanders/models.command'; -// import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; -// import { InitCommand } from './infrastructure/commanders/init.command'; -// import { HttpModule } from '@nestjs/axios'; -// import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; -// import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; -// import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; -// import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; -// import { ChatCommand } from './infrastructure/commanders/chat.command'; -// import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; -// import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; -// import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; -// import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; -// import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; -// import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; -// import { AssistantsModule } from './usecases/assistants/assistants.module'; -// import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; -// import { MessagesModule } from './usecases/messages/messages.module'; -// import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; +import { ModelsModule } from './usecases/models/models.module'; +import { DatabaseModule } from './infrastructure/database/database.module'; +import { ConfigModule } from '@nestjs/config'; +import { CortexModule } from './usecases/cortex/cortex.module'; +import { ServeCommand } from './infrastructure/commanders/serve.command'; +import { ModelsCommand } from './infrastructure/commanders/models.command'; +import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; +import { InitCommand } from './infrastructure/commanders/init.command'; +import { HttpModule } from '@nestjs/axios'; +import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; +import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; +import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; +import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; +import { ChatCommand } from './infrastructure/commanders/chat.command'; +import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; +import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; +import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; +import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; +import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; +import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; +import { AssistantsModule } from './usecases/assistants/assistants.module'; +import { MessagesModule } from './usecases/messages/messages.module'; +import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; import { PSCommand } from './infrastructure/commanders/ps.command'; -// import { KillCommand } from './infrastructure/commanders/kill.command'; -// import { PresetCommand } from './infrastructure/commanders/presets.command'; +import { KillCommand } from './infrastructure/commanders/kill.command'; +import { PresetCommand } from './infrastructure/commanders/presets.command'; import { TelemetryModule } from './usecases/telemetry/telemetry.module'; -// import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; -// import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; -// import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; -// import { EventEmitterModule } from '@nestjs/event-emitter'; -// import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; -// import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; +import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; +import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; +import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; +import { EventEmitterModule } from '@nestjs/event-emitter'; +import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; +import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; import { ContextModule } from './infrastructure/services/context/context.module'; -// import { ExtensionsModule } from './extensions/extensions.module'; -// import { ConfigsCommand } from './infrastructure/commanders/configs.command'; -// import { EnginesCommand } from './infrastructure/commanders/engines.command'; -// import { ConfigsModule } from './usecases/configs/configs.module'; -// import { EnginesModule } from './usecases/engines/engines.module'; -// import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; -// import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; -// import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; -// import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; -// import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; +import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; +import { ExtensionsModule } from './extensions/extensions.module'; +import { ConfigsCommand } from './infrastructure/commanders/configs.command'; +import { EnginesCommand } from './infrastructure/commanders/engines.command'; +import { ConfigsModule } from './usecases/configs/configs.module'; +import { EnginesModule } from './usecases/engines/engines.module'; +import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; +import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; +import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; +import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; +import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; @Module({ imports: [ - // ConfigModule.forRoot({ - // isGlobal: true, - // envFilePath: - // process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', - // }), - // EventEmitterModule.forRoot(), - // // DatabaseModule, - // ModelsModule, - // CortexModule, - // ExtensionModule, - // HttpModule, - // CliUsecasesModule, - // AssistantsModule, - // MessagesModule, - // FileManagerModule, + ConfigModule.forRoot({ + isGlobal: true, + envFilePath: + process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', + }), + EventEmitterModule.forRoot(), + // DatabaseModule, + ModelsModule, + CortexModule, + ExtensionModule, + HttpModule, + CliUsecasesModule, + AssistantsModule, + MessagesModule, + FileManagerModule, TelemetryModule, ContextModule, - // DownloadManagerModule, - // ExtensionsModule, - // ConfigsModule, - // EnginesModule, + DownloadManagerModule, + ExtensionsModule, + ConfigsModule, + EnginesModule, ], providers: [ - // CortexCommand, - // ModelsCommand, - // ServeCommand, - // ChatCommand, - // InitCommand, + CortexCommand, + ModelsCommand, + ServeCommand, + ChatCommand, + InitCommand, PSCommand, - // KillCommand, - // PresetCommand, - // EmbeddingCommand, - // BenchmarkCommand, - // EnginesCommand, + KillCommand, + PresetCommand, + EmbeddingCommand, + BenchmarkCommand, + EnginesCommand, - // // Questions - // InitRunModeQuestions, + // Questions + InitRunModeQuestions, - // // Model commands - // ModelStartCommand, - // ModelStopCommand, - // ModelListCommand, - // ModelGetCommand, - // ModelRemoveCommand, - // ModelPullCommand, - // ModelUpdateCommand, + // Model commands + ModelStartCommand, + ModelStopCommand, + ModelListCommand, + ModelGetCommand, + ModelRemoveCommand, + ModelPullCommand, + ModelUpdateCommand, - // // Shortcuts - // RunCommand, + // Shortcuts + RunCommand, - // // Telemetry - // TelemetryCommand, + // Telemetry + TelemetryCommand, - // // Serve - // ServeStopCommand, + // Serve + ServeStopCommand, - // // Configs - // ConfigsCommand, - // ConfigsGetCommand, - // ConfigsListCommand, - // ConfigsSetCommand, + // Configs + ConfigsCommand, + ConfigsGetCommand, + ConfigsListCommand, + ConfigsSetCommand, - // // Engines - // EnginesListCommand, - // EnginesGetCommand, + // Engines + EnginesListCommand, + EnginesGetCommand, ], }) export class CommandModule {} From 9dd587117719600a406052bd989e54771b1e10b8 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 22:58:06 +0700 Subject: [PATCH 23/64] a --- cortex-js/src/command.module.ts | 2 +- .../src/infrastructure/database/sqlite-database.providers.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index fca8b9597..acf1b698c 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -53,7 +53,7 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', }), EventEmitterModule.forRoot(), - // DatabaseModule, + DatabaseModule, ModelsModule, CortexModule, ExtensionModule, diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index e76b49b91..1fe587ed5 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -18,6 +18,7 @@ export const sqliteDatabaseProviders = [ database: sqlitePath, synchronize: process.env.NODE_ENV !== 'production', entities: [ThreadEntity, AssistantEntity, MessageEntity], + logging: true, }); return dataSource.initialize(); From aac4b91f1dbf73db1c657fb98a053047327765eb Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 23:05:03 +0700 Subject: [PATCH 24/64] debug import time --- cortex-js/src/command.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index 2c0c912ae..91521b12a 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -1,10 +1,13 @@ #!/usr/bin/env node --no-warnings +console.log('1'); +console.time('import'); import { CommandFactory } from 'nest-commander'; import { CommandModule } from './command.module'; import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; import { TelemetrySource } from './domain/telemetry/telemetry.interface'; import { ContextService } from '@/infrastructure/services/context/context.service'; +console.timeEnd('import'); console.time('test'); console.log('Running CLI'); async function bootstrap() { From ee70206a7935dcdaf0f7a2c1407a13c5aac3f695 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 23:07:46 +0700 Subject: [PATCH 25/64] debug import db module time --- .../database/sqlite-database.providers.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index 1fe587ed5..60d61410b 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -11,17 +11,18 @@ export const sqliteDatabaseProviders = [ provide: 'DATA_SOURCE', inject: [FileManagerService], useFactory: async (fileManagerService: FileManagerService) => { - const dataFolderPath = await fileManagerService.getDataFolderPath(); - const sqlitePath = join(dataFolderPath, databaseFile); - const dataSource = new DataSource({ - type: 'sqlite', - database: sqlitePath, - synchronize: process.env.NODE_ENV !== 'production', - entities: [ThreadEntity, AssistantEntity, MessageEntity], - logging: true, - }); + return null; + // const dataFolderPath = await fileManagerService.getDataFolderPath(); + // const sqlitePath = join(dataFolderPath, databaseFile); + // const dataSource = new DataSource({ + // type: 'sqlite', + // database: sqlitePath, + // synchronize: process.env.NODE_ENV !== 'production', + // entities: [ThreadEntity, AssistantEntity, MessageEntity], + // logging: true, + // }); - return dataSource.initialize(); + // return dataSource.initialize(); }, }, ]; From f3b47a8b607b1d51ea079b702e472858ac7544a5 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 23:10:17 +0700 Subject: [PATCH 26/64] debug import db module time --- .../infrastructure/commanders/ps.command.ts | 19 ++++++++++--------- .../database/database.module.ts | 14 +++++++------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/cortex-js/src/infrastructure/commanders/ps.command.ts b/cortex-js/src/infrastructure/commanders/ps.command.ts index 1f803e6e4..ab9edcbf8 100644 --- a/cortex-js/src/infrastructure/commanders/ps.command.ts +++ b/cortex-js/src/infrastructure/commanders/ps.command.ts @@ -10,18 +10,19 @@ import { ContextService } from '../services/context/context.service'; @SetCommandContext() export class PSCommand extends CommandRunner { constructor( - private readonly usecases: PSCliUsecases, - readonly contextService: ContextService, + // private readonly usecases: PSCliUsecases, + // readonly contextService: ContextService, ) { super(); } async run(): Promise { - return this.usecases - .getModels() - .then(console.table) - .then(() => this.usecases.isAPIServerOnline()) - .then((isOnline) => { - if (isOnline) console.log('API server is online'); - }); + return; + // return this.usecases + // .getModels() + // .then(console.table) + // .then(() => this.usecases.isAPIServerOnline()) + // .then((isOnline) => { + // if (isOnline) console.log('API server is online'); + // }); } } \ No newline at end of file diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index 2e7b3ae85..56f30a770 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -9,16 +9,16 @@ import { FileManagerModule } from '@/infrastructure/services/file-manager/file-m @Module({ imports: [FileManagerModule], providers: [ - ...sqliteDatabaseProviders, - ...threadProviders, - ...assistantProviders, - ...messageProviders, + // ...sqliteDatabaseProviders, + // ...threadProviders, + // ...assistantProviders, + // ...messageProviders, ...telemetryProviders, ], exports: [ - ...threadProviders, - ...assistantProviders, - ...messageProviders, + // ...threadProviders, + // ...assistantProviders, + // ...messageProviders, ...telemetryProviders, ], }) From 7ca3201d8ac5e2cdb9f9b84d4c2d9422af177669 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 23:13:18 +0700 Subject: [PATCH 27/64] debug telemetry import time --- cortex-js/src/command.module.ts | 10 +++---- cortex-js/src/command.ts | 46 ++++++++++++++++----------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index acf1b698c..e0fac5d79 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -25,8 +25,8 @@ import { FileManagerModule } from './infrastructure/services/file-manager/file-m import { PSCommand } from './infrastructure/commanders/ps.command'; import { KillCommand } from './infrastructure/commanders/kill.command'; import { PresetCommand } from './infrastructure/commanders/presets.command'; -import { TelemetryModule } from './usecases/telemetry/telemetry.module'; -import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; +// import { TelemetryModule } from './usecases/telemetry/telemetry.module'; +// import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; import { EventEmitterModule } from '@nestjs/event-emitter'; @@ -62,8 +62,8 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g AssistantsModule, MessagesModule, FileManagerModule, - TelemetryModule, - ContextModule, + // TelemetryModule, + // ContextModule, DownloadManagerModule, ExtensionsModule, ConfigsModule, @@ -98,7 +98,7 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g RunCommand, // Telemetry - TelemetryCommand, + // TelemetryCommand, // Serve ServeStopCommand, diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index 91521b12a..197fe54d4 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -3,41 +3,41 @@ console.log('1'); console.time('import'); import { CommandFactory } from 'nest-commander'; import { CommandModule } from './command.module'; -import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; -import { TelemetrySource } from './domain/telemetry/telemetry.interface'; -import { ContextService } from '@/infrastructure/services/context/context.service'; +// import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; +// import { TelemetrySource } from './domain/telemetry/telemetry.interface'; +// import { ContextService } from '@/infrastructure/services/context/context.service'; console.timeEnd('import'); console.time('test'); console.log('Running CLI'); async function bootstrap() { - let telemetryUseCase: TelemetryUsecases | null = null; - let contextService: ContextService | null = null; + // let telemetryUseCase: TelemetryUsecases | null = null; + // let contextService: ContextService | null = null; console.time('CLI'); - const app = await CommandFactory.createWithoutRunning(CommandModule, { - logger: ['warn', 'error'], - errorHandler: async (error) => { - await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - process.exit(1); - }, - serviceErrorHandler: async (error) => { - await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - process.exit(1); - }, - }); + // const app = await CommandFactory.createWithoutRunning(CommandModule, { + // logger: ['warn', 'error'], + // errorHandler: async (error) => { + // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // process.exit(1); + // }, + // serviceErrorHandler: async (error) => { + // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + // process.exit(1); + // }, + // }); - telemetryUseCase = await app.resolve(TelemetryUsecases); - contextService = await app.resolve(ContextService); + // telemetryUseCase = await app.resolve(TelemetryUsecases); + // contextService = await app.resolve(ContextService); - telemetryUseCase!.sendCrashReport(); + // telemetryUseCase!.sendCrashReport(); - await contextService!.init(async () => { - contextService!.set('source', TelemetrySource.CLI); - await CommandFactory.runApplication(app); + // await contextService!.init(async () => { + // contextService!.set('source', TelemetrySource.CLI); + // await CommandFactory.runApplication(app); await CommandFactory.run(CommandModule, ['warn', 'error']); console.timeEnd('CLI'); console.timeEnd('test'); - }); + // }); } bootstrap(); From b52a5c50e173ecc0138e524e579d69a6f08d4579 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 23:14:08 +0700 Subject: [PATCH 28/64] debug telemetry import time --- .../src/infrastructure/database/database.module.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index 56f30a770..2e7b3ae85 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -9,16 +9,16 @@ import { FileManagerModule } from '@/infrastructure/services/file-manager/file-m @Module({ imports: [FileManagerModule], providers: [ - // ...sqliteDatabaseProviders, - // ...threadProviders, - // ...assistantProviders, - // ...messageProviders, + ...sqliteDatabaseProviders, + ...threadProviders, + ...assistantProviders, + ...messageProviders, ...telemetryProviders, ], exports: [ - // ...threadProviders, - // ...assistantProviders, - // ...messageProviders, + ...threadProviders, + ...assistantProviders, + ...messageProviders, ...telemetryProviders, ], }) From 6d5d8991a7f0743a932b4d14ab95166714082041 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 23:18:29 +0700 Subject: [PATCH 29/64] debug telemetry import time --- cortex-js/src/command.module.ts | 200 ++++++++++++++++---------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index e0fac5d79..98702eb08 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,117 +1,117 @@ import { Module } from '@nestjs/common'; -import { ModelsModule } from './usecases/models/models.module'; -import { DatabaseModule } from './infrastructure/database/database.module'; -import { ConfigModule } from '@nestjs/config'; -import { CortexModule } from './usecases/cortex/cortex.module'; -import { ServeCommand } from './infrastructure/commanders/serve.command'; -import { ModelsCommand } from './infrastructure/commanders/models.command'; -import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; -import { InitCommand } from './infrastructure/commanders/init.command'; -import { HttpModule } from '@nestjs/axios'; -import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; -import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; -import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; -import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; -import { ChatCommand } from './infrastructure/commanders/chat.command'; -import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; -import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; -import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; -import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; -import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; -import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; -import { AssistantsModule } from './usecases/assistants/assistants.module'; -import { MessagesModule } from './usecases/messages/messages.module'; -import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; -import { PSCommand } from './infrastructure/commanders/ps.command'; -import { KillCommand } from './infrastructure/commanders/kill.command'; -import { PresetCommand } from './infrastructure/commanders/presets.command'; -// import { TelemetryModule } from './usecases/telemetry/telemetry.module'; -// import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; -import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; -import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; -import { EventEmitterModule } from '@nestjs/event-emitter'; -import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; -import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; -import { ContextModule } from './infrastructure/services/context/context.module'; -import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; -import { ExtensionsModule } from './extensions/extensions.module'; -import { ConfigsCommand } from './infrastructure/commanders/configs.command'; -import { EnginesCommand } from './infrastructure/commanders/engines.command'; -import { ConfigsModule } from './usecases/configs/configs.module'; -import { EnginesModule } from './usecases/engines/engines.module'; -import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; -import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; -import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; -import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; -import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; +// import { ModelsModule } from './usecases/models/models.module'; +// import { DatabaseModule } from './infrastructure/database/database.module'; +// import { ConfigModule } from '@nestjs/config'; +// import { CortexModule } from './usecases/cortex/cortex.module'; +// import { ServeCommand } from './infrastructure/commanders/serve.command'; +// import { ModelsCommand } from './infrastructure/commanders/models.command'; +// import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; +// import { InitCommand } from './infrastructure/commanders/init.command'; +// import { HttpModule } from '@nestjs/axios'; +// import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; +// import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; +// import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; +// import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; +// import { ChatCommand } from './infrastructure/commanders/chat.command'; +// import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; +// import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; +// import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; +// import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; +// import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; +// import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; +// import { AssistantsModule } from './usecases/assistants/assistants.module'; +// import { MessagesModule } from './usecases/messages/messages.module'; +// import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; +// import { PSCommand } from './infrastructure/commanders/ps.command'; +// import { KillCommand } from './infrastructure/commanders/kill.command'; +// import { PresetCommand } from './infrastructure/commanders/presets.command'; +// // import { TelemetryModule } from './usecases/telemetry/telemetry.module'; +// // import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; +// import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; +// import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; +// import { EventEmitterModule } from '@nestjs/event-emitter'; +// import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; +// import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; +// import { ContextModule } from './infrastructure/services/context/context.module'; +// import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; +// import { ExtensionsModule } from './extensions/extensions.module'; +// import { ConfigsCommand } from './infrastructure/commanders/configs.command'; +// import { EnginesCommand } from './infrastructure/commanders/engines.command'; +// import { ConfigsModule } from './usecases/configs/configs.module'; +// import { EnginesModule } from './usecases/engines/engines.module'; +// import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; +// import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; +// import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; +// import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; +// import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; @Module({ imports: [ - ConfigModule.forRoot({ - isGlobal: true, - envFilePath: - process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', - }), - EventEmitterModule.forRoot(), - DatabaseModule, - ModelsModule, - CortexModule, - ExtensionModule, - HttpModule, - CliUsecasesModule, - AssistantsModule, - MessagesModule, - FileManagerModule, - // TelemetryModule, - // ContextModule, - DownloadManagerModule, - ExtensionsModule, - ConfigsModule, - EnginesModule, + // ConfigModule.forRoot({ + // isGlobal: true, + // envFilePath: + // process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', + // }), + // EventEmitterModule.forRoot(), + // DatabaseModule, + // ModelsModule, + // CortexModule, + // ExtensionModule, + // HttpModule, + // CliUsecasesModule, + // AssistantsModule, + // MessagesModule, + // FileManagerModule, + // // TelemetryModule, + // // ContextModule, + // DownloadManagerModule, + // ExtensionsModule, + // ConfigsModule, + // EnginesModule, ], providers: [ - CortexCommand, - ModelsCommand, - ServeCommand, - ChatCommand, - InitCommand, + // CortexCommand, + // ModelsCommand, + // ServeCommand, + // ChatCommand, + // InitCommand, PSCommand, - KillCommand, - PresetCommand, - EmbeddingCommand, - BenchmarkCommand, - EnginesCommand, + // KillCommand, + // PresetCommand, + // EmbeddingCommand, + // BenchmarkCommand, + // EnginesCommand, - // Questions - InitRunModeQuestions, + // // Questions + // InitRunModeQuestions, - // Model commands - ModelStartCommand, - ModelStopCommand, - ModelListCommand, - ModelGetCommand, - ModelRemoveCommand, - ModelPullCommand, - ModelUpdateCommand, + // // Model commands + // ModelStartCommand, + // ModelStopCommand, + // ModelListCommand, + // ModelGetCommand, + // ModelRemoveCommand, + // ModelPullCommand, + // ModelUpdateCommand, - // Shortcuts - RunCommand, + // // Shortcuts + // RunCommand, - // Telemetry - // TelemetryCommand, + // // Telemetry + // // TelemetryCommand, - // Serve - ServeStopCommand, + // // Serve + // ServeStopCommand, - // Configs - ConfigsCommand, - ConfigsGetCommand, - ConfigsListCommand, - ConfigsSetCommand, + // // Configs + // ConfigsCommand, + // ConfigsGetCommand, + // ConfigsListCommand, + // ConfigsSetCommand, - // Engines - EnginesListCommand, - EnginesGetCommand, + // // Engines + // EnginesListCommand, + // EnginesGetCommand, ], }) export class CommandModule {} From c6cb079b21a5754f5e2029cddf1b4af839c86258 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 23:24:41 +0700 Subject: [PATCH 30/64] debug telemetry import time --- cortex-js/src/command.module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 98702eb08..e681f0176 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -22,7 +22,7 @@ import { Module } from '@nestjs/common'; // import { AssistantsModule } from './usecases/assistants/assistants.module'; // import { MessagesModule } from './usecases/messages/messages.module'; // import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; -// import { PSCommand } from './infrastructure/commanders/ps.command'; +import { PSCommand } from './infrastructure/commanders/ps.command'; // import { KillCommand } from './infrastructure/commanders/kill.command'; // import { PresetCommand } from './infrastructure/commanders/presets.command'; // // import { TelemetryModule } from './usecases/telemetry/telemetry.module'; From edf6f40f7abe0ffea00dafd9a6c2d822c74501f9 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 23:34:31 +0700 Subject: [PATCH 31/64] remove some import --- cortex-js/src/command.module.ts | 166 +++++++++--------- .../src/usecases/configs/configs.usecase.ts | 14 +- 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index e681f0176..38c774233 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,49 +1,49 @@ import { Module } from '@nestjs/common'; -// import { ModelsModule } from './usecases/models/models.module'; +import { ModelsModule } from './usecases/models/models.module'; // import { DatabaseModule } from './infrastructure/database/database.module'; // import { ConfigModule } from '@nestjs/config'; -// import { CortexModule } from './usecases/cortex/cortex.module'; -// import { ServeCommand } from './infrastructure/commanders/serve.command'; -// import { ModelsCommand } from './infrastructure/commanders/models.command'; -// import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; -// import { InitCommand } from './infrastructure/commanders/init.command'; -// import { HttpModule } from '@nestjs/axios'; -// import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; -// import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; -// import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; -// import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; -// import { ChatCommand } from './infrastructure/commanders/chat.command'; -// import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; -// import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; -// import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; -// import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; -// import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; -// import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; -// import { AssistantsModule } from './usecases/assistants/assistants.module'; -// import { MessagesModule } from './usecases/messages/messages.module'; -// import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; +import { CortexModule } from './usecases/cortex/cortex.module'; +import { ServeCommand } from './infrastructure/commanders/serve.command'; +import { ModelsCommand } from './infrastructure/commanders/models.command'; +import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; +import { InitCommand } from './infrastructure/commanders/init.command'; +import { HttpModule } from '@nestjs/axios'; +import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; +import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; +import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; +import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; +import { ChatCommand } from './infrastructure/commanders/chat.command'; +import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; +import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; +import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; +import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; +import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; +import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; +import { AssistantsModule } from './usecases/assistants/assistants.module'; +import { MessagesModule } from './usecases/messages/messages.module'; +import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; import { PSCommand } from './infrastructure/commanders/ps.command'; -// import { KillCommand } from './infrastructure/commanders/kill.command'; -// import { PresetCommand } from './infrastructure/commanders/presets.command'; -// // import { TelemetryModule } from './usecases/telemetry/telemetry.module'; -// // import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; -// import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; -// import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; -// import { EventEmitterModule } from '@nestjs/event-emitter'; -// import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; -// import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; -// import { ContextModule } from './infrastructure/services/context/context.module'; -// import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; -// import { ExtensionsModule } from './extensions/extensions.module'; -// import { ConfigsCommand } from './infrastructure/commanders/configs.command'; -// import { EnginesCommand } from './infrastructure/commanders/engines.command'; +import { KillCommand } from './infrastructure/commanders/kill.command'; +import { PresetCommand } from './infrastructure/commanders/presets.command'; +// import { TelemetryModule } from './usecases/telemetry/telemetry.module'; +// import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; +import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; +import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; +import { EventEmitterModule } from '@nestjs/event-emitter'; +import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; +import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; +import { ContextModule } from './infrastructure/services/context/context.module'; +import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; +import { ExtensionsModule } from './extensions/extensions.module'; +import { ConfigsCommand } from './infrastructure/commanders/configs.command'; +import { EnginesCommand } from './infrastructure/commanders/engines.command'; // import { ConfigsModule } from './usecases/configs/configs.module'; -// import { EnginesModule } from './usecases/engines/engines.module'; -// import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; -// import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; -// import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; -// import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; -// import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; +import { EnginesModule } from './usecases/engines/engines.module'; +import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; +import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; +import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; +import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; +import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; @Module({ imports: [ @@ -54,54 +54,54 @@ import { PSCommand } from './infrastructure/commanders/ps.command'; // }), // EventEmitterModule.forRoot(), // DatabaseModule, - // ModelsModule, - // CortexModule, - // ExtensionModule, - // HttpModule, - // CliUsecasesModule, - // AssistantsModule, - // MessagesModule, - // FileManagerModule, - // // TelemetryModule, - // // ContextModule, - // DownloadManagerModule, - // ExtensionsModule, + ModelsModule, + CortexModule, + ExtensionModule, + HttpModule, + CliUsecasesModule, + AssistantsModule, + MessagesModule, + FileManagerModule, + // TelemetryModule, + // ContextModule, + DownloadManagerModule, + ExtensionsModule, // ConfigsModule, - // EnginesModule, + EnginesModule, ], providers: [ - // CortexCommand, - // ModelsCommand, - // ServeCommand, - // ChatCommand, - // InitCommand, + CortexCommand, + ModelsCommand, + ServeCommand, + ChatCommand, + InitCommand, PSCommand, - // KillCommand, - // PresetCommand, - // EmbeddingCommand, - // BenchmarkCommand, - // EnginesCommand, + KillCommand, + PresetCommand, + EmbeddingCommand, + BenchmarkCommand, + EnginesCommand, - // // Questions - // InitRunModeQuestions, + // Questions + InitRunModeQuestions, - // // Model commands - // ModelStartCommand, - // ModelStopCommand, - // ModelListCommand, - // ModelGetCommand, - // ModelRemoveCommand, - // ModelPullCommand, - // ModelUpdateCommand, + // Model commands + ModelStartCommand, + ModelStopCommand, + ModelListCommand, + ModelGetCommand, + ModelRemoveCommand, + ModelPullCommand, + ModelUpdateCommand, - // // Shortcuts - // RunCommand, + // Shortcuts + RunCommand, - // // Telemetry - // // TelemetryCommand, + // Telemetry + // TelemetryCommand, - // // Serve - // ServeStopCommand, + // Serve + ServeStopCommand, // // Configs // ConfigsCommand, @@ -109,9 +109,9 @@ import { PSCommand } from './infrastructure/commanders/ps.command'; // ConfigsListCommand, // ConfigsSetCommand, - // // Engines - // EnginesListCommand, - // EnginesGetCommand, + // Engines + EnginesListCommand, + EnginesGetCommand, ], }) export class CommandModule {} diff --git a/cortex-js/src/usecases/configs/configs.usecase.ts b/cortex-js/src/usecases/configs/configs.usecase.ts index 4cff2e3f5..dcfd3307e 100644 --- a/cortex-js/src/usecases/configs/configs.usecase.ts +++ b/cortex-js/src/usecases/configs/configs.usecase.ts @@ -1,13 +1,13 @@ import { CommonResponseDto } from '@/infrastructure/dtos/common/common-response.dto'; import { FileManagerService } from '@/infrastructure/services/file-manager/file-manager.service'; import { Injectable } from '@nestjs/common'; -import { EventEmitter2 } from '@nestjs/event-emitter'; +// import { EventEmitter2 } from '@nestjs/event-emitter'; @Injectable() export class ConfigsUsecases { constructor( private readonly fileManagerService: FileManagerService, - private readonly eventEmitter: EventEmitter2, + // private readonly eventEmitter: EventEmitter2, ) {} /** @@ -41,11 +41,11 @@ export class ConfigsUsecases { .writeConfigFile(newConfigs) .then(async () => { if (group) { - this.eventEmitter.emit('config.updated', { - group, - key, - value, - }); + // this.eventEmitter.emit('config.updated', { + // group, + // key, + // value, + // }); } }) .then(() => { From f0a4a7321f390d4910ef78220d5e6d73c4a0e773 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 1 Jul 2024 23:37:45 +0700 Subject: [PATCH 32/64] remove filemanager --- cortex-js/src/command.module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 38c774233..8af4c8abb 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -21,7 +21,7 @@ import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; import { AssistantsModule } from './usecases/assistants/assistants.module'; import { MessagesModule } from './usecases/messages/messages.module'; -import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; +// import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; import { PSCommand } from './infrastructure/commanders/ps.command'; import { KillCommand } from './infrastructure/commanders/kill.command'; import { PresetCommand } from './infrastructure/commanders/presets.command'; @@ -61,7 +61,7 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g CliUsecasesModule, AssistantsModule, MessagesModule, - FileManagerModule, + // FileManagerModule, // TelemetryModule, // ContextModule, DownloadManagerModule, From 84ab94074dff4e09655d8430b1426680a511135e Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 00:44:58 +0700 Subject: [PATCH 33/64] remove filemanager --- cortex-js/src/command.module.ts | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 8af4c8abb..14399a859 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,7 +1,7 @@ import { Module } from '@nestjs/common'; import { ModelsModule } from './usecases/models/models.module'; -// import { DatabaseModule } from './infrastructure/database/database.module'; -// import { ConfigModule } from '@nestjs/config'; +import { DatabaseModule } from './infrastructure/database/database.module'; +import { ConfigModule } from '@nestjs/config'; import { CortexModule } from './usecases/cortex/cortex.module'; import { ServeCommand } from './infrastructure/commanders/serve.command'; import { ModelsCommand } from './infrastructure/commanders/models.command'; @@ -21,12 +21,12 @@ import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; import { AssistantsModule } from './usecases/assistants/assistants.module'; import { MessagesModule } from './usecases/messages/messages.module'; -// import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; +import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; import { PSCommand } from './infrastructure/commanders/ps.command'; import { KillCommand } from './infrastructure/commanders/kill.command'; import { PresetCommand } from './infrastructure/commanders/presets.command'; -// import { TelemetryModule } from './usecases/telemetry/telemetry.module'; -// import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; +import { TelemetryModule } from './usecases/telemetry/telemetry.module'; +import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; import { EventEmitterModule } from '@nestjs/event-emitter'; @@ -37,7 +37,7 @@ import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usec import { ExtensionsModule } from './extensions/extensions.module'; import { ConfigsCommand } from './infrastructure/commanders/configs.command'; import { EnginesCommand } from './infrastructure/commanders/engines.command'; -// import { ConfigsModule } from './usecases/configs/configs.module'; +import { ConfigsModule } from './usecases/configs/configs.module'; import { EnginesModule } from './usecases/engines/engines.module'; import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; @@ -54,20 +54,20 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g // }), // EventEmitterModule.forRoot(), // DatabaseModule, - ModelsModule, - CortexModule, - ExtensionModule, - HttpModule, - CliUsecasesModule, - AssistantsModule, - MessagesModule, + // ModelsModule, + // CortexModule, + // ExtensionModule, + // HttpModule, + // CliUsecasesModule, + // AssistantsModule, + // MessagesModule, // FileManagerModule, // TelemetryModule, // ContextModule, - DownloadManagerModule, - ExtensionsModule, + // DownloadManagerModule, + // ExtensionsModule, // ConfigsModule, - EnginesModule, + // EnginesModule, ], providers: [ CortexCommand, @@ -98,16 +98,16 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g RunCommand, // Telemetry - // TelemetryCommand, + TelemetryCommand, // Serve ServeStopCommand, // // Configs - // ConfigsCommand, - // ConfigsGetCommand, - // ConfigsListCommand, - // ConfigsSetCommand, + ConfigsCommand, + ConfigsGetCommand, + ConfigsListCommand, + ConfigsSetCommand, // Engines EnginesListCommand, From 9e68ba6f11997150b412673ddc46e3d6ad6dd20d Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 00:50:59 +0700 Subject: [PATCH 34/64] remove filemanager --- cortex-js/src/command.module.ts | 42 +++++++++---------- .../file-manager/file-manager.service.ts | 5 +++ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 14399a859..e88340f62 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -47,27 +47,27 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g @Module({ imports: [ - // ConfigModule.forRoot({ - // isGlobal: true, - // envFilePath: - // process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', - // }), - // EventEmitterModule.forRoot(), - // DatabaseModule, - // ModelsModule, - // CortexModule, - // ExtensionModule, - // HttpModule, - // CliUsecasesModule, - // AssistantsModule, - // MessagesModule, - // FileManagerModule, - // TelemetryModule, - // ContextModule, - // DownloadManagerModule, - // ExtensionsModule, - // ConfigsModule, - // EnginesModule, + ConfigModule.forRoot({ + isGlobal: true, + envFilePath: + process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', + }), + EventEmitterModule.forRoot(), + DatabaseModule, + ModelsModule, + CortexModule, + ExtensionModule, + HttpModule, + CliUsecasesModule, + AssistantsModule, + MessagesModule, + FileManagerModule, + TelemetryModule, + ContextModule, + DownloadManagerModule, + ExtensionsModule, + ConfigsModule, + EnginesModule, ], providers: [ CortexCommand, diff --git a/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts b/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts index e1ea41e92..b35e695fa 100644 --- a/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts +++ b/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts @@ -39,6 +39,7 @@ export class FileManagerService { * @returns the config object */ async getConfig(): Promise { + console.log('getConfig'); const homeDir = os.homedir(); const configPath = join(homeDir, this.configFile); @@ -67,6 +68,7 @@ export class FileManagerService { } async writeConfigFile(config: Config & object): Promise { + console.log('writeConfigFile'); const homeDir = os.homedir(); const configPath = join(homeDir, this.configFile); @@ -76,6 +78,7 @@ export class FileManagerService { } private async createFolderIfNotExist(dataFolderPath: string): Promise { + console.log('createFolderIfNotExist'); if (!existsSync(dataFolderPath)) { await promises.mkdir(dataFolderPath, { recursive: true }); } @@ -98,6 +101,7 @@ export class FileManagerService { } private defaultConfig(): Config { + console.log('defaultConfig'); // default will store at home directory const homeDir = os.homedir(); const dataFolderPath = join(homeDir, this.cortexDirectoryName); @@ -124,6 +128,7 @@ export class FileManagerService { filePath: string, ): Promise<{ data: any; position: number }> { try { + console.log('getLastLine'); const fileDescriptor = await openAsync(filePath, 'a+'); const stats = await promises.stat(filePath); const bufferSize = 1024 * 5; // 5KB From 4a0b46b2b3aec1795d4c812a49a4327839be70db Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 00:54:18 +0700 Subject: [PATCH 35/64] remove filemanager --- cortex-js/src/command.ts | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index 197fe54d4..69a35c3ef 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -3,41 +3,41 @@ console.log('1'); console.time('import'); import { CommandFactory } from 'nest-commander'; import { CommandModule } from './command.module'; -// import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; -// import { TelemetrySource } from './domain/telemetry/telemetry.interface'; -// import { ContextService } from '@/infrastructure/services/context/context.service'; +import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; +import { TelemetrySource } from './domain/telemetry/telemetry.interface'; +import { ContextService } from '@/infrastructure/services/context/context.service'; console.timeEnd('import'); console.time('test'); console.log('Running CLI'); async function bootstrap() { - // let telemetryUseCase: TelemetryUsecases | null = null; - // let contextService: ContextService | null = null; + let telemetryUseCase: TelemetryUsecases | null = null; + let contextService: ContextService | null = null; console.time('CLI'); - // const app = await CommandFactory.createWithoutRunning(CommandModule, { - // logger: ['warn', 'error'], - // errorHandler: async (error) => { - // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // process.exit(1); - // }, - // serviceErrorHandler: async (error) => { - // await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); - // process.exit(1); - // }, - // }); + const app = await CommandFactory.createWithoutRunning(CommandModule, { + logger: ['warn', 'error'], + errorHandler: async (error) => { + await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + process.exit(1); + }, + serviceErrorHandler: async (error) => { + await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + process.exit(1); + }, + }); - // telemetryUseCase = await app.resolve(TelemetryUsecases); - // contextService = await app.resolve(ContextService); + telemetryUseCase = await app.resolve(TelemetryUsecases); + contextService = await app.resolve(ContextService); - // telemetryUseCase!.sendCrashReport(); + telemetryUseCase!.sendCrashReport(); - // await contextService!.init(async () => { - // contextService!.set('source', TelemetrySource.CLI); - // await CommandFactory.runApplication(app); - await CommandFactory.run(CommandModule, ['warn', 'error']); + await contextService!.init(async () => { + contextService!.set('source', TelemetrySource.CLI); + await CommandFactory.runApplication(app); + // await CommandFactory.run(CommandModule, ['warn', 'error']); console.timeEnd('CLI'); console.timeEnd('test'); - // }); + }); } bootstrap(); From 3a47dee857cf47d1c9c172c787366dee10818d55 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 10:44:25 +0700 Subject: [PATCH 36/64] remove filemanager --- .../infrastructure/commanders/ps.command.ts | 19 ++++++----- .../database/database.module.ts | 32 +++++++++---------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/cortex-js/src/infrastructure/commanders/ps.command.ts b/cortex-js/src/infrastructure/commanders/ps.command.ts index ab9edcbf8..1f803e6e4 100644 --- a/cortex-js/src/infrastructure/commanders/ps.command.ts +++ b/cortex-js/src/infrastructure/commanders/ps.command.ts @@ -10,19 +10,18 @@ import { ContextService } from '../services/context/context.service'; @SetCommandContext() export class PSCommand extends CommandRunner { constructor( - // private readonly usecases: PSCliUsecases, - // readonly contextService: ContextService, + private readonly usecases: PSCliUsecases, + readonly contextService: ContextService, ) { super(); } async run(): Promise { - return; - // return this.usecases - // .getModels() - // .then(console.table) - // .then(() => this.usecases.isAPIServerOnline()) - // .then((isOnline) => { - // if (isOnline) console.log('API server is online'); - // }); + return this.usecases + .getModels() + .then(console.table) + .then(() => this.usecases.isAPIServerOnline()) + .then((isOnline) => { + if (isOnline) console.log('API server is online'); + }); } } \ No newline at end of file diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index 2e7b3ae85..016b4fd08 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -1,25 +1,25 @@ import { Module } from '@nestjs/common'; -import { threadProviders } from './providers/thread.providers'; -import { sqliteDatabaseProviders } from './sqlite-database.providers'; -import { assistantProviders } from './providers/assistant.providers'; -import { messageProviders } from './providers/message.providers'; -import { telemetryProviders } from './providers/telemetry.providers'; -import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module'; +// import { threadProviders } from './providers/thread.providers'; +// import { sqliteDatabaseProviders } from './sqlite-database.providers'; +// import { assistantProviders } from './providers/assistant.providers'; +// import { messageProviders } from './providers/message.providers'; +// import { telemetryProviders } from './providers/telemetry.providers'; +// import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module'; @Module({ - imports: [FileManagerModule], + imports: [], providers: [ - ...sqliteDatabaseProviders, - ...threadProviders, - ...assistantProviders, - ...messageProviders, - ...telemetryProviders, + // ...sqliteDatabaseProviders, + // ...threadProviders, + // ...assistantProviders, + // ...messageProviders, + // ...telemetryProviders, ], exports: [ - ...threadProviders, - ...assistantProviders, - ...messageProviders, - ...telemetryProviders, + // ...threadProviders, + // ...assistantProviders, + // ...messageProviders, + // ...telemetryProviders, ], }) export class DatabaseModule {} From 781498c2f079ae835e12a665aab467c47caf66b8 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 11:02:12 +0700 Subject: [PATCH 37/64] revert database --- .../database/database.module.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index 016b4fd08..a3d6d6359 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -1,25 +1,25 @@ import { Module } from '@nestjs/common'; -// import { threadProviders } from './providers/thread.providers'; -// import { sqliteDatabaseProviders } from './sqlite-database.providers'; -// import { assistantProviders } from './providers/assistant.providers'; -// import { messageProviders } from './providers/message.providers'; -// import { telemetryProviders } from './providers/telemetry.providers'; -// import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module'; +import { threadProviders } from './providers/thread.providers'; +import { sqliteDatabaseProviders } from './sqlite-database.providers'; +import { assistantProviders } from './providers/assistant.providers'; +import { messageProviders } from './providers/message.providers'; +import { telemetryProviders } from './providers/telemetry.providers'; +import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module'; @Module({ imports: [], providers: [ - // ...sqliteDatabaseProviders, - // ...threadProviders, - // ...assistantProviders, - // ...messageProviders, - // ...telemetryProviders, + ...sqliteDatabaseProviders, + ...threadProviders, + ...assistantProviders, + ...messageProviders, + ...telemetryProviders, ], exports: [ - // ...threadProviders, - // ...assistantProviders, - // ...messageProviders, - // ...telemetryProviders, + ...threadProviders, + ...assistantProviders, + ...messageProviders, + ...telemetryProviders, ], }) export class DatabaseModule {} From f2b1664a52667d18071031e0e8e12db54ae0d895 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 11:06:44 +0700 Subject: [PATCH 38/64] revert database --- .../database/database.module.ts | 2 +- .../database/sqlite-database.providers.ts | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index a3d6d6359..2e7b3ae85 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -7,7 +7,7 @@ import { telemetryProviders } from './providers/telemetry.providers'; import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module'; @Module({ - imports: [], + imports: [FileManagerModule], providers: [ ...sqliteDatabaseProviders, ...threadProviders, diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index 60d61410b..1fe587ed5 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -11,18 +11,17 @@ export const sqliteDatabaseProviders = [ provide: 'DATA_SOURCE', inject: [FileManagerService], useFactory: async (fileManagerService: FileManagerService) => { - return null; - // const dataFolderPath = await fileManagerService.getDataFolderPath(); - // const sqlitePath = join(dataFolderPath, databaseFile); - // const dataSource = new DataSource({ - // type: 'sqlite', - // database: sqlitePath, - // synchronize: process.env.NODE_ENV !== 'production', - // entities: [ThreadEntity, AssistantEntity, MessageEntity], - // logging: true, - // }); + const dataFolderPath = await fileManagerService.getDataFolderPath(); + const sqlitePath = join(dataFolderPath, databaseFile); + const dataSource = new DataSource({ + type: 'sqlite', + database: sqlitePath, + synchronize: process.env.NODE_ENV !== 'production', + entities: [ThreadEntity, AssistantEntity, MessageEntity], + logging: true, + }); - // return dataSource.initialize(); + return dataSource.initialize(); }, }, ]; From 7e4112517100e4fba5b6684af68c9e01e31b5f82 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 14:45:36 +0700 Subject: [PATCH 39/64] remove load extension --- .../repositories/extensions/extension.repository.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts b/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts index b37ece430..7002366cb 100644 --- a/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts +++ b/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts @@ -22,8 +22,8 @@ export class ExtensionRepositoryImpl implements ExtensionRepository { private readonly httpService: HttpService, private readonly fileManagerService: FileManagerService, ) { - this.loadCoreExtensions(); - this.loadExternalExtensions(); + // this.loadCoreExtensions(); + // this.loadExternalExtensions(); } create(object: Extension): Promise { this.extensions.set(object.name ?? '', object); From 2dcf85465fb7059511118a1e7e6b83bb38140784 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 14:48:13 +0700 Subject: [PATCH 40/64] remove load extension --- .../repositories/extensions/extension.repository.ts | 4 ++-- .../services/file-manager/file-manager.service.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts b/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts index 7002366cb..b37ece430 100644 --- a/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts +++ b/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts @@ -22,8 +22,8 @@ export class ExtensionRepositoryImpl implements ExtensionRepository { private readonly httpService: HttpService, private readonly fileManagerService: FileManagerService, ) { - // this.loadCoreExtensions(); - // this.loadExternalExtensions(); + this.loadCoreExtensions(); + this.loadExternalExtensions(); } create(object: Extension): Promise { this.extensions.set(object.name ?? '', object); diff --git a/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts b/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts index b35e695fa..a62dee416 100644 --- a/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts +++ b/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts @@ -172,6 +172,7 @@ export class FileManagerService { } async modifyLine(filePath: string, modifiedLine: any, position: number) { try { + console.log('modifyLine'); const fd = await openAsync(filePath, 'r+'); const buffer = Buffer.from(modifiedLine, 'utf8'); await writeAsync(fd, buffer, 0, buffer.length, position); @@ -184,6 +185,7 @@ export class FileManagerService { async append(filePath: string, data: any) { try { + console.log('append'); const stats = await promises.stat(filePath); return await promises.appendFile( filePath, @@ -198,6 +200,7 @@ export class FileManagerService { } } readLines(filePath: string, callback: (line: string) => void) { + console.log('readLines'); const fileStream = createReadStream(filePath); const rl = createInterface({ input: fileStream, @@ -212,6 +215,7 @@ export class FileManagerService { * @returns the path to the models folder */ async getModelsPath(): Promise { + console.log('getModelsPath'); const dataFolderPath = await this.getDataFolderPath(); return join(dataFolderPath, this.modelFolderName); } @@ -222,6 +226,7 @@ export class FileManagerService { * @returns the path to the presets folder */ async getPresetsPath(): Promise { + console.log('getPresetsPath'); const dataFolderPath = await this.getDataFolderPath(); return join(dataFolderPath, this.presetFolderName); } @@ -232,6 +237,7 @@ export class FileManagerService { * @returns the path to the extensions folder */ async getExtensionsPath(): Promise { + console.log('getExtensionsPath'); const dataFolderPath = await this.getDataFolderPath(); return join(dataFolderPath, this.extensionFoldername); } @@ -242,6 +248,7 @@ export class FileManagerService { * @returns the path to the benchmark folder */ async getBenchmarkPath(): Promise { + console.log('getBenchmarkPath'); const dataFolderPath = await this.getDataFolderPath(); return join(dataFolderPath, this.benchmarkFoldername); } @@ -251,10 +258,12 @@ export class FileManagerService { * @returns the path to the cortex engines folder */ async getCortexCppEnginePath(): Promise { + console.log('getCortexCppEnginePath'); return join(await this.getDataFolderPath(), 'cortex-cpp', 'engines'); } async createFolderIfNotExistInDataFolder(folderName: string): Promise { + console.log('createFolderIfNotExistInDataFolder'); const dataFolderPath = await this.getDataFolderPath(); const folderPath = join(dataFolderPath, folderName); if (!existsSync(folderPath)) { From 1eec8cb56e1174c3776d9a37828e25abb2556bcd Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 14:55:42 +0700 Subject: [PATCH 41/64] debug load module --- cortex-js/src/command.module.ts | 46 ++++++++++--------- .../extensions/extension.repository.ts | 2 + 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index e88340f62..bd466b97a 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,3 +1,4 @@ +console.time('import-command'); import { Module } from '@nestjs/common'; import { ModelsModule } from './usecases/models/models.module'; import { DatabaseModule } from './infrastructure/database/database.module'; @@ -44,30 +45,33 @@ import { ConfigsListCommand } from './infrastructure/commanders/configs/configs- import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; +console.timeEnd('import-command'); + +console.time('import-command'); @Module({ imports: [ - ConfigModule.forRoot({ - isGlobal: true, - envFilePath: - process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', - }), - EventEmitterModule.forRoot(), - DatabaseModule, - ModelsModule, - CortexModule, - ExtensionModule, - HttpModule, - CliUsecasesModule, - AssistantsModule, - MessagesModule, - FileManagerModule, - TelemetryModule, - ContextModule, - DownloadManagerModule, - ExtensionsModule, - ConfigsModule, - EnginesModule, + // ConfigModule.forRoot({ + // isGlobal: true, + // envFilePath: + // process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', + // }), + // EventEmitterModule.forRoot(), + // DatabaseModule, + // ModelsModule, + // CortexModule, + // ExtensionModule, + // HttpModule, + // CliUsecasesModule, + // AssistantsModule, + // MessagesModule, + // FileManagerModule, + // TelemetryModule, + // ContextModule, + // DownloadManagerModule, + // ExtensionsModule, + // ConfigsModule, + // EnginesModule, ], providers: [ CortexCommand, diff --git a/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts b/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts index b37ece430..2177c78af 100644 --- a/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts +++ b/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts @@ -22,8 +22,10 @@ export class ExtensionRepositoryImpl implements ExtensionRepository { private readonly httpService: HttpService, private readonly fileManagerService: FileManagerService, ) { + console.time('loadExtensions'); this.loadCoreExtensions(); this.loadExternalExtensions(); + console.timeEnd('loadExtensions'); } create(object: Extension): Promise { this.extensions.set(object.name ?? '', object); From 7f0a2a19e4bdc082cfd406cc2563a2a273fce8fc Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 14:57:00 +0700 Subject: [PATCH 42/64] comment all module --- cortex-js/src/command.module.ts | 70 ++++++++++++++++----------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index bd466b97a..b48118bc1 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -74,48 +74,48 @@ console.time('import-command'); // EnginesModule, ], providers: [ - CortexCommand, - ModelsCommand, - ServeCommand, - ChatCommand, - InitCommand, - PSCommand, - KillCommand, - PresetCommand, - EmbeddingCommand, - BenchmarkCommand, - EnginesCommand, + // CortexCommand, + // ModelsCommand, + // ServeCommand, + // ChatCommand, + // InitCommand, + // PSCommand, + // KillCommand, + // PresetCommand, + // EmbeddingCommand, + // BenchmarkCommand, + // EnginesCommand, - // Questions - InitRunModeQuestions, + // // Questions + // InitRunModeQuestions, - // Model commands - ModelStartCommand, - ModelStopCommand, - ModelListCommand, - ModelGetCommand, - ModelRemoveCommand, - ModelPullCommand, - ModelUpdateCommand, + // // Model commands + // ModelStartCommand, + // ModelStopCommand, + // ModelListCommand, + // ModelGetCommand, + // ModelRemoveCommand, + // ModelPullCommand, + // ModelUpdateCommand, - // Shortcuts - RunCommand, + // // Shortcuts + // RunCommand, - // Telemetry - TelemetryCommand, + // // Telemetry + // TelemetryCommand, - // Serve - ServeStopCommand, + // // Serve + // ServeStopCommand, - // // Configs - ConfigsCommand, - ConfigsGetCommand, - ConfigsListCommand, - ConfigsSetCommand, + // // // Configs + // ConfigsCommand, + // ConfigsGetCommand, + // ConfigsListCommand, + // ConfigsSetCommand, - // Engines - EnginesListCommand, - EnginesGetCommand, + // // Engines + // EnginesListCommand, + // EnginesGetCommand, ], }) export class CommandModule {} From 099ca97ed463e55e4545c0ff085ee41b9814761c Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 14:59:42 +0700 Subject: [PATCH 43/64] comment all module --- cortex-js/src/command.module.ts | 112 +++++++++--------- .../commanders/decorators/CommandContext.ts | 2 + 2 files changed, 58 insertions(+), 56 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index b48118bc1..56a66d5fb 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -51,71 +51,71 @@ console.time('import-command'); @Module({ imports: [ - // ConfigModule.forRoot({ - // isGlobal: true, - // envFilePath: - // process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', - // }), - // EventEmitterModule.forRoot(), - // DatabaseModule, - // ModelsModule, - // CortexModule, - // ExtensionModule, - // HttpModule, - // CliUsecasesModule, - // AssistantsModule, - // MessagesModule, - // FileManagerModule, - // TelemetryModule, - // ContextModule, - // DownloadManagerModule, - // ExtensionsModule, - // ConfigsModule, - // EnginesModule, + ConfigModule.forRoot({ + isGlobal: true, + envFilePath: + process.env.NODE_ENV !== 'production' ? '.env.development' : '.env', + }), + EventEmitterModule.forRoot(), + DatabaseModule, + ModelsModule, + CortexModule, + ExtensionModule, + HttpModule, + CliUsecasesModule, + AssistantsModule, + MessagesModule, + FileManagerModule, + TelemetryModule, + ContextModule, + DownloadManagerModule, + ExtensionsModule, + ConfigsModule, + EnginesModule, ], providers: [ - // CortexCommand, - // ModelsCommand, - // ServeCommand, - // ChatCommand, - // InitCommand, - // PSCommand, - // KillCommand, - // PresetCommand, - // EmbeddingCommand, - // BenchmarkCommand, - // EnginesCommand, + CortexCommand, + ModelsCommand, + ServeCommand, + ChatCommand, + InitCommand, + PSCommand, + KillCommand, + PresetCommand, + EmbeddingCommand, + BenchmarkCommand, + EnginesCommand, - // // Questions - // InitRunModeQuestions, + // Questions + InitRunModeQuestions, - // // Model commands - // ModelStartCommand, - // ModelStopCommand, - // ModelListCommand, - // ModelGetCommand, - // ModelRemoveCommand, - // ModelPullCommand, - // ModelUpdateCommand, + // Model commands + ModelStartCommand, + ModelStopCommand, + ModelListCommand, + ModelGetCommand, + ModelRemoveCommand, + ModelPullCommand, + ModelUpdateCommand, - // // Shortcuts - // RunCommand, + // Shortcuts + RunCommand, - // // Telemetry - // TelemetryCommand, + // Telemetry + TelemetryCommand, - // // Serve - // ServeStopCommand, + // Serve + ServeStopCommand, - // // // Configs - // ConfigsCommand, - // ConfigsGetCommand, - // ConfigsListCommand, - // ConfigsSetCommand, + // // Configs + ConfigsCommand, + ConfigsGetCommand, + ConfigsListCommand, + ConfigsSetCommand, - // // Engines - // EnginesListCommand, - // EnginesGetCommand, + // Engines + EnginesListCommand, + EnginesGetCommand, ], }) export class CommandModule {} diff --git a/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts b/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts index 04033c7cd..8f607a623 100644 --- a/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts +++ b/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts @@ -2,6 +2,7 @@ type Constructor = new (...args: any[]) => any; export const SetCommandContext = () => { return (constructor: Constructor) => { + console.time('SetCommandContext'); const classMethods = Object.getOwnPropertyNames(constructor.prototype); classMethods.forEach((methodName) => { @@ -30,5 +31,6 @@ export const SetCommandContext = () => { }; } }); + console.timeEnd('SetCommandContext'); }; }; From bd121bc0de95a9720f03eadf772d485d2826103c Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 15:06:59 +0700 Subject: [PATCH 44/64] comment all module --- .../infrastructure/commanders/decorators/CommandContext.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts b/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts index 8f607a623..7b71ec924 100644 --- a/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts +++ b/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts @@ -2,7 +2,9 @@ type Constructor = new (...args: any[]) => any; export const SetCommandContext = () => { return (constructor: Constructor) => { - console.time('SetCommandContext'); + const name = 'SetCommandContext' + constructor.name; + console.log('SetCommandContext', name); + console.time(name); const classMethods = Object.getOwnPropertyNames(constructor.prototype); classMethods.forEach((methodName) => { @@ -31,6 +33,6 @@ export const SetCommandContext = () => { }; } }); - console.timeEnd('SetCommandContext'); + console.timeEnd(name); }; }; From 6ba87a46b932be2f02ff9c28396e6cd2d4d01e31 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 15:23:54 +0700 Subject: [PATCH 45/64] comment all module --- cortex-js/src/command.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index 69a35c3ef..9f30edf70 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -1,12 +1,19 @@ #!/usr/bin/env node --no-warnings console.log('1'); console.time('import'); +console.time('imporCommandFactory'); import { CommandFactory } from 'nest-commander'; +console.timeEnd('imporCommandFactory'); +console.time('importCommandModule'); import { CommandModule } from './command.module'; +console.timeEnd('importCommandModule'); +console.time('importTelemetryUsecases'); import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; +console.timeEnd('importTelemetryUsecases'); +console.time('importContextService'); import { TelemetrySource } from './domain/telemetry/telemetry.interface'; import { ContextService } from '@/infrastructure/services/context/context.service'; - +console.timeEnd('importContextService'); console.timeEnd('import'); console.time('test'); console.log('Running CLI'); From a8fa3ddec1fcc1cb4f87ab1eee09d99bbec8fc72 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 15:39:25 +0700 Subject: [PATCH 46/64] comment all module --- cortex-js/src/command.module.ts | 92 +++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index 56a66d5fb..d9e8de607 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,50 +1,142 @@ console.time('import-command'); +console.time('import-command-module'); import { Module } from '@nestjs/common'; +console.timeEnd('import-command-module'); +console.time('import-command-model-module'); import { ModelsModule } from './usecases/models/models.module'; +console.timeEnd('import-command-model-module'); +console.time('import-command-database-module'); import { DatabaseModule } from './infrastructure/database/database.module'; +console.timeEnd('import-command-database-module'); +console.time('import-command-config-module'); import { ConfigModule } from '@nestjs/config'; +console.timeEnd('import-command-config-module'); +console.time('import-command-cortex-module'); import { CortexModule } from './usecases/cortex/cortex.module'; +console.timeEnd('import-command-cortex-module'); +console.time('import-command-server-command'); import { ServeCommand } from './infrastructure/commanders/serve.command'; +console.timeEnd('import-command-server-command'); +console.time('import-command-models-command'); import { ModelsCommand } from './infrastructure/commanders/models.command'; +console.timeEnd('import-command-models-command'); +console.time('import-command-extension-module'); import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; +console.timeEnd('import-command-extension-module'); +console.time('import-command-init-command'); import { InitCommand } from './infrastructure/commanders/init.command'; +console.timeEnd('import-command-init-command'); +console.time('import-command-http-module'); import { HttpModule } from '@nestjs/axios'; +console.timeEnd('import-command-http-module'); +console.time('import-command-questions'); import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; +console.timeEnd('import-command-questions'); +console.time('import-command-model-list-command'); import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; +console.timeEnd('import-command-model-list-command'); +console.time('import-command-model-pull-command'); import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; +console.timeEnd('import-command-model-pull-command'); +console.time('import-command-cortex-command'); import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; +console.timeEnd('import-command-cortex-command'); +console.time('import-command-chat-command'); import { ChatCommand } from './infrastructure/commanders/chat.command'; +console.timeEnd('import-command-chat-command'); +console.time('import-command-model-start-command'); import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; +console.timeEnd('import-command-model-start-command'); +console.time('import-command-model-stop-command'); import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; +console.timeEnd('import-command-model-stop-command'); +console.time('import-command-model-get-command'); import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; +console.timeEnd('import-command-model-get-command'); +console.time('import-command-model-remove-command'); import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; +console.timeEnd('import-command-model-remove-command'); +console.time('import-command-model-update-command'); import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; +console.timeEnd('import-command-model-update-command'); +console.time('import-command-model-update-command'); import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; +console.timeEnd('import-command-model-update-command'); +console.time('import-command-assistants-module'); import { AssistantsModule } from './usecases/assistants/assistants.module'; +console.timeEnd('import-command-assistants-module'); +console.time('import-command-messages-module'); import { MessagesModule } from './usecases/messages/messages.module'; +console.timeEnd('import-command-messages-module'); +console.time('import-command-file-manager-module'); import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; +console.timeEnd('import-command-file-manager-module'); +console.time('import-command-ps-command'); import { PSCommand } from './infrastructure/commanders/ps.command'; +console.timeEnd('import-command-ps-command'); +console.time('import-command-kill-command'); import { KillCommand } from './infrastructure/commanders/kill.command'; +console.timeEnd('import-command-kill-command'); +console.time('import-command-preset-command'); import { PresetCommand } from './infrastructure/commanders/presets.command'; +console.timeEnd('import-command-preset-command'); +console.time('import-command-telemetry-module'); import { TelemetryModule } from './usecases/telemetry/telemetry.module'; +console.timeEnd('import-command-telemetry-module'); +console.time('import-command-telemetry-command'); import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; +console.timeEnd('import-command-telemetry-command'); +console.time('import-command-embedding-command'); import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; +console.timeEnd('import-command-embedding-command'); +console.time('import-command-benchmark-command'); import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; +console.timeEnd('import-command-benchmark-command'); +console.time('import-command-event-emitter'); import { EventEmitterModule } from '@nestjs/event-emitter'; +console.timeEnd('import-command-event-emitter'); +console.time('import-command-download-manager'); import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; +console.timeEnd('import-command-download-manager'); +console.time('import-command-servestop-command'); import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; +console.timeEnd('import-command-servestop-command'); +console.time('import-command-context-module'); import { ContextModule } from './infrastructure/services/context/context.module'; +console.timeEnd('import-command-context-module'); +console.time('import-command-cli-usecases-module'); import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; +console.timeEnd('import-command-cli-usecases-module'); +console.time('import-command-extensions-module'); import { ExtensionsModule } from './extensions/extensions.module'; +console.timeEnd('import-command-extensions-module'); +console.time('import-command-configs-command'); import { ConfigsCommand } from './infrastructure/commanders/configs.command'; +console.timeEnd('import-command-configs-command'); +console.time('import-command-engines-command'); import { EnginesCommand } from './infrastructure/commanders/engines.command'; +console.timeEnd('import-command-engines-command'); +console.time('import-command-configs-module'); import { ConfigsModule } from './usecases/configs/configs.module'; +console.timeEnd('import-command-configs-module'); +console.time('import-command-engines-module'); import { EnginesModule } from './usecases/engines/engines.module'; +console.timeEnd('import-command-engines-module'); +console.time('import-command-configs-get-command'); import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; +console.timeEnd('import-command-configs-get-command'); +console.time('import-command-configs-list-command'); import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; +console.timeEnd('import-command-configs-list-command'); +console.time('import-command-configs-set-command'); import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; +console.timeEnd('import-command-configs-set-command'); +console.time('import-command-engines-list-command'); import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; +console.timeEnd('import-command-engines-list-command'); +console.time('import-command-engines-get-command'); import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; +console.timeEnd('import-command-engines-get-command'); console.timeEnd('import-command'); console.time('import-command'); From cdbba338154063613c6865f624937fbe06c23904 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 15:57:37 +0700 Subject: [PATCH 47/64] comment all module --- .../src/usecases/models/models.module.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cortex-js/src/usecases/models/models.module.ts b/cortex-js/src/usecases/models/models.module.ts index e5972941b..beb68c4b3 100644 --- a/cortex-js/src/usecases/models/models.module.ts +++ b/cortex-js/src/usecases/models/models.module.ts @@ -1,14 +1,36 @@ +console.time('import-command-models-module'); import { Module } from '@nestjs/common'; +console.timeEnd('import-command-models-module'); +console.time('import-command-models-model'); import { ModelsUsecases } from './models.usecases'; +console.timeEnd('import-command-models-model'); +console.time('import-command-models-database'); import { DatabaseModule } from '@/infrastructure/database/database.module'; +console.timeEnd('import-command-models-database'); +console.time('import-command-models-cortex'); import { CortexModule } from '@/usecases/cortex/cortex.module'; +console.timeEnd('import-command-models-cortex'); +console.time('import-command-models-extension'); import { ExtensionModule } from '@/infrastructure/repositories/extensions/extension.module'; +console.timeEnd('import-command-models-extension'); +console.time('import-command-models-http'); import { HttpModule } from '@nestjs/axios'; +console.timeEnd('import-command-models-http'); +console.time('import-command-models-telemetry'); import { TelemetryModule } from '../telemetry/telemetry.module'; +console.timeEnd('import-command-models-telemetry'); +console.time('import-command-models-file-manager'); import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module'; +console.timeEnd('import-command-models-file-manager'); +console.time('import-command-models-model-repository'); import { ModelRepositoryModule } from '@/infrastructure/repositories/models/model.module'; +console.timeEnd('import-command-models-model-repository'); +console.time('import-command-models-download-manager'); import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module'; +console.timeEnd('import-command-models-download-manager'); +console.time('import-command-models-context'); import { ContextModule } from '@/infrastructure/services/context/context.module'; +console.timeEnd('import-command-models-context'); @Module({ imports: [ From 7ceb8ab0c1b3c16d3261659f298a580dbb2ceaae Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 22:58:19 +0700 Subject: [PATCH 48/64] comment all module --- .../infrastructure/database/database.module.ts | 16 ++++++++++++++++ .../database/providers/thread.providers.ts | 15 +++++++++++++-- .../database/sqlite-database.providers.ts | 6 ++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index 2e7b3ae85..9d8a7cdcb 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -1,10 +1,26 @@ +console.time('import-command-database-module-total'); +console.time('import-command-database-module-module'); import { Module } from '@nestjs/common'; +console.timeEnd('import-command-database-module-module'); +console.time('import-command-database-module-thread-providers'); import { threadProviders } from './providers/thread.providers'; +console.timeEnd('import-command-database-module-thread-providers'); +console.time('import-command-database-module-sqlite-database-providers'); import { sqliteDatabaseProviders } from './sqlite-database.providers'; +console.timeEnd('import-command-database-module-sqlite-database-providers'); +console.time('import-command-database-module-assistant-providers'); import { assistantProviders } from './providers/assistant.providers'; +console.timeEnd('import-command-database-module-assistant-providers'); +console.time('import-command-database-module-message-providers'); import { messageProviders } from './providers/message.providers'; +console.timeEnd('import-command-database-module-message-providers'); +console.time('import-command-database-module-telemetry-providers'); import { telemetryProviders } from './providers/telemetry.providers'; +console.timeEnd('import-command-database-module-telemetry-providers'); +console.time('import-command-database-module-file-manager-module'); import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module'; +console.timeEnd('import-command-database-module-file-manager-module'); +console.timeEnd('import-command-database-module-total'); @Module({ imports: [FileManagerModule], diff --git a/cortex-js/src/infrastructure/database/providers/thread.providers.ts b/cortex-js/src/infrastructure/database/providers/thread.providers.ts index cc5a84916..b6bdc4204 100644 --- a/cortex-js/src/infrastructure/database/providers/thread.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/thread.providers.ts @@ -1,11 +1,22 @@ +console.time('threadProviders-import'); +console.time('threadProviders-threadentity'); import { ThreadEntity } from '@/infrastructure/entities/thread.entity'; +console.timeEnd('threadProviders-threadentity'); +console.time('threadProviders-typeorm'); import { DataSource } from 'typeorm'; +console.timeEnd('threadProviders-typeorm'); +console.timeEnd('threadProviders-import'); export const threadProviders = [ { provide: 'THREAD_REPOSITORY', - useFactory: (dataSource: DataSource) => - dataSource?.getRepository(ThreadEntity), + useFactory: async (dataSource: DataSource) =>{ + console.time('threadProviders'); + const result = await dataSource?.getRepository(ThreadEntity) + console.timeEnd('threadProviders'); + return result; + }, inject: ['DATA_SOURCE'], }, ]; + diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index 1fe587ed5..4ead09be2 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -11,6 +11,7 @@ export const sqliteDatabaseProviders = [ provide: 'DATA_SOURCE', inject: [FileManagerService], useFactory: async (fileManagerService: FileManagerService) => { + console.time('sqliteDatabaseProviders'); const dataFolderPath = await fileManagerService.getDataFolderPath(); const sqlitePath = join(dataFolderPath, databaseFile); const dataSource = new DataSource({ @@ -20,8 +21,9 @@ export const sqliteDatabaseProviders = [ entities: [ThreadEntity, AssistantEntity, MessageEntity], logging: true, }); - - return dataSource.initialize(); + const result = await dataSource.initialize(); + console.timeEnd('sqliteDatabaseProviders'); + return result; }, }, ]; From b8955a3f8558c26fcd49ffc45f5d698adfe6e74e Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 23:06:18 +0700 Subject: [PATCH 49/64] please work --- .../src/infrastructure/database/providers/thread.providers.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cortex-js/src/infrastructure/database/providers/thread.providers.ts b/cortex-js/src/infrastructure/database/providers/thread.providers.ts index b6bdc4204..4904ad447 100644 --- a/cortex-js/src/infrastructure/database/providers/thread.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/thread.providers.ts @@ -1,7 +1,4 @@ console.time('threadProviders-import'); -console.time('threadProviders-threadentity'); -import { ThreadEntity } from '@/infrastructure/entities/thread.entity'; -console.timeEnd('threadProviders-threadentity'); console.time('threadProviders-typeorm'); import { DataSource } from 'typeorm'; console.timeEnd('threadProviders-typeorm'); @@ -12,6 +9,7 @@ export const threadProviders = [ provide: 'THREAD_REPOSITORY', useFactory: async (dataSource: DataSource) =>{ console.time('threadProviders'); + const {ThreadEntity } = await import('../../entities/thread.entity'); const result = await dataSource?.getRepository(ThreadEntity) console.timeEnd('threadProviders'); return result; From 375b30d1997c1c611aa41483825898c538bc82ab Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 2 Jul 2024 23:33:32 +0700 Subject: [PATCH 50/64] please work --- .../database/mysql-database.providers.ts | 2 +- .../database/providers/assistant.providers.ts | 10 +++++----- .../database/providers/message.providers.ts | 10 +++++----- .../database/providers/thread.providers.ts | 3 +-- .../database/sqlite-database.providers.ts | 18 ++++++++++++++---- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/cortex-js/src/infrastructure/database/mysql-database.providers.ts b/cortex-js/src/infrastructure/database/mysql-database.providers.ts index ff756d5a8..004ce1a62 100644 --- a/cortex-js/src/infrastructure/database/mysql-database.providers.ts +++ b/cortex-js/src/infrastructure/database/mysql-database.providers.ts @@ -1,5 +1,4 @@ import { databaseName } from '@/infrastructure/constants/cortex'; -import { DataSource } from 'typeorm'; import { ThreadEntity } from '../entities/thread.entity'; import { AssistantEntity } from '../entities/assistant.entity'; import { MessageEntity } from '../entities/message.entity'; @@ -8,6 +7,7 @@ export const mysqlDatabaseProviders = [ { provide: 'DATA_SOURCE', useFactory: async () => { + const {DataSource} = await import('typeorm'); const dataSource = new DataSource({ type: 'mysql', host: 'localhost', diff --git a/cortex-js/src/infrastructure/database/providers/assistant.providers.ts b/cortex-js/src/infrastructure/database/providers/assistant.providers.ts index e8bea02d4..652f5b5b3 100644 --- a/cortex-js/src/infrastructure/database/providers/assistant.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/assistant.providers.ts @@ -1,11 +1,11 @@ -import { AssistantEntity } from '@/infrastructure/entities/assistant.entity'; -import { DataSource } from 'typeorm'; - export const assistantProviders = [ { provide: 'ASSISTANT_REPOSITORY', - useFactory: (dataSource: DataSource) => - dataSource?.getRepository(AssistantEntity), + useFactory: async(dataSource: any) =>{ + const {AssistantEntity } = await import('../../entities/assistant.entity'); + const result = await dataSource?.getRepository(AssistantEntity) + return result; + }, inject: ['DATA_SOURCE'], }, ]; diff --git a/cortex-js/src/infrastructure/database/providers/message.providers.ts b/cortex-js/src/infrastructure/database/providers/message.providers.ts index 388515aa1..324ee4a3b 100644 --- a/cortex-js/src/infrastructure/database/providers/message.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/message.providers.ts @@ -1,11 +1,11 @@ -import { MessageEntity } from '@/infrastructure/entities/message.entity'; -import { DataSource } from 'typeorm'; - export const messageProviders = [ { provide: 'MESSAGE_REPOSITORY', - useFactory: (dataSource: DataSource) => - dataSource?.getRepository(MessageEntity), + useFactory: async(dataSource: any) =>{ + const {MessageEntity } = await import('../../entities/message.entity'); + const result = await dataSource?.getRepository(MessageEntity) + return result; + }, inject: ['DATA_SOURCE'], }, ]; diff --git a/cortex-js/src/infrastructure/database/providers/thread.providers.ts b/cortex-js/src/infrastructure/database/providers/thread.providers.ts index 4904ad447..a21ade69b 100644 --- a/cortex-js/src/infrastructure/database/providers/thread.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/thread.providers.ts @@ -1,13 +1,12 @@ console.time('threadProviders-import'); console.time('threadProviders-typeorm'); -import { DataSource } from 'typeorm'; console.timeEnd('threadProviders-typeorm'); console.timeEnd('threadProviders-import'); export const threadProviders = [ { provide: 'THREAD_REPOSITORY', - useFactory: async (dataSource: DataSource) =>{ + useFactory: async (dataSource: any) =>{ console.time('threadProviders'); const {ThreadEntity } = await import('../../entities/thread.entity'); const result = await dataSource?.getRepository(ThreadEntity) diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index 4ead09be2..d091a8752 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -1,10 +1,16 @@ +console.time('sqliteDatabaseProviders-import'); +console.time('sqliteDatabaseProviders-file-manager-service'); import { FileManagerService } from '@/infrastructure/services/file-manager/file-manager.service'; +console.timeEnd('sqliteDatabaseProviders-file-manager-service'); +console.timeEnd('sqliteDatabaseProviders-database-file'); import { databaseFile } from '@/infrastructure/constants/cortex'; +console.timeEnd('sqliteDatabaseProviders-import'); +console.time('sqliteDatabaseProviders-import-path'); import { join } from 'path'; -import { DataSource } from 'typeorm'; -import { ThreadEntity } from '../entities/thread.entity'; -import { AssistantEntity } from '../entities/assistant.entity'; -import { MessageEntity } from '../entities/message.entity'; +console.timeEnd('sqliteDatabaseProviders-import-path'); +console.time('sqliteDatabaseProviders-import-typeorm'); +console.timeEnd('sqliteDatabaseProviders-import-typeorm'); +console.time('sqliteDatabaseProviders-import'); export const sqliteDatabaseProviders = [ { @@ -13,7 +19,11 @@ export const sqliteDatabaseProviders = [ useFactory: async (fileManagerService: FileManagerService) => { console.time('sqliteDatabaseProviders'); const dataFolderPath = await fileManagerService.getDataFolderPath(); + const { ThreadEntity } = await import('../entities/thread.entity'); + const { AssistantEntity } = await import('../entities/assistant.entity'); + const { MessageEntity } = await import('../entities/message.entity'); const sqlitePath = join(dataFolderPath, databaseFile); + const { DataSource } = await import('typeorm'); const dataSource = new DataSource({ type: 'sqlite', database: sqlitePath, From 70c8339e7c6557eee3f6e6c70a50854183288010 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Wed, 3 Jul 2024 00:07:59 +0700 Subject: [PATCH 51/64] please work --- .../src/infrastructure/database/mysql-database.providers.ts | 2 +- .../src/infrastructure/database/providers/thread.providers.ts | 3 ++- .../src/infrastructure/database/sqlite-database.providers.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cortex-js/src/infrastructure/database/mysql-database.providers.ts b/cortex-js/src/infrastructure/database/mysql-database.providers.ts index 004ce1a62..f3880e9f2 100644 --- a/cortex-js/src/infrastructure/database/mysql-database.providers.ts +++ b/cortex-js/src/infrastructure/database/mysql-database.providers.ts @@ -16,7 +16,7 @@ export const mysqlDatabaseProviders = [ password: '', database: databaseName, entities: [ThreadEntity, AssistantEntity, MessageEntity], - synchronize: process.env.NODE_ENV !== 'production', + synchronize: false, }); return dataSource.initialize(); diff --git a/cortex-js/src/infrastructure/database/providers/thread.providers.ts b/cortex-js/src/infrastructure/database/providers/thread.providers.ts index a21ade69b..4904ad447 100644 --- a/cortex-js/src/infrastructure/database/providers/thread.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/thread.providers.ts @@ -1,12 +1,13 @@ console.time('threadProviders-import'); console.time('threadProviders-typeorm'); +import { DataSource } from 'typeorm'; console.timeEnd('threadProviders-typeorm'); console.timeEnd('threadProviders-import'); export const threadProviders = [ { provide: 'THREAD_REPOSITORY', - useFactory: async (dataSource: any) =>{ + useFactory: async (dataSource: DataSource) =>{ console.time('threadProviders'); const {ThreadEntity } = await import('../../entities/thread.entity'); const result = await dataSource?.getRepository(ThreadEntity) diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index d091a8752..f672cfb18 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -27,7 +27,7 @@ export const sqliteDatabaseProviders = [ const dataSource = new DataSource({ type: 'sqlite', database: sqlitePath, - synchronize: process.env.NODE_ENV !== 'production', + synchronize: false, entities: [ThreadEntity, AssistantEntity, MessageEntity], logging: true, }); From 1997e4301474559b97383718fa34383e109ac267 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Wed, 3 Jul 2024 00:14:41 +0700 Subject: [PATCH 52/64] please work --- cortex-js/src/infrastructure/commanders/serve.command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cortex-js/src/infrastructure/commanders/serve.command.ts b/cortex-js/src/infrastructure/commanders/serve.command.ts index 4eaa7bc45..06276b1fa 100644 --- a/cortex-js/src/infrastructure/commanders/serve.command.ts +++ b/cortex-js/src/infrastructure/commanders/serve.command.ts @@ -6,7 +6,6 @@ import { CommandRunner, SubCommand, Option } from 'nest-commander'; import { SetCommandContext } from './decorators/CommandContext'; import { ServeStopCommand } from './sub-commands/serve-stop.command'; import { ContextService } from '../services/context/context.service'; -import { getApp } from '@/app'; import chalk from 'chalk'; type ServeOptions = { @@ -34,6 +33,7 @@ export class ServeCommand extends CommandRunner { } private async startServer(host: string, port: number) { + const { getApp } = await import('@/app'); const app = await getApp(); try { From ccb20177996930c4f777d2d024c59a889fb2e419 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Wed, 3 Jul 2024 01:20:11 +0700 Subject: [PATCH 53/64] add time require --- cortex-js/src/command.ts | 1 + .../infrastructure/commanders/chat.command.ts | 14 +++++++ .../commanders/cortex-command.commander.ts | 42 +++++++++++++++++++ .../database/sqlite-database.providers.ts | 3 +- 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index 9f30edf70..f1080476b 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -2,6 +2,7 @@ console.log('1'); console.time('import'); console.time('imporCommandFactory'); +require("time-require"); import { CommandFactory } from 'nest-commander'; console.timeEnd('imporCommandFactory'); console.time('importCommandModule'); diff --git a/cortex-js/src/infrastructure/commanders/chat.command.ts b/cortex-js/src/infrastructure/commanders/chat.command.ts index 0124ab54c..89e6777fe 100644 --- a/cortex-js/src/infrastructure/commanders/chat.command.ts +++ b/cortex-js/src/infrastructure/commanders/chat.command.ts @@ -4,13 +4,27 @@ import { Option, InquirerService, } from 'nest-commander'; +console.time('import-command-chat-cli-usecases'); import { ChatCliUsecases } from './usecases/chat.cli.usecases'; +console.timeEnd('import-command-chat-cli-usecases'); +console.time('import-command-chat-exit'); import { exit } from 'node:process'; +console.timeEnd('import-command-chat-exit'); +console.time('import-command-chat-ps-cli-usecases'); import { PSCliUsecases } from './usecases/ps.cli.usecases'; +console.timeEnd('import-command-chat-ps-cli-usecases'); +console.time('import-command-chat-models-usecases'); import { ModelsUsecases } from '@/usecases/models/models.usecases'; +console.timeEnd('import-command-chat-models-usecases'); +console.time('import-command-chat-types'); import { SetCommandContext } from './decorators/CommandContext'; +console.timeEnd('import-command-chat-types'); +console.time('import-command-chat-types'); import { ModelStat } from './types/model-stat.interface'; +console.timeEnd('import-command-chat-types'); +console.time('import-command-chat-types'); import { ContextService } from '../services/context/context.service'; +console.timeEnd('import-command-chat-types'); type ChatOptions = { threadId?: string; diff --git a/cortex-js/src/infrastructure/commanders/cortex-command.commander.ts b/cortex-js/src/infrastructure/commanders/cortex-command.commander.ts index 9ba0d23ed..d2fcd9889 100644 --- a/cortex-js/src/infrastructure/commanders/cortex-command.commander.ts +++ b/cortex-js/src/infrastructure/commanders/cortex-command.commander.ts @@ -1,23 +1,65 @@ +console.time('import-cortex-command-time'); +console.time('import-cortex-command-commander'); import { RootCommand, CommandRunner } from 'nest-commander'; +console.timeEnd('import-cortex-command-commander'); +console.time('import-cortex-command-serve-command'); import { ServeCommand } from './serve.command'; +console.timeEnd('import-cortex-command-serve-command'); +console.time('import-cortex-command-chat-command'); import { ChatCommand } from './chat.command'; +console.timeEnd('import-cortex-command-chat-command'); +console.time('import-cortex-command-models-command'); import { ModelsCommand } from './models.command'; +console.timeEnd('import-cortex-command-models-command'); +console.time('import-cortex-command-init-command'); import { InitCommand } from './init.command'; +console.timeEnd('import-cortex-command-init-command'); +console.time('import-cortex-command-run-command'); import { RunCommand } from './shortcuts/run.command'; +console.timeEnd('import-cortex-command-run-command'); +console.time('import-cortex-command-model-pull-command'); import { ModelPullCommand } from './models/model-pull.command'; +console.timeEnd('import-cortex-command-model-pull-command'); +console.time('import-cortex-command-ps-command'); import { PSCommand } from './ps.command'; +console.timeEnd('import-cortex-command-ps-command'); +console.time('import-cortex-command-kill-command'); import { KillCommand } from './kill.command'; +console.timeEnd('import-cortex-command-kill-command'); +console.time('import-cortex-command-preset-command'); import pkg from '@/../package.json'; +console.timeEnd('import-cortex-command-preset-command'); +console.time('import-cortex-command-telemetry-command'); import { PresetCommand } from './presets.command'; +console.timeEnd('import-cortex-command-telemetry-command'); +console.time('import-cortex-command-telemetry-command'); import { TelemetryCommand } from './telemetry.command'; +console.timeEnd('import-cortex-command-telemetry-command'); +console.time('import-cortex-command-embedding-command'); import { SetCommandContext } from './decorators/CommandContext'; +console.timeEnd('import-cortex-command-embedding-command'); +console.time('import-cortex-command-benchmark-command'); import { EmbeddingCommand } from './embeddings.command'; +console.timeEnd('import-cortex-command-benchmark-command'); +console.time('import-cortex-command-engines-command'); import { BenchmarkCommand } from './benchmark.command'; +console.timeEnd('import-cortex-command-engines-command'); +console.time('import-cortex-command-configs-command'); import chalk from 'chalk'; +console.timeEnd('import-cortex-command-configs-command'); +console.time('import-cortex-command-configs-command'); import { printSlogan } from '@/utils/logo'; +console.timeEnd('import-cortex-command-configs-command'); +console.time('import-cortex-command-configs-command'); import { ContextService } from '../services/context/context.service'; +console.timeEnd('import-cortex-command-configs-command'); +console.time('import-cortex-command-configs-command'); import { EnginesCommand } from './engines.command'; +console.timeEnd('import-cortex-command-configs-command'); +console.time('import-cortex-command-configs-command'); import { ConfigsCommand } from './configs.command'; +console.timeEnd('import-cortex-command-configs-command'); +console.time('import-cortex-command-time'); @RootCommand({ subCommands: [ diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index f672cfb18..e24366c85 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -9,6 +9,7 @@ console.time('sqliteDatabaseProviders-import-path'); import { join } from 'path'; console.timeEnd('sqliteDatabaseProviders-import-path'); console.time('sqliteDatabaseProviders-import-typeorm'); +import { DataSource } from 'typeorm'; console.timeEnd('sqliteDatabaseProviders-import-typeorm'); console.time('sqliteDatabaseProviders-import'); @@ -23,7 +24,7 @@ export const sqliteDatabaseProviders = [ const { AssistantEntity } = await import('../entities/assistant.entity'); const { MessageEntity } = await import('../entities/message.entity'); const sqlitePath = join(dataFolderPath, databaseFile); - const { DataSource } = await import('typeorm'); + const dataSource = new DataSource({ type: 'sqlite', database: sqlitePath, From d57830c50b1df8eec4a42d721b8b7c09ee96b0b9 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Wed, 3 Jul 2024 01:34:11 +0700 Subject: [PATCH 54/64] add time require package --- cortex-js/package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cortex-js/package.json b/cortex-js/package.json index 87b95cc6f..719a7be09 100644 --- a/cortex-js/package.json +++ b/cortex-js/package.json @@ -54,11 +54,13 @@ "decompress": "^4.2.1", "js-yaml": "^4.1.0", "nest-commander": "^3.13.0", + "perftrace": "^1.2.1", "readline": "^1.3.0", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", "sqlite3": "^5.1.7", "systeminformation": "^5.22.11", + "time-require": "^0.1.2", "typeorm": "^0.3.20", "ulid": "^2.3.0", "uuid": "^9.0.1", From 0989c3aae236504ddfcaa3bef7580e5d2184c92a Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Wed, 3 Jul 2024 21:05:20 +0700 Subject: [PATCH 55/64] remove type orm --- .../commanders/usecases/chat.cli.usecases.ts | 2 +- .../database/mysql-database.providers.ts | 25 ------- .../database/providers/assistant.providers.ts | 9 ++- .../database/providers/message.providers.ts | 9 ++- .../database/providers/thread.providers.ts | 11 +-- .../database/sqlite-database.providers.ts | 22 +++--- .../entities/assistant.entity.ts | 73 ++++++++++++++----- .../infrastructure/entities/message.entity.ts | 70 +++++++++++++----- .../infrastructure/entities/thread.entity.ts | 38 +++++++--- .../assistants/assistants.usecases.ts | 11 +-- .../usecases/messages/messages.usecases.ts | 9 ++- .../src/usecases/threads/threads.usecases.ts | 40 ++++++---- 12 files changed, 193 insertions(+), 126 deletions(-) delete mode 100644 cortex-js/src/infrastructure/database/mysql-database.providers.ts diff --git a/cortex-js/src/infrastructure/commanders/usecases/chat.cli.usecases.ts b/cortex-js/src/infrastructure/commanders/usecases/chat.cli.usecases.ts index 710a13902..6c0ffbc8a 100644 --- a/cortex-js/src/infrastructure/commanders/usecases/chat.cli.usecases.ts +++ b/cortex-js/src/infrastructure/commanders/usecases/chat.cli.usecases.ts @@ -41,7 +41,7 @@ export class ChatCliUsecases { const thread = await this.getOrCreateNewThread(modelId, threadId); const messages: ChatCompletionMessage[] = ( await this.messagesUsecases.getLastMessagesByThread(thread.id, 10) - ).map((message) => ({ + ).map((message: any) => ({ content: (message.content[0] as TextContentBlock).text.value, role: message.role, })); diff --git a/cortex-js/src/infrastructure/database/mysql-database.providers.ts b/cortex-js/src/infrastructure/database/mysql-database.providers.ts deleted file mode 100644 index f3880e9f2..000000000 --- a/cortex-js/src/infrastructure/database/mysql-database.providers.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { databaseName } from '@/infrastructure/constants/cortex'; -import { ThreadEntity } from '../entities/thread.entity'; -import { AssistantEntity } from '../entities/assistant.entity'; -import { MessageEntity } from '../entities/message.entity'; - -export const mysqlDatabaseProviders = [ - { - provide: 'DATA_SOURCE', - useFactory: async () => { - const {DataSource} = await import('typeorm'); - const dataSource = new DataSource({ - type: 'mysql', - host: 'localhost', - port: 3306, - username: 'root', - password: '', - database: databaseName, - entities: [ThreadEntity, AssistantEntity, MessageEntity], - synchronize: false, - }); - - return dataSource.initialize(); - }, - }, -]; diff --git a/cortex-js/src/infrastructure/database/providers/assistant.providers.ts b/cortex-js/src/infrastructure/database/providers/assistant.providers.ts index 652f5b5b3..02ed0c90d 100644 --- a/cortex-js/src/infrastructure/database/providers/assistant.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/assistant.providers.ts @@ -1,10 +1,11 @@ +import { AssistantEntity } from '@/infrastructure/entities/assistant.entity'; +import { Sequelize } from 'sequelize-typescript'; + export const assistantProviders = [ { provide: 'ASSISTANT_REPOSITORY', - useFactory: async(dataSource: any) =>{ - const {AssistantEntity } = await import('../../entities/assistant.entity'); - const result = await dataSource?.getRepository(AssistantEntity) - return result; + useFactory: async(sequelize: Sequelize) =>{ + return sequelize.getRepository(AssistantEntity); }, inject: ['DATA_SOURCE'], }, diff --git a/cortex-js/src/infrastructure/database/providers/message.providers.ts b/cortex-js/src/infrastructure/database/providers/message.providers.ts index 324ee4a3b..aa6cc9261 100644 --- a/cortex-js/src/infrastructure/database/providers/message.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/message.providers.ts @@ -1,10 +1,11 @@ +import { MessageEntity } from "@/infrastructure/entities/message.entity"; +import { Sequelize } from "sequelize-typescript"; + export const messageProviders = [ { provide: 'MESSAGE_REPOSITORY', - useFactory: async(dataSource: any) =>{ - const {MessageEntity } = await import('../../entities/message.entity'); - const result = await dataSource?.getRepository(MessageEntity) - return result; + useFactory: async(sequelize: Sequelize) =>{ + return sequelize.getRepository(MessageEntity); }, inject: ['DATA_SOURCE'], }, diff --git a/cortex-js/src/infrastructure/database/providers/thread.providers.ts b/cortex-js/src/infrastructure/database/providers/thread.providers.ts index 4904ad447..cde488847 100644 --- a/cortex-js/src/infrastructure/database/providers/thread.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/thread.providers.ts @@ -1,18 +1,15 @@ console.time('threadProviders-import'); console.time('threadProviders-typeorm'); -import { DataSource } from 'typeorm'; +import { ThreadEntity } from '@/infrastructure/entities/thread.entity'; +import { Sequelize } from 'sequelize-typescript'; console.timeEnd('threadProviders-typeorm'); console.timeEnd('threadProviders-import'); export const threadProviders = [ { provide: 'THREAD_REPOSITORY', - useFactory: async (dataSource: DataSource) =>{ - console.time('threadProviders'); - const {ThreadEntity } = await import('../../entities/thread.entity'); - const result = await dataSource?.getRepository(ThreadEntity) - console.timeEnd('threadProviders'); - return result; + useFactory: async(sequelize: Sequelize) =>{ + return sequelize.getRepository(ThreadEntity); }, inject: ['DATA_SOURCE'], }, diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index e24366c85..1ff7fa3e0 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -9,7 +9,10 @@ console.time('sqliteDatabaseProviders-import-path'); import { join } from 'path'; console.timeEnd('sqliteDatabaseProviders-import-path'); console.time('sqliteDatabaseProviders-import-typeorm'); -import { DataSource } from 'typeorm'; +import { ThreadEntity } from '../entities/thread.entity'; +import { MessageEntity } from '../entities/message.entity'; +import { AssistantEntity } from '../entities/assistant.entity'; +import { Sequelize } from 'sequelize-typescript'; console.timeEnd('sqliteDatabaseProviders-import-typeorm'); console.time('sqliteDatabaseProviders-import'); @@ -20,21 +23,14 @@ export const sqliteDatabaseProviders = [ useFactory: async (fileManagerService: FileManagerService) => { console.time('sqliteDatabaseProviders'); const dataFolderPath = await fileManagerService.getDataFolderPath(); - const { ThreadEntity } = await import('../entities/thread.entity'); - const { AssistantEntity } = await import('../entities/assistant.entity'); - const { MessageEntity } = await import('../entities/message.entity'); const sqlitePath = join(dataFolderPath, databaseFile); - const dataSource = new DataSource({ - type: 'sqlite', - database: sqlitePath, - synchronize: false, - entities: [ThreadEntity, AssistantEntity, MessageEntity], - logging: true, + const sequelize = new Sequelize({ + dialect: 'sqlite', + storage: sqlitePath, }); - const result = await dataSource.initialize(); - console.timeEnd('sqliteDatabaseProviders'); - return result; + sequelize.addModels([ThreadEntity, MessageEntity, AssistantEntity]); + return sequelize; }, }, ]; diff --git a/cortex-js/src/infrastructure/entities/assistant.entity.ts b/cortex-js/src/infrastructure/entities/assistant.entity.ts index 9eb5fcb15..cea9f89e2 100644 --- a/cortex-js/src/infrastructure/entities/assistant.entity.ts +++ b/cortex-js/src/infrastructure/entities/assistant.entity.ts @@ -1,51 +1,90 @@ +import { Table, Column, Model, PrimaryKey, DataType } from 'sequelize-typescript'; import { Assistant } from '@/domain/models/assistant.interface'; import type { AssistantToolResources, AssistantResponseFormatOption, } from '@/domain/models/assistant.interface'; -import { Column, Entity, PrimaryColumn } from 'typeorm'; -@Entity('assistants') -export class AssistantEntity implements Assistant { - @PrimaryColumn({ type: String }) +@Table({ tableName: 'assistants' }) +export class AssistantEntity extends Model implements Assistant { + @PrimaryKey + @Column({ + type: DataType.STRING, + }) id: string; - @Column({ type: String, nullable: true }) + @Column({ + type: DataType.STRING, + allowNull: true, + }) avatar?: string; - @Column({ type: String }) + @Column({ + type: DataType.STRING, + defaultValue: 'assistant', + }) object: 'assistant'; - @Column({ type: Number }) + @Column({ + type: DataType.INTEGER, + }) created_at: number; - @Column({ type: String, nullable: true }) + @Column({ + type: DataType.STRING, + allowNull: true, + }) name: string | null; - @Column({ type: String, nullable: true }) + @Column({ + type: DataType.STRING, + allowNull: true, + }) description: string | null; - @Column({ type: String }) + @Column({ + type: DataType.STRING, + }) model: string; - @Column({ type: String, nullable: true }) + @Column({ + type: DataType.STRING, + allowNull: true, + }) instructions: string | null; - @Column({ type: 'simple-json' }) + @Column({ + type: DataType.JSON, + }) tools: any; - @Column({ type: 'simple-json', nullable: true }) + @Column({ + type: DataType.JSON, + allowNull: true, + }) metadata: any | null; - @Column({ type: Number, nullable: true }) + @Column({ + type: DataType.FLOAT, + allowNull: true, + }) top_p: number | null; - @Column({ type: Number, nullable: true }) + @Column({ + type: DataType.FLOAT, + allowNull: true, + }) temperature: number | null; - @Column({ type: 'simple-json', nullable: true }) + @Column({ + type: DataType.JSON, + allowNull: true, + }) response_format: AssistantResponseFormatOption | null; - @Column({ type: 'simple-json', nullable: true }) + @Column({ + type: DataType.JSON, + allowNull: true, + }) tool_resources: AssistantToolResources | null; } diff --git a/cortex-js/src/infrastructure/entities/message.entity.ts b/cortex-js/src/infrastructure/entities/message.entity.ts index 8e009d9c6..06975dd51 100644 --- a/cortex-js/src/infrastructure/entities/message.entity.ts +++ b/cortex-js/src/infrastructure/entities/message.entity.ts @@ -1,52 +1,88 @@ +import { Table, Column, Model, PrimaryKey, DataType } from 'sequelize-typescript'; import type { Message, MessageContent, MessageIncompleteDetails, MessageAttachment, } from '@/domain/models/message.interface'; -import { Column, Entity, PrimaryColumn } from 'typeorm'; -@Entity('messages') -export class MessageEntity implements Message { - @PrimaryColumn({ type: String }) +@Table({ tableName: 'messages' }) +export class MessageEntity extends Model implements Message { + @PrimaryKey + @Column({ + type: DataType.STRING, + }) id: string; - @Column({ type: String }) + @Column({ + type: DataType.STRING, + defaultValue: 'thread.message', + }) object: 'thread.message'; - @Column({ type: String }) + @Column({ + type: DataType.STRING, + }) thread_id: string; - @Column({ type: String, nullable: true }) + @Column({ + type: DataType.STRING, + allowNull: true, + }) assistant_id: string | null; - @Column({ type: String }) + @Column({ + type: DataType.STRING, + }) role: 'user' | 'assistant'; - @Column({ type: String }) + @Column({ + type: DataType.STRING, + }) status: 'in_progress' | 'incomplete' | 'completed'; - @Column({ type: 'simple-json', nullable: true }) + @Column({ + type: DataType.JSON, + allowNull: true, + }) metadata: any | null; - @Column({ type: String, nullable: true }) + @Column({ + type: DataType.STRING, + allowNull: true, + }) run_id: string | null; - @Column({ type: Number, nullable: true }) + @Column({ + type: DataType.INTEGER, + allowNull: true, + }) completed_at: number | null; - @Column({ type: 'simple-json' }) + @Column({ + type: DataType.JSON, + }) content: MessageContent[]; - @Column({ type: 'simple-json', nullable: true }) + @Column({ + type: DataType.JSON, + allowNull: true, + }) incomplete_details: MessageIncompleteDetails | null; - @Column({ type: Number }) + @Column({ + type: DataType.INTEGER, + }) created_at: number; - @Column({ type: 'simple-json' }) + @Column({ + type: DataType.JSON, + }) attachments: MessageAttachment[]; - @Column({ type: Number, nullable: true }) + @Column({ + type: DataType.INTEGER, + allowNull: true, + }) incomplete_at: number | null; } diff --git a/cortex-js/src/infrastructure/entities/thread.entity.ts b/cortex-js/src/infrastructure/entities/thread.entity.ts index c53f2559d..69bfb6d5b 100644 --- a/cortex-js/src/infrastructure/entities/thread.entity.ts +++ b/cortex-js/src/infrastructure/entities/thread.entity.ts @@ -1,27 +1,45 @@ +import { Table, Column, Model, PrimaryKey, DataType } from 'sequelize-typescript'; import type { Thread, ThreadToolResources } from '@/domain/models/thread.interface'; -import { Entity, PrimaryColumn, Column } from 'typeorm'; import { AssistantEntity } from './assistant.entity'; -@Entity('threads') -export class ThreadEntity implements Thread { - @PrimaryColumn({ type: String }) +@Table({ tableName: 'threads' }) +export class ThreadEntity extends Model implements Thread { + @PrimaryKey + @Column({ + type: DataType.STRING, + }) id: string; - @Column({ type: String }) + @Column({ + type: DataType.STRING, + defaultValue: 'thread', + }) object: 'thread'; - @Column({ type: String, name: 'title' }) + @Column({ + type: DataType.STRING, + }) title: string; - @Column({ type: 'simple-json' }) + @Column({ + type: DataType.JSON, + }) assistants: AssistantEntity[]; - @Column({ type: Number }) + @Column({ + type: DataType.INTEGER, + }) created_at: number; - @Column({ type: 'simple-json', nullable: true }) + @Column({ + type: DataType.JSON, + allowNull: true, + }) tool_resources: ThreadToolResources | null; - @Column({ type: 'simple-json', nullable: true }) + @Column({ + type: DataType.JSON, + allowNull: true, + }) metadata: any | null; } diff --git a/cortex-js/src/usecases/assistants/assistants.usecases.ts b/cortex-js/src/usecases/assistants/assistants.usecases.ts index 2c9c1bb68..af09a0454 100644 --- a/cortex-js/src/usecases/assistants/assistants.usecases.ts +++ b/cortex-js/src/usecases/assistants/assistants.usecases.ts @@ -1,18 +1,17 @@ import { Inject, Injectable } from '@nestjs/common'; -import { AssistantEntity } from '@/infrastructure/entities/assistant.entity'; -import { QueryFailedError, Repository } from 'typeorm'; import { CreateAssistantDto } from '@/infrastructure/dtos/assistants/create-assistant.dto'; import { Assistant } from '@/domain/models/assistant.interface'; import { PageDto } from '@/infrastructure/dtos/page.dto'; import { ModelRepository } from '@/domain/repositories/model.interface'; import { ModelNotFoundException } from '@/infrastructure/exception/model-not-found.exception'; import { DuplicateAssistantException } from '@/infrastructure/exception/duplicate-assistant.exception'; +import { Repository } from 'sequelize-typescript'; @Injectable() export class AssistantsUsecases { constructor( @Inject('ASSISTANT_REPOSITORY') - private readonly assistantRepository: Repository, + private readonly assistantRepository: any, private readonly modelRepository: ModelRepository, ) {} @@ -25,7 +24,7 @@ export class AssistantsUsecases { } } - const assistant: AssistantEntity = { + const assistant: Assistant = { ...createAssistantDto, object: 'assistant', created_at: Date.now(), @@ -38,10 +37,6 @@ export class AssistantsUsecases { try { await this.assistantRepository.insert(assistant); } catch (err) { - if (err instanceof QueryFailedError) { - if (err.driverError.code === 'SQLITE_CONSTRAINT') - throw new DuplicateAssistantException(id); - } throw err; } diff --git a/cortex-js/src/usecases/messages/messages.usecases.ts b/cortex-js/src/usecases/messages/messages.usecases.ts index 9ae758e88..9009251c5 100644 --- a/cortex-js/src/usecases/messages/messages.usecases.ts +++ b/cortex-js/src/usecases/messages/messages.usecases.ts @@ -1,20 +1,21 @@ import { Inject, Injectable } from '@nestjs/common'; import { CreateMessageDto } from '@/infrastructure/dtos/messages/create-message.dto'; import { UpdateMessageDto } from '@/infrastructure/dtos/messages/update-message.dto'; -import { Repository } from 'typeorm'; import { MessageEntity } from '@/infrastructure/entities/message.entity'; import { ulid } from 'ulid'; +import { Repository } from 'sequelize-typescript'; +import { Message } from '@/domain/models/message.interface'; @Injectable() export class MessagesUsecases { constructor( @Inject('MESSAGE_REPOSITORY') - private messageRepository: Repository, + private messageRepository: any, ) {} async create(createMessageDto: CreateMessageDto) { const { assistant_id } = createMessageDto; - const message: MessageEntity = { + const message: Message = { ...createMessageDto, id: ulid(), created_at: Date.now(), @@ -43,7 +44,7 @@ export class MessagesUsecases { } update(id: string, updateMessageDto: UpdateMessageDto) { - const updateEntity: Partial = { + const updateEntity: Partial = { ...updateMessageDto, }; return this.messageRepository.update(id, updateEntity); diff --git a/cortex-js/src/usecases/threads/threads.usecases.ts b/cortex-js/src/usecases/threads/threads.usecases.ts index 0a06e971b..bd59d449c 100644 --- a/cortex-js/src/usecases/threads/threads.usecases.ts +++ b/cortex-js/src/usecases/threads/threads.usecases.ts @@ -2,7 +2,6 @@ import { Inject, Injectable, NotFoundException } from '@nestjs/common'; import { CreateThreadDto } from '@/infrastructure/dtos/threads/create-thread.dto'; import { UpdateThreadDto } from '@/infrastructure/dtos/threads/update-thread.dto'; import { ThreadEntity } from '@/infrastructure/entities/thread.entity'; -import { Repository } from 'typeorm'; import { v4 as uuidv4 } from 'uuid'; import { MessageEntity } from '@/infrastructure/entities/message.entity'; import { PageDto } from '@/infrastructure/dtos/page.dto'; @@ -13,21 +12,23 @@ import { UpdateMessageDto } from '@/infrastructure/dtos/threads/update-message.d import { Thread } from '@/domain/models/thread.interface'; import DeleteMessageDto from '@/infrastructure/dtos/threads/delete-message.dto'; import { AssistantEntity } from '@/infrastructure/entities/assistant.entity'; +import { Repository } from 'sequelize-typescript'; +import { Assistant } from '@/domain/models/assistant.interface'; @Injectable() export class ThreadsUsecases { constructor( @Inject('THREAD_REPOSITORY') - private threadRepository: Repository, + private threadRepository: any, @Inject('MESSAGE_REPOSITORY') - private messageRepository: Repository, + private messageRepository: any, ) {} async create(createThreadDto: CreateThreadDto): Promise { const id = uuidv4(); const { assistants } = createThreadDto; - const assistantEntity: AssistantEntity[] = assistants.map((assistant) => { - const entity: AssistantEntity = { + const assistantEntity: Assistant[] = assistants.map((assistant) => { + const entity: Assistant = { ...assistant, response_format: null, tool_resources: null, @@ -37,7 +38,7 @@ export class ThreadsUsecases { return entity; }); - const thread: ThreadEntity = { + const thread: Thread = { id, assistants: assistantEntity, object: 'thread', @@ -46,15 +47,22 @@ export class ThreadsUsecases { tool_resources: null, metadata: null, }; - await this.threadRepository.insert(thread); - return thread; + await this.threadRepository.create({ + id, + assistants: assistantEntity, + object: 'thread', + created_at: Date.now(), + title: 'New Thread', + tool_resources: null, + metadata: null, + }); + return thread as ThreadEntity; } async findAll(): Promise { - return this.threadRepository.find({ - order: { - created_at: 'DESC', - }, + return this.threadRepository.findAll({ + include: [AssistantEntity], + order: [['created_at', 'DESC']], }); } @@ -113,7 +121,7 @@ export class ThreadsUsecases { }, }; - const message: MessageEntity = { + const message: Message = { id: ulid(), object: 'thread.message', thread_id: threadId, @@ -172,9 +180,9 @@ export class ThreadsUsecases { } async update(id: string, updateThreadDto: UpdateThreadDto) { - const assistantEntities: AssistantEntity[] = + const assistantEntities: Assistant[] = updateThreadDto.assistants?.map((assistant) => { - const entity: AssistantEntity = { + const entity: Assistant = { ...assistant, name: assistant.name, response_format: null, @@ -185,7 +193,7 @@ export class ThreadsUsecases { return entity; }) ?? []; - const entity: Partial = { + const entity: Partial = { ...updateThreadDto, assistants: assistantEntities, }; From f0af975c9a12867a4834b95f598a4cb7a34e8710 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Wed, 3 Jul 2024 21:15:47 +0700 Subject: [PATCH 56/64] update package.json --- cortex-js/package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cortex-js/package.json b/cortex-js/package.json index 719a7be09..9fad1c91c 100644 --- a/cortex-js/package.json +++ b/cortex-js/package.json @@ -44,6 +44,7 @@ "@nestjs/event-emitter": "^2.0.4", "@nestjs/mapped-types": "*", "@nestjs/platform-express": "^10.0.0", + "@nestjs/sequelize": "^10.0.1", "@nestjs/swagger": "^7.3.1", "@terascope/fetch-github-release": "^0.8.8", "axios": "^1.6.8", @@ -58,10 +59,11 @@ "readline": "^1.3.0", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", + "sequelize": "^6.37.3", + "sequelize-typescript": "^2.1.6", "sqlite3": "^5.1.7", "systeminformation": "^5.22.11", "time-require": "^0.1.2", - "typeorm": "^0.3.20", "ulid": "^2.3.0", "uuid": "^9.0.1", "yaml": "^2.4.2" @@ -70,13 +72,13 @@ "@nestjs/cli": "^10.0.0", "@nestjs/schematics": "^10.0.0", "@nestjs/testing": "^10.0.0", - "@nestjs/typeorm": "^10.0.2", "@types/cli-progress": "^3.11.5", "@types/decompress": "^4.2.7", "@types/express": "^4.17.17", "@types/jest": "^29.5.2", "@types/js-yaml": "^4.0.9", "@types/node": "^20.12.9", + "@types/sequelize": "^4.28.20", "@types/supertest": "^6.0.2", "@types/update-notifier": "^6.0.8", "@types/uuid": "^9.0.8", From 81baf8889147ace116cc17cacd093ed1f2de7a59 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Thu, 4 Jul 2024 01:49:26 +0700 Subject: [PATCH 57/64] add traces --- cortex-js/src/command.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index f1080476b..592ca786b 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -3,6 +3,18 @@ console.log('1'); console.time('import'); console.time('imporCommandFactory'); require("time-require"); +const { TraceEvents, trackRequires } = require('perftrace') +const { writeFileSync } = require('fs'); + +const traceEvents = new TraceEvents(); + +process.on('beforeExit', () => { + const events = traceEvents.getEvents(); + traceEvents.destroy(); + writeFileSync('events.json', JSON.stringify(events)); +}); + +trackRequires(true); import { CommandFactory } from 'nest-commander'; console.timeEnd('imporCommandFactory'); console.time('importCommandModule'); From 2bf81c5d2aa155e72d49738b5d57dde5d45988a4 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 8 Jul 2024 10:25:41 +0700 Subject: [PATCH 58/64] replace typeorm to sequelize --- .../database/sqlite-database.providers.ts | 1 - .../assistants/assistants.usecases.ts | 38 +++---- .../usecases/messages/messages.usecases.ts | 46 ++++----- .../src/usecases/threads/threads.usecases.ts | 99 +++++++------------ 4 files changed, 82 insertions(+), 102 deletions(-) diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index 1ff7fa3e0..f079a0b36 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -21,7 +21,6 @@ export const sqliteDatabaseProviders = [ provide: 'DATA_SOURCE', inject: [FileManagerService], useFactory: async (fileManagerService: FileManagerService) => { - console.time('sqliteDatabaseProviders'); const dataFolderPath = await fileManagerService.getDataFolderPath(); const sqlitePath = join(dataFolderPath, databaseFile); diff --git a/cortex-js/src/usecases/assistants/assistants.usecases.ts b/cortex-js/src/usecases/assistants/assistants.usecases.ts index af09a0454..c44792b4a 100644 --- a/cortex-js/src/usecases/assistants/assistants.usecases.ts +++ b/cortex-js/src/usecases/assistants/assistants.usecases.ts @@ -5,13 +5,15 @@ import { PageDto } from '@/infrastructure/dtos/page.dto'; import { ModelRepository } from '@/domain/repositories/model.interface'; import { ModelNotFoundException } from '@/infrastructure/exception/model-not-found.exception'; import { DuplicateAssistantException } from '@/infrastructure/exception/duplicate-assistant.exception'; -import { Repository } from 'sequelize-typescript'; +import { InjectModel } from '@nestjs/sequelize'; +import { Op } from 'sequelize'; +import { AssistantEntity } from '@/infrastructure/entities/assistant.entity'; @Injectable() export class AssistantsUsecases { constructor( - @Inject('ASSISTANT_REPOSITORY') - private readonly assistantRepository: any, + @InjectModel(AssistantEntity) + private readonly assistantModel: typeof AssistantEntity, private readonly modelRepository: ModelRepository, ) {} @@ -24,7 +26,7 @@ export class AssistantsUsecases { } } - const assistant: Assistant = { + const assistant: Partial = { ...createAssistantDto, object: 'assistant', created_at: Date.now(), @@ -35,13 +37,12 @@ export class AssistantsUsecases { }; try { - await this.assistantRepository.insert(assistant); + await this.assistantModel.create(assistant); } catch (err) { - throw err; } - return this.findOne(assistant.id); + return this.findOne(id); } async listAssistants( @@ -50,20 +51,21 @@ export class AssistantsUsecases { after?: string, before?: string, ) { - const queryBuilder = this.assistantRepository.createQueryBuilder(); const normalizedOrder = order === 'asc' ? 'ASC' : 'DESC'; - queryBuilder.orderBy('created_at', normalizedOrder).take(limit + 1); - + const where: any = {}; if (after) { - queryBuilder.andWhere('id > :after', { after }); + where.id = { [Op.gt]: after }; } - if (before) { - queryBuilder.andWhere('id < :before', { before }); + where.id = { [Op.lt]: before }; } - const { entities: assistants } = await queryBuilder.getRawAndEntities(); + const assistants = await this.assistantModel.findAll({ + where, + order: [['created_at', normalizedOrder]], + limit: limit + 1, + }); let hasMore = false; if (assistants.length > limit) { @@ -78,16 +80,18 @@ export class AssistantsUsecases { } async findAll(): Promise { - return this.assistantRepository.find(); + return this.assistantModel.findAll(); } async findOne(id: string) { - return this.assistantRepository.findOne({ + return this.assistantModel.findOne({ where: { id }, }); } async remove(id: string) { - return this.assistantRepository.delete(id); + return this.assistantModel.destroy({ + where: { id }, + }); } } diff --git a/cortex-js/src/usecases/messages/messages.usecases.ts b/cortex-js/src/usecases/messages/messages.usecases.ts index 9009251c5..ee5a81f22 100644 --- a/cortex-js/src/usecases/messages/messages.usecases.ts +++ b/cortex-js/src/usecases/messages/messages.usecases.ts @@ -1,21 +1,22 @@ import { Inject, Injectable } from '@nestjs/common'; import { CreateMessageDto } from '@/infrastructure/dtos/messages/create-message.dto'; import { UpdateMessageDto } from '@/infrastructure/dtos/messages/update-message.dto'; -import { MessageEntity } from '@/infrastructure/entities/message.entity'; import { ulid } from 'ulid'; -import { Repository } from 'sequelize-typescript'; +import { MessageEntity } from '@/infrastructure/entities/message.entity'; import { Message } from '@/domain/models/message.interface'; +import { InjectModel } from '@nestjs/sequelize'; +import { Op } from 'sequelize'; @Injectable() export class MessagesUsecases { constructor( - @Inject('MESSAGE_REPOSITORY') - private messageRepository: any, + @InjectModel(MessageEntity) + private readonly messageModel: typeof MessageEntity, ) {} async create(createMessageDto: CreateMessageDto) { const { assistant_id } = createMessageDto; - const message: Message = { + const message: Partial = { ...createMessageDto, id: ulid(), created_at: Date.now(), @@ -28,41 +29,42 @@ export class MessagesUsecases { metadata: undefined, assistant_id: assistant_id ?? null, }; - this.messageRepository.insert(message); + return this.messageModel.create(message); } - findAll() { - return this.messageRepository.find(); + async findAll() { + return this.messageModel.findAll(); } - findOne(id: string) { - return this.messageRepository.findOne({ + async findOne(id: string) { + return this.messageModel.findOne({ where: { id, }, }); } - update(id: string, updateMessageDto: UpdateMessageDto) { - const updateEntity: Partial = { - ...updateMessageDto, - }; - return this.messageRepository.update(id, updateEntity); + async update(id: string, updateMessageDto: UpdateMessageDto) { + const [numberOfAffectedRows, [updatedMessage]] = await this.messageModel.update(updateMessageDto, { + where: { id }, + returning: true, + }); + return { numberOfAffectedRows, updatedMessage }; } - remove(id: string) { - return this.messageRepository.delete(id); + async remove(id: string) { + return this.messageModel.destroy({ + where: { id }, + }); } async getLastMessagesByThread(threadId: string, limit: number) { - return this.messageRepository.find({ + return this.messageModel.findAll({ where: { thread_id: threadId, }, - order: { - created_at: 'DESC', - }, - take: limit, + order: [['created_at', 'DESC']], + limit: limit, }); } } diff --git a/cortex-js/src/usecases/threads/threads.usecases.ts b/cortex-js/src/usecases/threads/threads.usecases.ts index bd59d449c..52296b972 100644 --- a/cortex-js/src/usecases/threads/threads.usecases.ts +++ b/cortex-js/src/usecases/threads/threads.usecases.ts @@ -1,9 +1,7 @@ -import { Inject, Injectable, NotFoundException } from '@nestjs/common'; +import { Injectable, NotFoundException } from '@nestjs/common'; import { CreateThreadDto } from '@/infrastructure/dtos/threads/create-thread.dto'; import { UpdateThreadDto } from '@/infrastructure/dtos/threads/update-thread.dto'; -import { ThreadEntity } from '@/infrastructure/entities/thread.entity'; import { v4 as uuidv4 } from 'uuid'; -import { MessageEntity } from '@/infrastructure/entities/message.entity'; import { PageDto } from '@/infrastructure/dtos/page.dto'; import { CreateMessageDto } from '@/infrastructure/dtos/threads/create-message.dto'; import { ulid } from 'ulid'; @@ -11,20 +9,23 @@ import { Message, MessageContent } from '@/domain/models/message.interface'; import { UpdateMessageDto } from '@/infrastructure/dtos/threads/update-message.dto'; import { Thread } from '@/domain/models/thread.interface'; import DeleteMessageDto from '@/infrastructure/dtos/threads/delete-message.dto'; -import { AssistantEntity } from '@/infrastructure/entities/assistant.entity'; -import { Repository } from 'sequelize-typescript'; import { Assistant } from '@/domain/models/assistant.interface'; +import { Repository } from 'sequelize-typescript'; +import { ThreadEntity } from '@/infrastructure/entities/thread.entity'; +import { InjectModel } from '@nestjs/sequelize'; +import { MessageEntity } from '@/infrastructure/entities/message.entity'; +import { Op } from 'sequelize'; @Injectable() export class ThreadsUsecases { constructor( - @Inject('THREAD_REPOSITORY') - private threadRepository: any, - @Inject('MESSAGE_REPOSITORY') - private messageRepository: any, + @InjectModel(ThreadEntity) + private threadRepository: typeof ThreadEntity, + @InjectModel(MessageEntity) + private messageRepository: typeof MessageEntity, ) {} - async create(createThreadDto: CreateThreadDto): Promise { + async create(createThreadDto: CreateThreadDto): Promise { const id = uuidv4(); const { assistants } = createThreadDto; const assistantEntity: Assistant[] = assistants.map((assistant) => { @@ -38,7 +39,7 @@ export class ThreadsUsecases { return entity; }); - const thread: Thread = { + const thread: Partial = { id, assistants: assistantEntity, object: 'thread', @@ -47,21 +48,13 @@ export class ThreadsUsecases { tool_resources: null, metadata: null, }; - await this.threadRepository.create({ - id, - assistants: assistantEntity, - object: 'thread', - created_at: Date.now(), - title: 'New Thread', - tool_resources: null, - metadata: null, - }); - return thread as ThreadEntity; + + return this.threadRepository.create(thread); } - async findAll(): Promise { + async findAll(): Promise { return this.threadRepository.findAll({ - include: [AssistantEntity], + include: [{ all: true }], order: [['created_at', 'DESC']], }); } @@ -72,32 +65,23 @@ export class ThreadsUsecases { order: 'asc' | 'desc', after?: string, before?: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars runId?: string, ) { await this.getThreadOrThrow(threadId); - const queryBuilder = this.messageRepository.createQueryBuilder(); const normalizedOrder = order === 'asc' ? 'ASC' : 'DESC'; - queryBuilder - .where('thread_id = :id', { id: threadId }) - .orderBy('created_at', normalizedOrder) - .take(limit + 1); // Fetch one more record than the limit - - if (after) { - queryBuilder.andWhere('id > :after', { after }); - } - - if (before) { - queryBuilder.andWhere('id < :before', { before }); - } - - const { entities: messages } = await queryBuilder.getRawAndEntities(); + const messages = await this.messageRepository.findAll({ + where: { thread_id: threadId }, + order: [['created_at', normalizedOrder]], + limit: limit + 1, + ...(after && { where: { id: { [Op.gt]: after } } }), + ...(before && { where: { id: { [Op.lt]: before } } }), + }); let hasMore = false; if (messages.length > limit) { hasMore = true; - messages.pop(); // Remove the extra record + messages.pop(); } const firstId = messages[0]?.id ?? undefined; @@ -121,7 +105,7 @@ export class ThreadsUsecases { }, }; - const message: Message = { + const message: Partial = { id: ulid(), object: 'thread.message', thread_id: threadId, @@ -137,7 +121,8 @@ export class ThreadsUsecases { attachments: [], incomplete_at: null, }; - await this.messageRepository.insert(message); + + await this.messageRepository.create(message); return message; } @@ -147,12 +132,8 @@ export class ThreadsUsecases { updateMessageDto: UpdateMessageDto, ) { await this.getThreadOrThrow(threadId); - await this.messageRepository.update(messageId, updateMessageDto); - return this.messageRepository.findOne({ - where: { - id: messageId, - }, - }); + await this.messageRepository.update(updateMessageDto, { where: { id: messageId } }); + return this.messageRepository.findOne({ where: { id: messageId } }); } private async getThreadOrThrow(threadId: string): Promise { @@ -165,9 +146,7 @@ export class ThreadsUsecases { private async getMessageOrThrow(messageId: string): Promise { const message = await this.messageRepository.findOne({ - where: { - id: messageId, - }, + where: { id: messageId }, }); if (!message) { throw new NotFoundException(`Message with id ${messageId} not found`); @@ -197,20 +176,17 @@ export class ThreadsUsecases { ...updateThreadDto, assistants: assistantEntities, }; - return this.threadRepository.update(id, entity); + + return this.threadRepository.update(entity, { where: { id } }); } - remove(id: string) { - this.threadRepository.delete(id); + async remove(id: string) { + await this.threadRepository.destroy({ where: { id } }); } - async deleteMessage( - _threadId: string, - messageId: string, - ): Promise { - // we still allow user to delete message even if the thread is not there + async deleteMessage(_threadId: string, messageId: string): Promise { await this.getMessageOrThrow(messageId); - await this.messageRepository.delete(messageId); + await this.messageRepository.destroy({ where: { id: messageId } }); return { id: messageId, @@ -220,12 +196,11 @@ export class ThreadsUsecases { } async retrieveMessage(_threadId: string, messageId: string) { - // we still allow user to delete message even if the thread is not there return this.getMessageOrThrow(messageId); } async clean(threadId: string) { await this.getThreadOrThrow(threadId); - await this.messageRepository.delete({ thread_id: threadId }); + await this.messageRepository.destroy({ where: { thread_id: threadId } }); } } From 19df8fe351bd2cc3b4942aaf76f87ce7d03c9e63 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 8 Jul 2024 22:34:57 +0700 Subject: [PATCH 59/64] clean up --- cortex-js/src/command.module.ts | 95 ------------------- cortex-js/src/command.ts | 30 ------ .../infrastructure/commanders/chat.command.ts | 14 --- .../commanders/cortex-command.commander.ts | 42 -------- .../commanders/decorators/CommandContext.ts | 3 - .../database/database.module.ts | 16 ---- .../database/providers/thread.providers.ts | 4 - .../database/sqlite-database.providers.ts | 10 -- .../extensions/extension.repository.ts | 2 - .../file-manager/file-manager.service.ts | 14 --- .../assistants/assistants.usecases.ts | 7 +- .../usecases/messages/messages.usecases.ts | 19 ++-- .../src/usecases/models/models.module.ts | 22 ----- .../src/usecases/threads/threads.usecases.ts | 11 +-- 14 files changed, 17 insertions(+), 272 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index d9e8de607..fb92186d0 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -1,145 +1,50 @@ -console.time('import-command'); -console.time('import-command-module'); import { Module } from '@nestjs/common'; -console.timeEnd('import-command-module'); -console.time('import-command-model-module'); import { ModelsModule } from './usecases/models/models.module'; -console.timeEnd('import-command-model-module'); -console.time('import-command-database-module'); import { DatabaseModule } from './infrastructure/database/database.module'; -console.timeEnd('import-command-database-module'); -console.time('import-command-config-module'); import { ConfigModule } from '@nestjs/config'; -console.timeEnd('import-command-config-module'); -console.time('import-command-cortex-module'); import { CortexModule } from './usecases/cortex/cortex.module'; -console.timeEnd('import-command-cortex-module'); -console.time('import-command-server-command'); import { ServeCommand } from './infrastructure/commanders/serve.command'; -console.timeEnd('import-command-server-command'); -console.time('import-command-models-command'); import { ModelsCommand } from './infrastructure/commanders/models.command'; -console.timeEnd('import-command-models-command'); -console.time('import-command-extension-module'); import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module'; -console.timeEnd('import-command-extension-module'); -console.time('import-command-init-command'); import { InitCommand } from './infrastructure/commanders/init.command'; -console.timeEnd('import-command-init-command'); -console.time('import-command-http-module'); import { HttpModule } from '@nestjs/axios'; -console.timeEnd('import-command-http-module'); -console.time('import-command-questions'); import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions'; -console.timeEnd('import-command-questions'); -console.time('import-command-model-list-command'); import { ModelListCommand } from './infrastructure/commanders/models/model-list.command'; -console.timeEnd('import-command-model-list-command'); -console.time('import-command-model-pull-command'); import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command'; -console.timeEnd('import-command-model-pull-command'); -console.time('import-command-cortex-command'); import { CortexCommand } from './infrastructure/commanders/cortex-command.commander'; -console.timeEnd('import-command-cortex-command'); -console.time('import-command-chat-command'); import { ChatCommand } from './infrastructure/commanders/chat.command'; -console.timeEnd('import-command-chat-command'); -console.time('import-command-model-start-command'); import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command'; -console.timeEnd('import-command-model-start-command'); -console.time('import-command-model-stop-command'); import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command'; -console.timeEnd('import-command-model-stop-command'); -console.time('import-command-model-get-command'); import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command'; -console.timeEnd('import-command-model-get-command'); -console.time('import-command-model-remove-command'); import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command'; -console.timeEnd('import-command-model-remove-command'); -console.time('import-command-model-update-command'); import { RunCommand } from './infrastructure/commanders/shortcuts/run.command'; -console.timeEnd('import-command-model-update-command'); -console.time('import-command-model-update-command'); import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command'; -console.timeEnd('import-command-model-update-command'); -console.time('import-command-assistants-module'); import { AssistantsModule } from './usecases/assistants/assistants.module'; -console.timeEnd('import-command-assistants-module'); -console.time('import-command-messages-module'); import { MessagesModule } from './usecases/messages/messages.module'; -console.timeEnd('import-command-messages-module'); -console.time('import-command-file-manager-module'); import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module'; -console.timeEnd('import-command-file-manager-module'); -console.time('import-command-ps-command'); import { PSCommand } from './infrastructure/commanders/ps.command'; -console.timeEnd('import-command-ps-command'); -console.time('import-command-kill-command'); import { KillCommand } from './infrastructure/commanders/kill.command'; -console.timeEnd('import-command-kill-command'); -console.time('import-command-preset-command'); import { PresetCommand } from './infrastructure/commanders/presets.command'; -console.timeEnd('import-command-preset-command'); -console.time('import-command-telemetry-module'); import { TelemetryModule } from './usecases/telemetry/telemetry.module'; -console.timeEnd('import-command-telemetry-module'); -console.time('import-command-telemetry-command'); import { TelemetryCommand } from './infrastructure/commanders/telemetry.command'; -console.timeEnd('import-command-telemetry-command'); -console.time('import-command-embedding-command'); import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command'; -console.timeEnd('import-command-embedding-command'); -console.time('import-command-benchmark-command'); import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command'; -console.timeEnd('import-command-benchmark-command'); -console.time('import-command-event-emitter'); import { EventEmitterModule } from '@nestjs/event-emitter'; -console.timeEnd('import-command-event-emitter'); -console.time('import-command-download-manager'); import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module'; -console.timeEnd('import-command-download-manager'); -console.time('import-command-servestop-command'); import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command'; -console.timeEnd('import-command-servestop-command'); -console.time('import-command-context-module'); import { ContextModule } from './infrastructure/services/context/context.module'; -console.timeEnd('import-command-context-module'); -console.time('import-command-cli-usecases-module'); import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module'; -console.timeEnd('import-command-cli-usecases-module'); -console.time('import-command-extensions-module'); import { ExtensionsModule } from './extensions/extensions.module'; -console.timeEnd('import-command-extensions-module'); -console.time('import-command-configs-command'); import { ConfigsCommand } from './infrastructure/commanders/configs.command'; -console.timeEnd('import-command-configs-command'); -console.time('import-command-engines-command'); import { EnginesCommand } from './infrastructure/commanders/engines.command'; -console.timeEnd('import-command-engines-command'); -console.time('import-command-configs-module'); import { ConfigsModule } from './usecases/configs/configs.module'; -console.timeEnd('import-command-configs-module'); -console.time('import-command-engines-module'); import { EnginesModule } from './usecases/engines/engines.module'; -console.timeEnd('import-command-engines-module'); -console.time('import-command-configs-get-command'); import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command'; -console.timeEnd('import-command-configs-get-command'); -console.time('import-command-configs-list-command'); import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command'; -console.timeEnd('import-command-configs-list-command'); -console.time('import-command-configs-set-command'); import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command'; -console.timeEnd('import-command-configs-set-command'); -console.time('import-command-engines-list-command'); import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command'; -console.timeEnd('import-command-engines-list-command'); -console.time('import-command-engines-get-command'); import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command'; -console.timeEnd('import-command-engines-get-command'); -console.timeEnd('import-command'); -console.time('import-command'); @Module({ imports: [ diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index 592ca786b..d1a287cfc 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -1,39 +1,12 @@ #!/usr/bin/env node --no-warnings -console.log('1'); -console.time('import'); -console.time('imporCommandFactory'); -require("time-require"); -const { TraceEvents, trackRequires } = require('perftrace') -const { writeFileSync } = require('fs'); - -const traceEvents = new TraceEvents(); - -process.on('beforeExit', () => { - const events = traceEvents.getEvents(); - traceEvents.destroy(); - writeFileSync('events.json', JSON.stringify(events)); -}); - -trackRequires(true); import { CommandFactory } from 'nest-commander'; -console.timeEnd('imporCommandFactory'); -console.time('importCommandModule'); import { CommandModule } from './command.module'; -console.timeEnd('importCommandModule'); -console.time('importTelemetryUsecases'); import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases'; -console.timeEnd('importTelemetryUsecases'); -console.time('importContextService'); import { TelemetrySource } from './domain/telemetry/telemetry.interface'; import { ContextService } from '@/infrastructure/services/context/context.service'; -console.timeEnd('importContextService'); -console.timeEnd('import'); -console.time('test'); -console.log('Running CLI'); async function bootstrap() { let telemetryUseCase: TelemetryUsecases | null = null; let contextService: ContextService | null = null; - console.time('CLI'); const app = await CommandFactory.createWithoutRunning(CommandModule, { logger: ['warn', 'error'], errorHandler: async (error) => { @@ -54,9 +27,6 @@ async function bootstrap() { await contextService!.init(async () => { contextService!.set('source', TelemetrySource.CLI); await CommandFactory.runApplication(app); - // await CommandFactory.run(CommandModule, ['warn', 'error']); - console.timeEnd('CLI'); - console.timeEnd('test'); }); } diff --git a/cortex-js/src/infrastructure/commanders/chat.command.ts b/cortex-js/src/infrastructure/commanders/chat.command.ts index 89e6777fe..0124ab54c 100644 --- a/cortex-js/src/infrastructure/commanders/chat.command.ts +++ b/cortex-js/src/infrastructure/commanders/chat.command.ts @@ -4,27 +4,13 @@ import { Option, InquirerService, } from 'nest-commander'; -console.time('import-command-chat-cli-usecases'); import { ChatCliUsecases } from './usecases/chat.cli.usecases'; -console.timeEnd('import-command-chat-cli-usecases'); -console.time('import-command-chat-exit'); import { exit } from 'node:process'; -console.timeEnd('import-command-chat-exit'); -console.time('import-command-chat-ps-cli-usecases'); import { PSCliUsecases } from './usecases/ps.cli.usecases'; -console.timeEnd('import-command-chat-ps-cli-usecases'); -console.time('import-command-chat-models-usecases'); import { ModelsUsecases } from '@/usecases/models/models.usecases'; -console.timeEnd('import-command-chat-models-usecases'); -console.time('import-command-chat-types'); import { SetCommandContext } from './decorators/CommandContext'; -console.timeEnd('import-command-chat-types'); -console.time('import-command-chat-types'); import { ModelStat } from './types/model-stat.interface'; -console.timeEnd('import-command-chat-types'); -console.time('import-command-chat-types'); import { ContextService } from '../services/context/context.service'; -console.timeEnd('import-command-chat-types'); type ChatOptions = { threadId?: string; diff --git a/cortex-js/src/infrastructure/commanders/cortex-command.commander.ts b/cortex-js/src/infrastructure/commanders/cortex-command.commander.ts index d2fcd9889..9ba0d23ed 100644 --- a/cortex-js/src/infrastructure/commanders/cortex-command.commander.ts +++ b/cortex-js/src/infrastructure/commanders/cortex-command.commander.ts @@ -1,65 +1,23 @@ -console.time('import-cortex-command-time'); -console.time('import-cortex-command-commander'); import { RootCommand, CommandRunner } from 'nest-commander'; -console.timeEnd('import-cortex-command-commander'); -console.time('import-cortex-command-serve-command'); import { ServeCommand } from './serve.command'; -console.timeEnd('import-cortex-command-serve-command'); -console.time('import-cortex-command-chat-command'); import { ChatCommand } from './chat.command'; -console.timeEnd('import-cortex-command-chat-command'); -console.time('import-cortex-command-models-command'); import { ModelsCommand } from './models.command'; -console.timeEnd('import-cortex-command-models-command'); -console.time('import-cortex-command-init-command'); import { InitCommand } from './init.command'; -console.timeEnd('import-cortex-command-init-command'); -console.time('import-cortex-command-run-command'); import { RunCommand } from './shortcuts/run.command'; -console.timeEnd('import-cortex-command-run-command'); -console.time('import-cortex-command-model-pull-command'); import { ModelPullCommand } from './models/model-pull.command'; -console.timeEnd('import-cortex-command-model-pull-command'); -console.time('import-cortex-command-ps-command'); import { PSCommand } from './ps.command'; -console.timeEnd('import-cortex-command-ps-command'); -console.time('import-cortex-command-kill-command'); import { KillCommand } from './kill.command'; -console.timeEnd('import-cortex-command-kill-command'); -console.time('import-cortex-command-preset-command'); import pkg from '@/../package.json'; -console.timeEnd('import-cortex-command-preset-command'); -console.time('import-cortex-command-telemetry-command'); import { PresetCommand } from './presets.command'; -console.timeEnd('import-cortex-command-telemetry-command'); -console.time('import-cortex-command-telemetry-command'); import { TelemetryCommand } from './telemetry.command'; -console.timeEnd('import-cortex-command-telemetry-command'); -console.time('import-cortex-command-embedding-command'); import { SetCommandContext } from './decorators/CommandContext'; -console.timeEnd('import-cortex-command-embedding-command'); -console.time('import-cortex-command-benchmark-command'); import { EmbeddingCommand } from './embeddings.command'; -console.timeEnd('import-cortex-command-benchmark-command'); -console.time('import-cortex-command-engines-command'); import { BenchmarkCommand } from './benchmark.command'; -console.timeEnd('import-cortex-command-engines-command'); -console.time('import-cortex-command-configs-command'); import chalk from 'chalk'; -console.timeEnd('import-cortex-command-configs-command'); -console.time('import-cortex-command-configs-command'); import { printSlogan } from '@/utils/logo'; -console.timeEnd('import-cortex-command-configs-command'); -console.time('import-cortex-command-configs-command'); import { ContextService } from '../services/context/context.service'; -console.timeEnd('import-cortex-command-configs-command'); -console.time('import-cortex-command-configs-command'); import { EnginesCommand } from './engines.command'; -console.timeEnd('import-cortex-command-configs-command'); -console.time('import-cortex-command-configs-command'); import { ConfigsCommand } from './configs.command'; -console.timeEnd('import-cortex-command-configs-command'); -console.time('import-cortex-command-time'); @RootCommand({ subCommands: [ diff --git a/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts b/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts index 7b71ec924..53f7c6b47 100644 --- a/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts +++ b/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts @@ -3,8 +3,6 @@ type Constructor = new (...args: any[]) => any; export const SetCommandContext = () => { return (constructor: Constructor) => { const name = 'SetCommandContext' + constructor.name; - console.log('SetCommandContext', name); - console.time(name); const classMethods = Object.getOwnPropertyNames(constructor.prototype); classMethods.forEach((methodName) => { @@ -33,6 +31,5 @@ export const SetCommandContext = () => { }; } }); - console.timeEnd(name); }; }; diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index 9d8a7cdcb..2e7b3ae85 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -1,26 +1,10 @@ -console.time('import-command-database-module-total'); -console.time('import-command-database-module-module'); import { Module } from '@nestjs/common'; -console.timeEnd('import-command-database-module-module'); -console.time('import-command-database-module-thread-providers'); import { threadProviders } from './providers/thread.providers'; -console.timeEnd('import-command-database-module-thread-providers'); -console.time('import-command-database-module-sqlite-database-providers'); import { sqliteDatabaseProviders } from './sqlite-database.providers'; -console.timeEnd('import-command-database-module-sqlite-database-providers'); -console.time('import-command-database-module-assistant-providers'); import { assistantProviders } from './providers/assistant.providers'; -console.timeEnd('import-command-database-module-assistant-providers'); -console.time('import-command-database-module-message-providers'); import { messageProviders } from './providers/message.providers'; -console.timeEnd('import-command-database-module-message-providers'); -console.time('import-command-database-module-telemetry-providers'); import { telemetryProviders } from './providers/telemetry.providers'; -console.timeEnd('import-command-database-module-telemetry-providers'); -console.time('import-command-database-module-file-manager-module'); import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module'; -console.timeEnd('import-command-database-module-file-manager-module'); -console.timeEnd('import-command-database-module-total'); @Module({ imports: [FileManagerModule], diff --git a/cortex-js/src/infrastructure/database/providers/thread.providers.ts b/cortex-js/src/infrastructure/database/providers/thread.providers.ts index cde488847..8f91cb9a7 100644 --- a/cortex-js/src/infrastructure/database/providers/thread.providers.ts +++ b/cortex-js/src/infrastructure/database/providers/thread.providers.ts @@ -1,9 +1,5 @@ -console.time('threadProviders-import'); -console.time('threadProviders-typeorm'); import { ThreadEntity } from '@/infrastructure/entities/thread.entity'; import { Sequelize } from 'sequelize-typescript'; -console.timeEnd('threadProviders-typeorm'); -console.timeEnd('threadProviders-import'); export const threadProviders = [ { diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index f079a0b36..9ac5e7437 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -1,20 +1,10 @@ -console.time('sqliteDatabaseProviders-import'); -console.time('sqliteDatabaseProviders-file-manager-service'); import { FileManagerService } from '@/infrastructure/services/file-manager/file-manager.service'; -console.timeEnd('sqliteDatabaseProviders-file-manager-service'); -console.timeEnd('sqliteDatabaseProviders-database-file'); import { databaseFile } from '@/infrastructure/constants/cortex'; -console.timeEnd('sqliteDatabaseProviders-import'); -console.time('sqliteDatabaseProviders-import-path'); import { join } from 'path'; -console.timeEnd('sqliteDatabaseProviders-import-path'); -console.time('sqliteDatabaseProviders-import-typeorm'); import { ThreadEntity } from '../entities/thread.entity'; import { MessageEntity } from '../entities/message.entity'; import { AssistantEntity } from '../entities/assistant.entity'; import { Sequelize } from 'sequelize-typescript'; -console.timeEnd('sqliteDatabaseProviders-import-typeorm'); -console.time('sqliteDatabaseProviders-import'); export const sqliteDatabaseProviders = [ { diff --git a/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts b/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts index 2177c78af..b37ece430 100644 --- a/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts +++ b/cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts @@ -22,10 +22,8 @@ export class ExtensionRepositoryImpl implements ExtensionRepository { private readonly httpService: HttpService, private readonly fileManagerService: FileManagerService, ) { - console.time('loadExtensions'); this.loadCoreExtensions(); this.loadExternalExtensions(); - console.timeEnd('loadExtensions'); } create(object: Extension): Promise { this.extensions.set(object.name ?? '', object); diff --git a/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts b/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts index a62dee416..e1ea41e92 100644 --- a/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts +++ b/cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts @@ -39,7 +39,6 @@ export class FileManagerService { * @returns the config object */ async getConfig(): Promise { - console.log('getConfig'); const homeDir = os.homedir(); const configPath = join(homeDir, this.configFile); @@ -68,7 +67,6 @@ export class FileManagerService { } async writeConfigFile(config: Config & object): Promise { - console.log('writeConfigFile'); const homeDir = os.homedir(); const configPath = join(homeDir, this.configFile); @@ -78,7 +76,6 @@ export class FileManagerService { } private async createFolderIfNotExist(dataFolderPath: string): Promise { - console.log('createFolderIfNotExist'); if (!existsSync(dataFolderPath)) { await promises.mkdir(dataFolderPath, { recursive: true }); } @@ -101,7 +98,6 @@ export class FileManagerService { } private defaultConfig(): Config { - console.log('defaultConfig'); // default will store at home directory const homeDir = os.homedir(); const dataFolderPath = join(homeDir, this.cortexDirectoryName); @@ -128,7 +124,6 @@ export class FileManagerService { filePath: string, ): Promise<{ data: any; position: number }> { try { - console.log('getLastLine'); const fileDescriptor = await openAsync(filePath, 'a+'); const stats = await promises.stat(filePath); const bufferSize = 1024 * 5; // 5KB @@ -172,7 +167,6 @@ export class FileManagerService { } async modifyLine(filePath: string, modifiedLine: any, position: number) { try { - console.log('modifyLine'); const fd = await openAsync(filePath, 'r+'); const buffer = Buffer.from(modifiedLine, 'utf8'); await writeAsync(fd, buffer, 0, buffer.length, position); @@ -185,7 +179,6 @@ export class FileManagerService { async append(filePath: string, data: any) { try { - console.log('append'); const stats = await promises.stat(filePath); return await promises.appendFile( filePath, @@ -200,7 +193,6 @@ export class FileManagerService { } } readLines(filePath: string, callback: (line: string) => void) { - console.log('readLines'); const fileStream = createReadStream(filePath); const rl = createInterface({ input: fileStream, @@ -215,7 +207,6 @@ export class FileManagerService { * @returns the path to the models folder */ async getModelsPath(): Promise { - console.log('getModelsPath'); const dataFolderPath = await this.getDataFolderPath(); return join(dataFolderPath, this.modelFolderName); } @@ -226,7 +217,6 @@ export class FileManagerService { * @returns the path to the presets folder */ async getPresetsPath(): Promise { - console.log('getPresetsPath'); const dataFolderPath = await this.getDataFolderPath(); return join(dataFolderPath, this.presetFolderName); } @@ -237,7 +227,6 @@ export class FileManagerService { * @returns the path to the extensions folder */ async getExtensionsPath(): Promise { - console.log('getExtensionsPath'); const dataFolderPath = await this.getDataFolderPath(); return join(dataFolderPath, this.extensionFoldername); } @@ -248,7 +237,6 @@ export class FileManagerService { * @returns the path to the benchmark folder */ async getBenchmarkPath(): Promise { - console.log('getBenchmarkPath'); const dataFolderPath = await this.getDataFolderPath(); return join(dataFolderPath, this.benchmarkFoldername); } @@ -258,12 +246,10 @@ export class FileManagerService { * @returns the path to the cortex engines folder */ async getCortexCppEnginePath(): Promise { - console.log('getCortexCppEnginePath'); return join(await this.getDataFolderPath(), 'cortex-cpp', 'engines'); } async createFolderIfNotExistInDataFolder(folderName: string): Promise { - console.log('createFolderIfNotExistInDataFolder'); const dataFolderPath = await this.getDataFolderPath(); const folderPath = join(dataFolderPath, folderName); if (!existsSync(folderPath)) { diff --git a/cortex-js/src/usecases/assistants/assistants.usecases.ts b/cortex-js/src/usecases/assistants/assistants.usecases.ts index c44792b4a..00cf850fa 100644 --- a/cortex-js/src/usecases/assistants/assistants.usecases.ts +++ b/cortex-js/src/usecases/assistants/assistants.usecases.ts @@ -4,16 +4,15 @@ import { Assistant } from '@/domain/models/assistant.interface'; import { PageDto } from '@/infrastructure/dtos/page.dto'; import { ModelRepository } from '@/domain/repositories/model.interface'; import { ModelNotFoundException } from '@/infrastructure/exception/model-not-found.exception'; -import { DuplicateAssistantException } from '@/infrastructure/exception/duplicate-assistant.exception'; -import { InjectModel } from '@nestjs/sequelize'; import { Op } from 'sequelize'; import { AssistantEntity } from '@/infrastructure/entities/assistant.entity'; +import { Repository } from 'sequelize-typescript'; @Injectable() export class AssistantsUsecases { constructor( - @InjectModel(AssistantEntity) - private readonly assistantModel: typeof AssistantEntity, + @Inject('ASSISTANT_REPOSITORY') + private readonly assistantModel: Repository, private readonly modelRepository: ModelRepository, ) {} diff --git a/cortex-js/src/usecases/messages/messages.usecases.ts b/cortex-js/src/usecases/messages/messages.usecases.ts index ee5a81f22..13eaac7c4 100644 --- a/cortex-js/src/usecases/messages/messages.usecases.ts +++ b/cortex-js/src/usecases/messages/messages.usecases.ts @@ -4,14 +4,13 @@ import { UpdateMessageDto } from '@/infrastructure/dtos/messages/update-message. import { ulid } from 'ulid'; import { MessageEntity } from '@/infrastructure/entities/message.entity'; import { Message } from '@/domain/models/message.interface'; -import { InjectModel } from '@nestjs/sequelize'; -import { Op } from 'sequelize'; +import { Repository } from 'sequelize-typescript'; @Injectable() export class MessagesUsecases { constructor( - @InjectModel(MessageEntity) - private readonly messageModel: typeof MessageEntity, + @Inject('MESSAGE_REPOSITORY') + private messageRepository: Repository, ) {} async create(createMessageDto: CreateMessageDto) { @@ -29,15 +28,15 @@ export class MessagesUsecases { metadata: undefined, assistant_id: assistant_id ?? null, }; - return this.messageModel.create(message); + return this.messageRepository.create(message); } async findAll() { - return this.messageModel.findAll(); + return this.messageRepository.findAll(); } async findOne(id: string) { - return this.messageModel.findOne({ + return this.messageRepository.findOne({ where: { id, }, @@ -45,7 +44,7 @@ export class MessagesUsecases { } async update(id: string, updateMessageDto: UpdateMessageDto) { - const [numberOfAffectedRows, [updatedMessage]] = await this.messageModel.update(updateMessageDto, { + const [numberOfAffectedRows, [updatedMessage]] = await this.messageRepository.update(updateMessageDto, { where: { id }, returning: true, }); @@ -53,13 +52,13 @@ export class MessagesUsecases { } async remove(id: string) { - return this.messageModel.destroy({ + return this.messageRepository.destroy({ where: { id }, }); } async getLastMessagesByThread(threadId: string, limit: number) { - return this.messageModel.findAll({ + return this.messageRepository.findAll({ where: { thread_id: threadId, }, diff --git a/cortex-js/src/usecases/models/models.module.ts b/cortex-js/src/usecases/models/models.module.ts index beb68c4b3..e5972941b 100644 --- a/cortex-js/src/usecases/models/models.module.ts +++ b/cortex-js/src/usecases/models/models.module.ts @@ -1,36 +1,14 @@ -console.time('import-command-models-module'); import { Module } from '@nestjs/common'; -console.timeEnd('import-command-models-module'); -console.time('import-command-models-model'); import { ModelsUsecases } from './models.usecases'; -console.timeEnd('import-command-models-model'); -console.time('import-command-models-database'); import { DatabaseModule } from '@/infrastructure/database/database.module'; -console.timeEnd('import-command-models-database'); -console.time('import-command-models-cortex'); import { CortexModule } from '@/usecases/cortex/cortex.module'; -console.timeEnd('import-command-models-cortex'); -console.time('import-command-models-extension'); import { ExtensionModule } from '@/infrastructure/repositories/extensions/extension.module'; -console.timeEnd('import-command-models-extension'); -console.time('import-command-models-http'); import { HttpModule } from '@nestjs/axios'; -console.timeEnd('import-command-models-http'); -console.time('import-command-models-telemetry'); import { TelemetryModule } from '../telemetry/telemetry.module'; -console.timeEnd('import-command-models-telemetry'); -console.time('import-command-models-file-manager'); import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module'; -console.timeEnd('import-command-models-file-manager'); -console.time('import-command-models-model-repository'); import { ModelRepositoryModule } from '@/infrastructure/repositories/models/model.module'; -console.timeEnd('import-command-models-model-repository'); -console.time('import-command-models-download-manager'); import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module'; -console.timeEnd('import-command-models-download-manager'); -console.time('import-command-models-context'); import { ContextModule } from '@/infrastructure/services/context/context.module'; -console.timeEnd('import-command-models-context'); @Module({ imports: [ diff --git a/cortex-js/src/usecases/threads/threads.usecases.ts b/cortex-js/src/usecases/threads/threads.usecases.ts index 52296b972..ac1fd2666 100644 --- a/cortex-js/src/usecases/threads/threads.usecases.ts +++ b/cortex-js/src/usecases/threads/threads.usecases.ts @@ -1,4 +1,4 @@ -import { Injectable, NotFoundException } from '@nestjs/common'; +import { Inject, Injectable, NotFoundException } from '@nestjs/common'; import { CreateThreadDto } from '@/infrastructure/dtos/threads/create-thread.dto'; import { UpdateThreadDto } from '@/infrastructure/dtos/threads/update-thread.dto'; import { v4 as uuidv4 } from 'uuid'; @@ -12,17 +12,16 @@ import DeleteMessageDto from '@/infrastructure/dtos/threads/delete-message.dto'; import { Assistant } from '@/domain/models/assistant.interface'; import { Repository } from 'sequelize-typescript'; import { ThreadEntity } from '@/infrastructure/entities/thread.entity'; -import { InjectModel } from '@nestjs/sequelize'; import { MessageEntity } from '@/infrastructure/entities/message.entity'; import { Op } from 'sequelize'; @Injectable() export class ThreadsUsecases { constructor( - @InjectModel(ThreadEntity) - private threadRepository: typeof ThreadEntity, - @InjectModel(MessageEntity) - private messageRepository: typeof MessageEntity, + @Inject('THREAD_REPOSITORY') + private threadRepository: Repository, + @Inject('MESSAGE_REPOSITORY') + private messageRepository: Repository, ) {} async create(createThreadDto: CreateThreadDto): Promise { From 858c019ffe6796bb98ac05c675ea3709347a0ffa Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 8 Jul 2024 22:37:30 +0700 Subject: [PATCH 60/64] remove debug packages --- cortex-js/package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/cortex-js/package.json b/cortex-js/package.json index 9fad1c91c..32e503b7a 100644 --- a/cortex-js/package.json +++ b/cortex-js/package.json @@ -55,7 +55,6 @@ "decompress": "^4.2.1", "js-yaml": "^4.1.0", "nest-commander": "^3.13.0", - "perftrace": "^1.2.1", "readline": "^1.3.0", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", @@ -63,7 +62,6 @@ "sequelize-typescript": "^2.1.6", "sqlite3": "^5.1.7", "systeminformation": "^5.22.11", - "time-require": "^0.1.2", "ulid": "^2.3.0", "uuid": "^9.0.1", "yaml": "^2.4.2" From 4b87d7f3a07502b0949be458f7489d6a463960c5 Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 8 Jul 2024 22:50:05 +0700 Subject: [PATCH 61/64] fix error --- .../src/infrastructure/database/sqlite-database.providers.ts | 2 +- cortex-js/src/infrastructure/entities/assistant.entity.ts | 2 +- cortex-js/src/infrastructure/entities/message.entity.ts | 2 +- cortex-js/src/infrastructure/entities/thread.entity.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index 9ac5e7437..db33dc333 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -13,10 +13,10 @@ export const sqliteDatabaseProviders = [ useFactory: async (fileManagerService: FileManagerService) => { const dataFolderPath = await fileManagerService.getDataFolderPath(); const sqlitePath = join(dataFolderPath, databaseFile); - const sequelize = new Sequelize({ dialect: 'sqlite', storage: sqlitePath, + logging: false, }); sequelize.addModels([ThreadEntity, MessageEntity, AssistantEntity]); return sequelize; diff --git a/cortex-js/src/infrastructure/entities/assistant.entity.ts b/cortex-js/src/infrastructure/entities/assistant.entity.ts index cea9f89e2..f9ef78435 100644 --- a/cortex-js/src/infrastructure/entities/assistant.entity.ts +++ b/cortex-js/src/infrastructure/entities/assistant.entity.ts @@ -5,7 +5,7 @@ import type { AssistantResponseFormatOption, } from '@/domain/models/assistant.interface'; -@Table({ tableName: 'assistants' }) +@Table({ tableName: 'assistants', timestamps: false}) export class AssistantEntity extends Model implements Assistant { @PrimaryKey @Column({ diff --git a/cortex-js/src/infrastructure/entities/message.entity.ts b/cortex-js/src/infrastructure/entities/message.entity.ts index 06975dd51..1fe6192a5 100644 --- a/cortex-js/src/infrastructure/entities/message.entity.ts +++ b/cortex-js/src/infrastructure/entities/message.entity.ts @@ -6,7 +6,7 @@ import type { MessageAttachment, } from '@/domain/models/message.interface'; -@Table({ tableName: 'messages' }) +@Table({ tableName: 'messages', timestamps: false}) export class MessageEntity extends Model implements Message { @PrimaryKey @Column({ diff --git a/cortex-js/src/infrastructure/entities/thread.entity.ts b/cortex-js/src/infrastructure/entities/thread.entity.ts index 69bfb6d5b..fabd11338 100644 --- a/cortex-js/src/infrastructure/entities/thread.entity.ts +++ b/cortex-js/src/infrastructure/entities/thread.entity.ts @@ -2,7 +2,7 @@ import { Table, Column, Model, PrimaryKey, DataType } from 'sequelize-typescript import type { Thread, ThreadToolResources } from '@/domain/models/thread.interface'; import { AssistantEntity } from './assistant.entity'; -@Table({ tableName: 'threads' }) +@Table({ tableName: 'threads', timestamps: false}) export class ThreadEntity extends Model implements Thread { @PrimaryKey @Column({ From d83677d0fbd04301117b0c80bbcdadea480bea3c Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 8 Jul 2024 22:59:17 +0700 Subject: [PATCH 62/64] clean up --- cortex-js/src/command.ts | 2 ++ cortex-js/src/infrastructure/commanders/serve.command.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cortex-js/src/command.ts b/cortex-js/src/command.ts index d1a287cfc..6e2fa7ee5 100644 --- a/cortex-js/src/command.ts +++ b/cortex-js/src/command.ts @@ -11,10 +11,12 @@ async function bootstrap() { logger: ['warn', 'error'], errorHandler: async (error) => { await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + console.error(error); process.exit(1); }, serviceErrorHandler: async (error) => { await telemetryUseCase!.createCrashReport(error, TelemetrySource.CLI); + console.error(error); process.exit(1); }, }); diff --git a/cortex-js/src/infrastructure/commanders/serve.command.ts b/cortex-js/src/infrastructure/commanders/serve.command.ts index 06276b1fa..4eaa7bc45 100644 --- a/cortex-js/src/infrastructure/commanders/serve.command.ts +++ b/cortex-js/src/infrastructure/commanders/serve.command.ts @@ -6,6 +6,7 @@ import { CommandRunner, SubCommand, Option } from 'nest-commander'; import { SetCommandContext } from './decorators/CommandContext'; import { ServeStopCommand } from './sub-commands/serve-stop.command'; import { ContextService } from '../services/context/context.service'; +import { getApp } from '@/app'; import chalk from 'chalk'; type ServeOptions = { @@ -33,7 +34,6 @@ export class ServeCommand extends CommandRunner { } private async startServer(host: string, port: number) { - const { getApp } = await import('@/app'); const app = await getApp(); try { From 498d25d33a03868eadd7fe328edd36fc8483a84d Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Mon, 8 Jul 2024 23:09:24 +0700 Subject: [PATCH 63/64] revert debug change --- cortex-js/src/command.module.ts | 2 +- .../commanders/decorators/CommandContext.ts | 1 - .../commanders/usecases/chat.cli.usecases.ts | 2 +- cortex-js/src/usecases/configs/configs.usecase.ts | 14 +++++++------- cortex-js/src/usecases/threads/threads.usecases.ts | 1 + 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cortex-js/src/command.module.ts b/cortex-js/src/command.module.ts index fb92186d0..79d55b09c 100644 --- a/cortex-js/src/command.module.ts +++ b/cortex-js/src/command.module.ts @@ -104,7 +104,7 @@ import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-g // Serve ServeStopCommand, - // // Configs + // Configs ConfigsCommand, ConfigsGetCommand, ConfigsListCommand, diff --git a/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts b/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts index 53f7c6b47..04033c7cd 100644 --- a/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts +++ b/cortex-js/src/infrastructure/commanders/decorators/CommandContext.ts @@ -2,7 +2,6 @@ type Constructor = new (...args: any[]) => any; export const SetCommandContext = () => { return (constructor: Constructor) => { - const name = 'SetCommandContext' + constructor.name; const classMethods = Object.getOwnPropertyNames(constructor.prototype); classMethods.forEach((methodName) => { diff --git a/cortex-js/src/infrastructure/commanders/usecases/chat.cli.usecases.ts b/cortex-js/src/infrastructure/commanders/usecases/chat.cli.usecases.ts index 6c0ffbc8a..710a13902 100644 --- a/cortex-js/src/infrastructure/commanders/usecases/chat.cli.usecases.ts +++ b/cortex-js/src/infrastructure/commanders/usecases/chat.cli.usecases.ts @@ -41,7 +41,7 @@ export class ChatCliUsecases { const thread = await this.getOrCreateNewThread(modelId, threadId); const messages: ChatCompletionMessage[] = ( await this.messagesUsecases.getLastMessagesByThread(thread.id, 10) - ).map((message: any) => ({ + ).map((message) => ({ content: (message.content[0] as TextContentBlock).text.value, role: message.role, })); diff --git a/cortex-js/src/usecases/configs/configs.usecase.ts b/cortex-js/src/usecases/configs/configs.usecase.ts index dcfd3307e..4cff2e3f5 100644 --- a/cortex-js/src/usecases/configs/configs.usecase.ts +++ b/cortex-js/src/usecases/configs/configs.usecase.ts @@ -1,13 +1,13 @@ import { CommonResponseDto } from '@/infrastructure/dtos/common/common-response.dto'; import { FileManagerService } from '@/infrastructure/services/file-manager/file-manager.service'; import { Injectable } from '@nestjs/common'; -// import { EventEmitter2 } from '@nestjs/event-emitter'; +import { EventEmitter2 } from '@nestjs/event-emitter'; @Injectable() export class ConfigsUsecases { constructor( private readonly fileManagerService: FileManagerService, - // private readonly eventEmitter: EventEmitter2, + private readonly eventEmitter: EventEmitter2, ) {} /** @@ -41,11 +41,11 @@ export class ConfigsUsecases { .writeConfigFile(newConfigs) .then(async () => { if (group) { - // this.eventEmitter.emit('config.updated', { - // group, - // key, - // value, - // }); + this.eventEmitter.emit('config.updated', { + group, + key, + value, + }); } }) .then(() => { diff --git a/cortex-js/src/usecases/threads/threads.usecases.ts b/cortex-js/src/usecases/threads/threads.usecases.ts index ac1fd2666..0ffcfa522 100644 --- a/cortex-js/src/usecases/threads/threads.usecases.ts +++ b/cortex-js/src/usecases/threads/threads.usecases.ts @@ -195,6 +195,7 @@ export class ThreadsUsecases { } async retrieveMessage(_threadId: string, messageId: string) { + // we still allow user to delete message even if the thread is not there return this.getMessageOrThrow(messageId); } From 858077419ac7b2729700dc2c2c67c4d5cf56d1af Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Tue, 9 Jul 2024 01:15:20 +0700 Subject: [PATCH 64/64] change naming --- .../src/usecases/assistants/assistants.usecases.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cortex-js/src/usecases/assistants/assistants.usecases.ts b/cortex-js/src/usecases/assistants/assistants.usecases.ts index 00cf850fa..b3b425468 100644 --- a/cortex-js/src/usecases/assistants/assistants.usecases.ts +++ b/cortex-js/src/usecases/assistants/assistants.usecases.ts @@ -12,7 +12,7 @@ import { Repository } from 'sequelize-typescript'; export class AssistantsUsecases { constructor( @Inject('ASSISTANT_REPOSITORY') - private readonly assistantModel: Repository, + private readonly assistantRepository: Repository, private readonly modelRepository: ModelRepository, ) {} @@ -36,7 +36,7 @@ export class AssistantsUsecases { }; try { - await this.assistantModel.create(assistant); + await this.assistantRepository.create(assistant); } catch (err) { throw err; } @@ -60,7 +60,7 @@ export class AssistantsUsecases { where.id = { [Op.lt]: before }; } - const assistants = await this.assistantModel.findAll({ + const assistants = await this.assistantRepository.findAll({ where, order: [['created_at', normalizedOrder]], limit: limit + 1, @@ -79,17 +79,17 @@ export class AssistantsUsecases { } async findAll(): Promise { - return this.assistantModel.findAll(); + return this.assistantRepository.findAll(); } async findOne(id: string) { - return this.assistantModel.findOne({ + return this.assistantRepository.findOne({ where: { id }, }); } async remove(id: string) { - return this.assistantModel.destroy({ + return this.assistantRepository.destroy({ where: { id }, }); }