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

Commit 1a17c1c

Browse files
committed
chore: add engine pull on run
1 parent 9dada4a commit 1a17c1c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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))

0 commit comments

Comments
 (0)