-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feat/cortex-publish-launchpad
- Loading branch information
Showing
12 changed files
with
144 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,86 @@ | ||
import { CommandRunner, SubCommand } from 'nest-commander'; | ||
import { SubCommand } from 'nest-commander'; | ||
import { ModelStartCommand } from './models/model-start.command'; | ||
import { ModelGetCommand } from './models/model-get.command'; | ||
import { ModelListCommand } from './models/model-list.command'; | ||
import { ModelStopCommand } from './models/model-stop.command'; | ||
import { ModelPullCommand } from './models/model-pull.command'; | ||
import { ModelRemoveCommand } from './models/model-remove.command'; | ||
import { ModelUpdateCommand } from './models/model-update.command'; | ||
import { RunCommand } from './shortcuts/run.command'; | ||
import { BaseCommand } from './base.command'; | ||
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases'; | ||
import { ModuleRef } from '@nestjs/core'; | ||
import { ModelPullCommand } from './models/model-pull.command'; | ||
|
||
@SubCommand({ | ||
name: 'models', | ||
subCommands: [ | ||
ModelPullCommand, | ||
ModelStartCommand, | ||
ModelStopCommand, | ||
ModelListCommand, | ||
ModelGetCommand, | ||
ModelRemoveCommand, | ||
ModelUpdateCommand, | ||
RunCommand, | ||
], | ||
description: 'Subcommands for managing models', | ||
}) | ||
export class ModelsCommand extends BaseCommand { | ||
async runCommand(): Promise<void> { | ||
this.command?.help(); | ||
constructor( | ||
private readonly moduleRef: ModuleRef, | ||
readonly cortexUsecases: CortexUsecases, | ||
) { | ||
super(cortexUsecases); | ||
} | ||
|
||
commandMap: { [key: string]: any } = { | ||
pull: ModelPullCommand, | ||
start: ModelStartCommand, | ||
stop: ModelStopCommand, | ||
list: ModelListCommand, | ||
get: ModelGetCommand, | ||
remove: ModelRemoveCommand, | ||
update: ModelUpdateCommand, | ||
}; | ||
async runCommand(passedParam: string[], options: any) { | ||
const [parameter, command, ...restParams] = passedParam; | ||
if (command !== 'list' && !parameter) { | ||
console.error('Model id is required.'); | ||
return; | ||
} | ||
|
||
// Handle the commands accordingly | ||
const commandClass = this.commandMap[command as string]; | ||
if (!commandClass) { | ||
this.command?.help(); | ||
return; | ||
} | ||
const modelId = parameter; | ||
await this.runModelCommand( | ||
commandClass, | ||
[modelId, ...(restParams || [])], | ||
options, | ||
); | ||
} | ||
|
||
private async runModelCommand( | ||
commandClass: any, | ||
params: string[] = [], | ||
options?: any, | ||
) { | ||
const commandInstance = this.moduleRef.get(commandClass, { strict: false }); | ||
if (commandInstance) { | ||
await commandInstance.run(params, options); | ||
} else { | ||
console.error('Command not found.'); | ||
} | ||
} | ||
|
||
help() { | ||
console.log('Usage: cortex models <subcommand|parameter> [subcommand]'); | ||
console.log('Commands:'); | ||
console.log(' <model_id> start - Start a model by ID'); | ||
console.log(' <model_id> stop - Stop a model by ID'); | ||
console.log(' list - List all available models'); | ||
console.log(' <model_id> get - Get model details by ID'); | ||
console.log(' <model_id> remove - Remove a model by ID'); | ||
console.log(' <model_id> update - Update a model by ID'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters