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

Commit 4b36aa1

Browse files
feat: update models command (#905)
1 parent 349e57f commit 4b36aa1

File tree

1 file changed

+63
-7
lines changed

1 file changed

+63
-7
lines changed
Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,86 @@
1-
import { CommandRunner, SubCommand } from 'nest-commander';
1+
import { SubCommand } from 'nest-commander';
22
import { ModelStartCommand } from './models/model-start.command';
33
import { ModelGetCommand } from './models/model-get.command';
44
import { ModelListCommand } from './models/model-list.command';
55
import { ModelStopCommand } from './models/model-stop.command';
6-
import { ModelPullCommand } from './models/model-pull.command';
76
import { ModelRemoveCommand } from './models/model-remove.command';
87
import { ModelUpdateCommand } from './models/model-update.command';
9-
import { RunCommand } from './shortcuts/run.command';
108
import { BaseCommand } from './base.command';
9+
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
10+
import { ModuleRef } from '@nestjs/core';
11+
import { ModelPullCommand } from './models/model-pull.command';
1112

1213
@SubCommand({
1314
name: 'models',
1415
subCommands: [
15-
ModelPullCommand,
1616
ModelStartCommand,
1717
ModelStopCommand,
1818
ModelListCommand,
1919
ModelGetCommand,
2020
ModelRemoveCommand,
2121
ModelUpdateCommand,
22-
RunCommand,
2322
],
2423
description: 'Subcommands for managing models',
2524
})
2625
export class ModelsCommand extends BaseCommand {
27-
async runCommand(): Promise<void> {
28-
this.command?.help();
26+
constructor(
27+
private readonly moduleRef: ModuleRef,
28+
readonly cortexUsecases: CortexUsecases,
29+
) {
30+
super(cortexUsecases);
31+
}
32+
33+
commandMap: { [key: string]: any } = {
34+
pull: ModelPullCommand,
35+
start: ModelStartCommand,
36+
stop: ModelStopCommand,
37+
list: ModelListCommand,
38+
get: ModelGetCommand,
39+
remove: ModelRemoveCommand,
40+
update: ModelUpdateCommand,
41+
};
42+
async runCommand(passedParam: string[], options: any) {
43+
const [parameter, command, ...restParams] = passedParam;
44+
if (command !== 'list' && !parameter) {
45+
console.error('Model id is required.');
46+
return;
47+
}
48+
49+
// Handle the commands accordingly
50+
const commandClass = this.commandMap[command as string];
51+
if (!commandClass) {
52+
this.command?.help();
53+
return;
54+
}
55+
const modelId = parameter;
56+
await this.runModelCommand(
57+
commandClass,
58+
[modelId, ...(restParams || [])],
59+
options,
60+
);
61+
}
62+
63+
private async runModelCommand(
64+
commandClass: any,
65+
params: string[] = [],
66+
options?: any,
67+
) {
68+
const commandInstance = this.moduleRef.get(commandClass, { strict: false });
69+
if (commandInstance) {
70+
await commandInstance.run(params, options);
71+
} else {
72+
console.error('Command not found.');
73+
}
74+
}
75+
76+
help() {
77+
console.log('Usage: cortex models <subcommand|parameter> [subcommand]');
78+
console.log('Commands:');
79+
console.log(' <model_id> start - Start a model by ID');
80+
console.log(' <model_id> stop - Stop a model by ID');
81+
console.log(' list - List all available models');
82+
console.log(' <model_id> get - Get model details by ID');
83+
console.log(' <model_id> remove - Remove a model by ID');
84+
console.log(' <model_id> update - Update a model by ID');
2985
}
3086
}

0 commit comments

Comments
 (0)