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

Commit 6cefe1c

Browse files
authored
chore: separating commands (#577)
1 parent b41299c commit 6cefe1c

File tree

17 files changed

+248
-97
lines changed

17 files changed

+248
-97
lines changed

cortex-js/src/command.module.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ import { DatabaseModule } from './infrastructure/database/database.module';
55
import { ConfigModule } from '@nestjs/config';
66
import { CortexModule } from './usecases/cortex/cortex.module';
77
import { ServeCommand } from './infrastructure/commanders/serve.command';
8-
import { PullCommand } from './infrastructure/commanders/pull.command';
9-
import { InferenceCommand } from './infrastructure/commanders/inference.command';
8+
import { ChatCommand } from './infrastructure/commanders/chat.command';
109
import { ModelsCommand } from './infrastructure/commanders/models.command';
1110
import { StartCommand } from './infrastructure/commanders/start.command';
1211
import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module';
1312
import { ChatModule } from './usecases/chat/chat.module';
1413
import { InitCommand } from './infrastructure/commanders/init.command';
1514
import { HttpModule } from '@nestjs/axios';
1615
import { CreateInitQuestions } from './infrastructure/commanders/inquirer/init.questions';
16+
import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command';
17+
import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command';
18+
import { ModelListCommand } from './infrastructure/commanders/models/model-list.command';
19+
import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command';
20+
import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command';
21+
import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command';
1722

1823
@Module({
1924
imports: [
@@ -32,12 +37,19 @@ import { CreateInitQuestions } from './infrastructure/commanders/inquirer/init.q
3237
providers: [
3338
BasicCommand,
3439
ModelsCommand,
35-
PullCommand,
3640
ServeCommand,
37-
InferenceCommand,
41+
ChatCommand,
3842
StartCommand,
3943
InitCommand,
4044
CreateInitQuestions,
45+
46+
// Model commands
47+
ModelStartCommand,
48+
ModelStopCommand,
49+
ModelListCommand,
50+
ModelGetCommand,
51+
ModelRemoveCommand,
52+
ModelPullCommand,
4153
],
4254
})
4355
export class CommandModule {}

cortex-js/src/domain/abstracts/engine.abstract.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-unused-vars, @typescript-eslint/no-unused-vars */
12
import { Model, ModelSettingParams } from '../models/model.interface';
23
import { Extension } from './extension.abstract';
34

cortex-js/src/infrastructure/commanders/basic-command.commander.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { RootCommand, CommandRunner, Option } from 'nest-commander';
2-
import { PullCommand } from './pull.command';
32
import { ServeCommand } from './serve.command';
4-
import { InferenceCommand } from './inference.command';
3+
import { ChatCommand } from './chat.command';
54
import { ModelsCommand } from './models.command';
65
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
76
import { defaultCortexJsHost, defaultCortexJsPort } from 'constant';
87
import { InitCommand } from './init.command';
8+
import { StartCommand } from './start.command';
99

1010
@RootCommand({
1111
subCommands: [
1212
ModelsCommand,
13-
PullCommand,
1413
ServeCommand,
15-
InferenceCommand,
14+
ChatCommand,
1615
InitCommand,
16+
StartCommand,
1717
],
1818
})
1919
export class BasicCommand extends CommandRunner {
@@ -31,10 +31,12 @@ export class BasicCommand extends CommandRunner {
3131
return this.cortexUsecases
3232
.startCortex(host, port)
3333
.then((e) => console.log(e));
34+
3435
case 'stop':
3536
return this.cortexUsecases
3637
.stopCortex(defaultCortexJsHost, defaultCortexJsPort)
3738
.then((e) => console.log(e));
39+
3840
default:
3941
console.error(`Command ${command} is not supported`);
4042
return;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ChatUsecases } from '@/usecases/chat/chat.usecases';
2+
import { CommandRunner, SubCommand } from 'nest-commander';
3+
import { ChatCliUsecases } from './usecases/chat.cli.usecases';
4+
5+
@SubCommand({ name: 'chat' })
6+
export class ChatCommand extends CommandRunner {
7+
constructor(private readonly chatUsecases: ChatUsecases) {
8+
super();
9+
}
10+
11+
async run(input: string[]): Promise<void> {
12+
const chatCliService = new ChatCliUsecases(this.chatUsecases);
13+
return chatCliService.run(input);
14+
}
15+
}
Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,22 @@
1-
import { ModelsUsecases } from '@/usecases/models/models.usecases';
21
import { CommandRunner, SubCommand } from 'nest-commander';
3-
import { PullCommand } from './pull.command';
4-
import { StartCommand } from './start.command';
2+
import { ModelStartCommand } from './models/model-start.command';
3+
import { ModelGetCommand } from './models/model-get.command';
4+
import { ModelListCommand } from './models/model-list.command';
5+
import { ModelStopCommand } from './models/model-stop.command';
6+
import { ModelPullCommand } from './models/model-pull.command';
7+
import { ModelRemoveCommand } from './models/model-remove.command';
58

6-
@SubCommand({ name: 'models', subCommands: [PullCommand, StartCommand] })
9+
@SubCommand({
10+
name: 'models',
11+
subCommands: [
12+
ModelPullCommand,
13+
ModelStartCommand,
14+
ModelStopCommand,
15+
ModelListCommand,
16+
ModelGetCommand,
17+
ModelRemoveCommand,
18+
],
19+
})
720
export class ModelsCommand extends CommandRunner {
8-
constructor(private readonly modelsUsecases: ModelsUsecases) {
9-
super();
10-
}
11-
12-
async run(input: string[]): Promise<void> {
13-
const command = input[0];
14-
const modelId = input[1];
15-
16-
if (command !== 'list') {
17-
if (!modelId) {
18-
console.log('Model ID is required');
19-
return;
20-
}
21-
}
22-
23-
switch (command) {
24-
case 'list':
25-
this.modelsUsecases.findAll().then(console.log);
26-
return;
27-
case 'get':
28-
this.modelsUsecases.findOne(modelId).then(console.log);
29-
return;
30-
case 'remove':
31-
this.modelsUsecases.remove(modelId).then(console.log);
32-
return;
33-
34-
case 'stop':
35-
return this.modelsUsecases
36-
.stopModel(modelId)
37-
.then(console.log)
38-
.catch(console.error);
39-
40-
case 'stats':
41-
case 'fetch':
42-
case 'build': {
43-
console.log('Command is not supported yet');
44-
return;
45-
}
46-
47-
default:
48-
console.error(`Command ${command} is not supported`);
49-
return;
50-
}
51-
}
21+
async run(): Promise<void> {}
5222
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ModelsUsecases } from '@/usecases/models/models.usecases';
2+
import { CommandRunner, SubCommand } from 'nest-commander';
3+
import { ModelsCliUsecases } from '../usecases/models.cli.usecases';
4+
import { exit } from 'node:process';
5+
6+
@SubCommand({ name: 'get' })
7+
export class ModelGetCommand extends CommandRunner {
8+
constructor(private readonly modelsUsecases: ModelsUsecases) {
9+
super();
10+
}
11+
12+
async run(input: string[]): Promise<void> {
13+
if (input.length === 0) {
14+
console.error('Model ID is required');
15+
exit(1);
16+
}
17+
18+
const modelsCliUsecases = new ModelsCliUsecases(this.modelsUsecases);
19+
const models = await modelsCliUsecases.getModel(input[0]);
20+
console.log(models);
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ModelsUsecases } from '@/usecases/models/models.usecases';
2+
import { CommandRunner, SubCommand } from 'nest-commander';
3+
import { ModelsCliUsecases } from '../usecases/models.cli.usecases';
4+
5+
@SubCommand({ name: 'list' })
6+
export class ModelListCommand extends CommandRunner {
7+
constructor(private readonly modelsUsecases: ModelsUsecases) {
8+
super();
9+
}
10+
11+
async run(): Promise<void> {
12+
const modelsCliUsecases = new ModelsCliUsecases(this.modelsUsecases);
13+
const models = await modelsCliUsecases.listAllModels();
14+
console.log(models);
15+
}
16+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { ModelsUsecases } from '@/usecases/models/models.usecases';
2+
import { CommandRunner, SubCommand } from 'nest-commander';
3+
import { Presets, SingleBar } from 'cli-progress';
4+
import { exit } from 'node:process';
5+
import { ModelsCliUsecases } from '../usecases/models.cli.usecases';
6+
7+
@SubCommand({ name: 'pull', aliases: ['download'] })
8+
export class ModelPullCommand extends CommandRunner {
9+
constructor(private readonly modelsUsecases: ModelsUsecases) {
10+
super();
11+
}
12+
13+
async run(input: string[]) {
14+
if (input.length < 1) {
15+
console.error('Model ID is required');
16+
exit(1);
17+
}
18+
19+
const bar = new SingleBar({}, Presets.shades_classic);
20+
bar.start(100, 0);
21+
const callback = (progress: number) => {
22+
bar.update(progress);
23+
};
24+
await new ModelsCliUsecases(this.modelsUsecases).pullModel(
25+
input[0],
26+
callback,
27+
);
28+
console.log('\nDownload complete!');
29+
exit(0);
30+
}
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ModelsUsecases } from '@/usecases/models/models.usecases';
2+
import { CommandRunner, SubCommand } from 'nest-commander';
3+
import { ModelsCliUsecases } from '../usecases/models.cli.usecases';
4+
import { exit } from 'node:process';
5+
6+
@SubCommand({ name: 'remove' })
7+
export class ModelRemoveCommand extends CommandRunner {
8+
constructor(private readonly modelsUsecases: ModelsUsecases) {
9+
super();
10+
}
11+
12+
async run(input: string[]): Promise<void> {
13+
if (input.length === 0) {
14+
console.error('Model ID is required');
15+
exit(1);
16+
}
17+
18+
const modelsCliUsecases = new ModelsCliUsecases(this.modelsUsecases);
19+
const result = await modelsCliUsecases.removeModel(input[0]);
20+
console.log(result);
21+
}
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ModelsUsecases } from '@/usecases/models/models.usecases';
2+
import { CommandRunner, SubCommand } from 'nest-commander';
3+
import { exit } from 'node:process';
4+
import { ModelsCliUsecases } from '../usecases/models.cli.usecases';
5+
6+
@SubCommand({ name: 'start' })
7+
export class ModelStartCommand extends CommandRunner {
8+
constructor(private readonly modelsUsecases: ModelsUsecases) {
9+
super();
10+
}
11+
12+
async run(input: string[]): Promise<void> {
13+
if (input.length === 0) {
14+
console.error('Model ID is required');
15+
exit(1);
16+
}
17+
18+
const modelsCliUsecases = new ModelsCliUsecases(this.modelsUsecases);
19+
await modelsCliUsecases.startModel(input[0]);
20+
}
21+
}

0 commit comments

Comments
 (0)