Skip to content

Commit

Permalink
feat: cortex single executable binary (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo authored Jun 18, 2024
1 parent e421676 commit d72d08a
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 15 deletions.
9 changes: 8 additions & 1 deletion cortex-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"scripts": {
"dev": "nest dev",
"build": "yarn build:extensions && nest build && cpx \"cpuinfo/bin/**\" dist/bin",
"build:binary": "yarn build && nexe dist/src/command.js --build --python=$(which python3) -o dist/cortex",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"build:extensions": "run-script-os",
"build:extensions:windows": "powershell -command \"$jobs = Get-ChildItem -Path './src/extensions' -Directory | ForEach-Object { Start-Job -Name ($_.Name) -ScriptBlock { param($_dir); try { Set-Location $_dir; yarn; yarn build; Write-Output 'Build successful in ' + $_dir } catch { Write-Error 'Error in ' + $_dir; throw } } -ArgumentList $_.FullName }; $jobs | Wait-Job; $jobs | ForEach-Object { Receive-Job -Job $_ -Keep } | ForEach-Object { Write-Host $_ }; $failed = $jobs | Where-Object { $_.State -ne 'Completed' -or $_.ChildJobs[0].JobStateInfo.State -ne 'Completed' }; if ($failed) { Exit 1 }\"",
Expand All @@ -19,7 +20,7 @@
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:prod": "node dist/src/main --trace-deprecation",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
Expand Down Expand Up @@ -84,8 +85,10 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"hanbi": "^1.0.3",
"is-primitive": "^3.0.1",
"jest": "^29.5.0",
"nest-commander-testing": "^3.3.0",
"nexe": "^4.0.0-rc.6",
"prettier": "^3.0.0",
"run-script-os": "^1.1.6",
"source-map-support": "^0.5.21",
Expand All @@ -95,6 +98,10 @@
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
},
"resolutions": {
"ajv": "8.15.0",
"whatwg-url": "14.0.0"
},
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion cortex-js/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ModelsController } from './infrastructure/controllers/models.controller
import { ThreadsController } from './infrastructure/controllers/threads.controller';
import { StatusController } from './infrastructure/controllers/status.controller';
import { ProcessController } from './infrastructure/controllers/process.controller';
import { DownloadManagerModule } from './download-manager/download-manager.module';
import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module';

@Module({
imports: [
Expand Down
2 changes: 1 addition & 1 deletion cortex-js/src/command.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { UtilModule } from './util/util.module';
import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command';
import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { DownloadManagerModule } from './download-manager/download-manager.module';
import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module';
import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command';

@Module({
Expand Down
2 changes: 1 addition & 1 deletion cortex-js/src/command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node --no-warnings
#!/usr/bin/env node
import { CommandFactory } from 'nest-commander';
import { CommandModule } from './command.module';
import updateNotifier from 'update-notifier';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DatabaseModule } from '../database/database.module';
import { ExtensionModule } from '../repositories/extensions/extension.module';
import { ModelRepositoryModule } from '../repositories/models/model.module';
import { HttpModule } from '@nestjs/axios';
import { DownloadManagerModule } from '@/download-manager/download-manager.module';
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { TelemetryModule } from '@/usecases/telemetry/telemetry.module';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DatabaseModule } from '../database/database.module';
import { ModelRepositoryModule } from '../repositories/models/model.module';
import { ExtensionModule } from '../repositories/extensions/extension.module';
import { HttpModule } from '@nestjs/axios';
import { DownloadManagerModule } from '@/download-manager/download-manager.module';
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { TelemetryModule } from '@/usecases/telemetry/telemetry.module';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ModelStatus,
ModelStatusAndEvent,
} from '@/domain/models/model.event';
import { DownloadManagerService } from '@/download-manager/download-manager.service';
import { DownloadManagerService } from '@/infrastructure/services/download-manager/download-manager.service';
import { ModelsUsecases } from '@/usecases/models/models.usecases';
import { Controller, Sse } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FileManagerModule } from '@/infrastructure/services/file-manager/file-m
import { HttpModule } from '@nestjs/axios';
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
import { ModelRepositoryModule } from '../repositories/models/model.module';
import { DownloadManagerModule } from '@/download-manager/download-manager.module';
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { TelemetryModule } from '@/usecases/telemetry/telemetry.module';
import { UtilModule } from '@/util/util.module';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
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';

export const mysqlDatabaseProviders = [
{
Expand All @@ -12,7 +15,7 @@ export const mysqlDatabaseProviders = [
username: 'root',
password: '',
database: databaseName,
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
entities: [ThreadEntity, AssistantEntity, MessageEntity],
synchronize: process.env.NODE_ENV !== 'production',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { FileManagerService } from '@/infrastructure/services/file-manager/file-
import { databaseFile } from '@/infrastructure/constants/cortex';
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';

export const sqliteDatabaseProviders = [
{
Expand All @@ -14,7 +17,7 @@ export const sqliteDatabaseProviders = [
type: 'sqlite',
database: sqlitePath,
synchronize: process.env.NODE_ENV !== 'production',
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
entities: [ThreadEntity, AssistantEntity, MessageEntity],
});

return dataSource.initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HttpModule } from '@nestjs/axios';
import { ModelRepository } from '@/domain/repositories/model.interface';
import { ModelRepositoryImpl } from './model.repository';
import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module';
import { DownloadManagerModule } from '@/download-manager/download-manager.module';
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module';

@Module({
imports: [
Expand Down
2 changes: 1 addition & 1 deletion cortex-js/src/usecases/chat/chat.usecases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ExtensionModule } from '@/infrastructure/repositories/extensions/extens
import { TelemetryModule } from '../telemetry/telemetry.module';
import { ModelRepositoryModule } from '@/infrastructure/repositories/models/model.module';
import { HttpModule } from '@nestjs/axios';
import { DownloadManagerModule } from '@/download-manager/download-manager.module';
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module';
import { EventEmitterModule } from '@nestjs/event-emitter';

describe('ChatService', () => {
Expand Down
2 changes: 1 addition & 1 deletion cortex-js/src/usecases/models/models.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TelemetryModule } from '../telemetry/telemetry.module';
import { UtilModule } from '@/util/util.module';
import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module';
import { ModelRepositoryModule } from '@/infrastructure/repositories/models/model.module';
import { DownloadManagerModule } from '@/download-manager/download-manager.module';
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module';

@Module({
imports: [
Expand Down
2 changes: 1 addition & 1 deletion cortex-js/src/usecases/models/models.usecases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ExtensionModule } from '@/infrastructure/repositories/extensions/extens
import { FileManagerModule } from '@/infrastructure/services/file-manager/file-manager.module';
import { HttpModule } from '@nestjs/axios';
import { ModelRepositoryModule } from '@/infrastructure/repositories/models/model.module';
import { DownloadManagerModule } from '@/download-manager/download-manager.module';
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { TelemetryModule } from '../telemetry/telemetry.module';
import { UtilModule } from '@/util/util.module';
Expand Down
2 changes: 1 addition & 1 deletion cortex-js/src/usecases/models/models.usecases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import {
getHFModelMetadata,
} from '@/utils/huggingface';
import { DownloadType } from '@/domain/models/download.interface';
import { DownloadManagerService } from '@/download-manager/download-manager.service';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { ModelId, ModelStatus } from '@/domain/models/model.event';
import { DownloadManagerService } from '@/infrastructure/services/download-manager/download-manager.service';

@Injectable()
export class ModelsUsecases {
Expand Down

0 comments on commit d72d08a

Please sign in to comment.