Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 0be10c5

Browse files
louis-janirfanpena
authored andcommitted
fix: cortex node suppress warning (#771)
1 parent 1b2cb35 commit 0be10c5

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

cortex-js/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"scripts": {
1212
"dev": "nest dev",
1313
"build": "nest build && cpx \"cpuinfo/bin/**\" dist/bin",
14-
"build:binary": "run-script-os && cpx \"cpuinfo/bin/**\" dist/bin",
14+
"build:binary": "npx -q patch-package && run-script-os && cpx \"cpuinfo/bin/**\" dist/bin",
1515
"build:binary:windows": "bun build --compile ./src/command.ts --outfile cortex.exe --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
1616
"build:binary:linux": "bun build --compile ./src/command.ts --outfile cortex --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
1717
"build:binary:macos": "bun build --compile ./src/command.ts --outfile cortex --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
@@ -31,8 +31,7 @@
3131
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
3232
"test:e2e": "jest --config ./test/jest-e2e.json",
3333
"typeorm": "typeorm-ts-node-esm",
34-
"build:dev": "npx nest build && chmod +x ./dist/src/command.js && npm link",
35-
"postinstall": "npx patch-package"
34+
"build:dev": "npx nest build && chmod +x ./dist/src/command.js && npm link"
3635
},
3736
"dependencies": {
3837
"@huggingface/gguf": "^0.1.5",

cortex-js/src/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env node --no-warnings
22
import { CommandFactory } from 'nest-commander';
33
import { CommandModule } from './command.module';
44
import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases';

cortex-js/src/infrastructure/commanders/shortcuts/run.command.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import { exit } from 'node:process';
99
import { ChatCliUsecases } from '@commanders/usecases/chat.cli.usecases';
1010
import { ModelsCliUsecases } from '@commanders/usecases/models.cli.usecases';
1111
import { ModelNotFoundException } from '@/infrastructure/exception/model-not-found.exception';
12+
import { existsSync } from 'fs';
13+
import { join } from 'path';
14+
import { FileManagerService } from '@/infrastructure/services/file-manager/file-manager.service';
15+
import { InitCliUsecases } from '../usecases/init.cli.usecases';
16+
import { Engines } from '../types/engine.interface';
1217

1318
type RunOptions = {
1419
threadId?: string;
@@ -30,6 +35,8 @@ export class RunCommand extends CommandRunner {
3035
private readonly cortexUsecases: CortexUsecases,
3136
private readonly chatCliUsecases: ChatCliUsecases,
3237
private readonly inquirerService: InquirerService,
38+
private readonly fileService: FileManagerService,
39+
private readonly initUsecases: InitCliUsecases,
3340
) {
3441
super();
3542
}
@@ -57,6 +64,33 @@ export class RunCommand extends CommandRunner {
5764
});
5865
}
5966

67+
// Second check if model is available
68+
const existingModel = await this.modelsCliUsecases.getModel(modelId);
69+
if (
70+
!existingModel ||
71+
!Array.isArray(existingModel.files) ||
72+
/^(http|https):\/\/[^/]+\/.*/.test(existingModel.files[0])
73+
) {
74+
console.error('Model is not available. Please pull the model first.');
75+
process.exit(1);
76+
}
77+
78+
const engine = existingModel.engine || 'cortex.llamacpp';
79+
// Pull engine if not exist
80+
if (
81+
!existsSync(join(await this.fileService.getCortexCppEnginePath(), engine))
82+
) {
83+
await this.initUsecases.installEngine(
84+
await this.initUsecases.defaultInstallationOptions(),
85+
'latest',
86+
engine,
87+
);
88+
}
89+
if (engine === Engines.onnx && process.platform !== 'win32') {
90+
console.error('The ONNX engine does not support this OS yet.');
91+
process.exit(1);
92+
}
93+
6094
return this.cortexUsecases
6195
.startCortex(false)
6296
.then(() => this.modelsCliUsecases.startModel(modelId, options.preset))

cortex-js/src/usecases/cortex/cortex.usecases.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@nestjs/common';
22
import { ChildProcess, spawn } from 'child_process';
3-
import { join } from 'path';
3+
import { delimiter, join } from 'path';
44
import { CortexOperationSuccessfullyDto } from '@/infrastructure/dtos/cortex/cortex-operation-successfully.dto';
55
import { HttpService } from '@nestjs/axios';
66

@@ -11,6 +11,7 @@ import {
1111
CORTEX_CPP_HEALTH_Z_URL,
1212
CORTEX_CPP_PROCESS_DESTROY_URL,
1313
} from '@/infrastructure/constants/cortex';
14+
import { Engines } from '@/infrastructure/commanders/types/engine.interface';
1415

1516
@Injectable()
1617
export class CortexUsecases {
@@ -44,6 +45,11 @@ export class CortexUsecases {
4445
throw new Error('The engine is not available, please run "cortex init".');
4546
}
4647

48+
const cortexCPPPath = join(
49+
await this.fileManagerService.getDataFolderPath(),
50+
'cortex-cpp',
51+
);
52+
4753
// go up one level to get the binary folder, have to also work on windows
4854
this.cortexProcess = spawn(cortexCppPath, args, {
4955
detached: !attach,
@@ -52,6 +58,11 @@ export class CortexUsecases {
5258
env: {
5359
...process.env,
5460
CUDA_VISIBLE_DEVICES: '0',
61+
PATH: (process.env.PATH || '').concat(delimiter, cortexCPPPath),
62+
LD_LIBRARY_PATH: (process.env.LD_LIBRARY_PATH || '').concat(
63+
delimiter,
64+
cortexCPPPath,
65+
),
5566
// // Vulkan - Support 1 device at a time for now
5667
// ...(executableOptions.vkVisibleDevices?.length > 0 && {
5768
// GGML_VULKAN_DEVICE: executableOptions.vkVisibleDevices[0],

0 commit comments

Comments
 (0)