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

Commit 92e22cb

Browse files
committed
feat: add engine pull support for tensorrt-llm
1 parent fd9d8c3 commit 92e22cb

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

cortex-js/src/infrastructure/commanders/usecases/init.cli.usecases.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { rm } from 'fs/promises';
1212
import { exec } from 'child_process';
1313
import { appPath } from '@/utils/app-path';
1414
import {
15-
CORTEX_ONNX_ENGINE_RELEASES_URL,
15+
CORTEX_ENGINE_RELEASES_URL,
1616
CORTEX_RELEASES_URL,
1717
CUDA_DOWNLOAD_URL,
1818
} from '@/infrastructure/constants/cortex';
@@ -70,13 +70,13 @@ export class InitCliUsecases {
7070
)
7171
await this.installLlamaCppEngine(options, version);
7272

73-
if (engine === 'cortex.onnx' && process.platform === 'win32')
74-
await this.installONNXEngine();
75-
else if (engine === 'cortex.onnx' && process.platform !== 'win32') {
73+
if (engine === 'cortex.onnx' && process.platform !== 'win32') {
7674
console.error('The ONNX engine does not support this OS yet.');
7775
process.exit(1);
7876
}
7977

78+
if (engine !== 'cortex.llamacpp') await this.installAcceleratedEngine();
79+
8080
configs.initialized = true;
8181
await this.fileManagerService.writeConfigFile(configs);
8282
};
@@ -305,17 +305,17 @@ export class InitCliUsecases {
305305
};
306306

307307
/**
308-
* Download and install ONNX engine
308+
* Download and install accelerated engine
309309
* @param version
310310
* @param engineFileName
311311
*/
312-
private async installONNXEngine(
312+
private async installAcceleratedEngine(
313313
version: string = 'latest',
314-
engineFileName: string = 'windows-amd64',
314+
engine: string = 'cortex.onnx',
315315
) {
316316
const res = await firstValueFrom(
317317
this.httpService.get(
318-
CORTEX_ONNX_ENGINE_RELEASES_URL +
318+
CORTEX_ENGINE_RELEASES_URL(engine) +
319319
`${version === 'latest' ? '/latest' : ''}`,
320320
{
321321
headers: {
@@ -338,15 +338,17 @@ export class InitCliUsecases {
338338
);
339339
}
340340
const toDownloadAsset = release.assets.find((s: any) =>
341-
s.name.includes(engineFileName),
341+
s.name.includes(process.platform === 'win32' ? 'windows' : 'linux'),
342342
);
343343

344344
if (!toDownloadAsset) {
345-
console.log(`Could not find engine file ${engineFileName}`);
345+
console.log(
346+
`Could not find engine file for platform ${process.platform}`,
347+
);
346348
exit(1);
347349
}
348350

349-
console.log(`Downloading ONNX engine file ${engineFileName}`);
351+
console.log(`Downloading ONNX engine file ${toDownloadAsset.name}`);
350352
const dataFolderPath = await this.fileManagerService.getDataFolderPath();
351353
const engineDir = join(dataFolderPath, 'cortex-cpp');
352354

@@ -397,7 +399,7 @@ export class InitCliUsecases {
397399
await rm(destination, { force: true });
398400

399401
// Copy the additional files to the cortex-cpp directory
400-
for (const file of readdirSync(join(engineDir, 'engines', 'cortex.onnx'))) {
402+
for (const file of readdirSync(join(engineDir, 'engines', engine))) {
401403
if (file !== 'engine.dll') {
402404
await cpSync(
403405
join(engineDir, 'engines', 'cortex.onnx', file),

cortex-js/src/infrastructure/constants/cortex.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export const CORTEX_JS_STOP_API_SERVER_URL = (
4242
export const CORTEX_RELEASES_URL =
4343
'https://api.github.com/repos/janhq/cortex/releases';
4444

45-
export const CORTEX_ONNX_ENGINE_RELEASES_URL =
46-
'https://api.github.com/repos/janhq/cortex.onnx/releases';
45+
export const CORTEX_ENGINE_RELEASES_URL = (engine: string) =>
46+
`https://api.github.com/repos/janhq/${engine}/releases`;
4747

4848
export const CUDA_DOWNLOAD_URL =
4949
'https://catalog.jan.ai/dist/cuda-dependencies/<version>/<platform>/cuda.tar.gz';

0 commit comments

Comments
 (0)