@@ -9,6 +9,11 @@ import { exit } from 'node:process';
99import { ChatCliUsecases } from '@commanders/usecases/chat.cli.usecases' ;
1010import { ModelsCliUsecases } from '@commanders/usecases/models.cli.usecases' ;
1111import { 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
1318type 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+ / ^ ( h t t p | h t t p s ) : \/ \/ [ ^ / ] + \/ .* / . 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