Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add log to commands, load dependencies indicator #821

Merged
merged 13 commits into from
Jul 4, 2024
22 changes: 14 additions & 8 deletions cortex-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
"class-validator": "^0.14.1",
"cli-progress": "^3.12.0",
"cortexso-node": "^0.0.4",
"cpuinfo": "file:./cpuinfo",
"decompress": "^4.2.1",
"js-yaml": "^4.1.0",
"nest-commander": "^3.13.0",
"ora": "5.4.1",
"readline": "^1.3.0",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
Expand All @@ -65,8 +67,7 @@
"typeorm": "^0.3.20",
"ulid": "^2.3.0",
"uuid": "^9.0.1",
"yaml": "^2.4.2",
"cpuinfo": "file:./cpuinfo"
"yaml": "^2.4.2"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
Expand All @@ -84,6 +85,8 @@
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vercel/ncc": "^0.38.0",
"@yao-pkg/pkg": "^5.12.0",
"bun": "^1.1.15",
"cpx": "^1.5.0",
"eslint": "^8.42.0",
Expand All @@ -94,18 +97,16 @@
"jest": "^29.5.0",
"nest-commander-testing": "^3.3.0",
"node-gyp": "^10.1.0",
"patch-package": "^8.0.0",
"prettier": "^3.0.0",
"resedit-cli": "^2.0.0",
"run-script-os": "^1.1.6",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3",
"patch-package": "^8.0.0",
"@yao-pkg/pkg": "^5.12.0",
"resedit-cli": "^2.0.0",
"@vercel/ncc": "^0.38.0"
"typescript": "^5.1.3"
},
"resolutions": {
"ajv": "8.15.0",
Expand Down Expand Up @@ -137,7 +138,12 @@
},
"pkg": {
"scripts": "command/**/*.js",
"assets": ["command/*.node", "**/package.json", "node_modules/axios/**/*", "cpuinfo/**/*"],
"assets": [
"command/*.node",
"**/package.json",
"node_modules/axios/**/*",
"cpuinfo/**/*"
],
"outputPath": "dist"
}
}
6 changes: 4 additions & 2 deletions cortex-js/src/command.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env node --no-warnings
import ora from 'ora';
const dependenciesSpinner = ora('Loading dependencies...').start();
const time = Date.now();
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 { ContextService } from '@/infrastructure/services/context/context.service';

export const asyncLocalStorage = new AsyncLocalStorage();
dependenciesSpinner.succeed('Dependencies loaded in ' + (Date.now() - time) + 'ms');

async function bootstrap() {
let telemetryUseCase: TelemetryUsecases | null = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class ModelStartCommand extends CommandRunner {

async run(passedParams: string[], options: ModelStartOptions): Promise<void> {
let modelId = passedParams[0];
console.log('Finding model...');
marknguyen1302 marked this conversation as resolved.
Show resolved Hide resolved
if (!modelId) {
try {
modelId = await this.modelInquiry();
Expand Down Expand Up @@ -72,13 +73,14 @@ export class ModelStartCommand extends CommandRunner {
if (
!existsSync(join(await this.fileService.getCortexCppEnginePath(), engine))
) {
console.log('Installing engine...');
await this.initUsecases.installEngine(
await this.initUsecases.defaultInstallationOptions(),
'latest',
engine,
);
}

console.log('Starting model...');
await this.cortexUsecases
.startCortex(options.attach)
.then(() => this.modelsCliUsecases.startModel(modelId, options.preset))
Expand Down
9 changes: 7 additions & 2 deletions cortex-js/src/infrastructure/commanders/ps.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ export class PSCommand extends CommandRunner {
super();
}
async run(): Promise<void> {
console.log('Running PS command...');
return this.usecases
.getModels()
.then(console.table)
.then(() => this.usecases.isAPIServerOnline())
.then(() => {
console.log('Checking API server...');
return this.usecases.isAPIServerOnline();
})
.then((isOnline) => {
if (isOnline) console.log('API server is online');
else console.log('API server is offline');
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class RunCommand extends CommandRunner {

async run(passedParams: string[], options: RunOptions): Promise<void> {
let modelId = passedParams[0];
console.log('Running model...');
if (!modelId) {
try {
modelId = await this.modelInquiry();
Expand Down Expand Up @@ -82,6 +83,7 @@ export class RunCommand extends CommandRunner {
if (
!existsSync(join(await this.fileService.getCortexCppEnginePath(), engine))
) {
console.log('Installing engine...');
await this.initUsecases.installEngine(
await this.initUsecases.defaultInstallationOptions(),
'latest',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class PSCliUsecases {
*/
async getModels(): Promise<ModelStat[]> {
const configs = await this.fileService.getConfig();
console.log('Getting models...');
return new Promise<ModelStat[]>((resolve, reject) =>
firstValueFrom(
this.httpService.get(
Expand Down
Loading