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

Commit bb51792

Browse files
authored
fix: allow users to select a model to start (#633)
1 parent c08c797 commit bb51792

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

cortex-js/src/infrastructure/commanders/chat.command.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from 'nest-commander';
77
import { ChatCliUsecases } from './usecases/chat.cli.usecases';
88
import { exit } from 'node:process';
9-
import { PSCliUsecases } from './usecases/ps.cli.usecases';
9+
import { ModelStat, PSCliUsecases } from './usecases/ps.cli.usecases';
1010
import { ModelsUsecases } from '@/usecases/models/models.usecases';
1111

1212
type ChatOptions = {
@@ -41,16 +41,7 @@ export class ChatCommand extends CommandRunner {
4141
if (models.length === 1) {
4242
modelId = models[0].modelId;
4343
} else if (models.length > 0) {
44-
const { model } = await this.inquirerService.inquirer.prompt({
45-
type: 'list',
46-
name: 'model',
47-
message: 'Select running model to chat with:',
48-
choices: models.map((e) => ({
49-
name: e.modelId,
50-
value: e.modelId,
51-
})),
52-
});
53-
modelId = model;
44+
modelId = await this.modelInquiry(models);
5445
} else {
5546
console.error('Model ID is required');
5647
exit(1);
@@ -66,6 +57,19 @@ export class ChatCommand extends CommandRunner {
6657
);
6758
}
6859

60+
modelInquiry = async (models: ModelStat[]) => {
61+
const { model } = await this.inquirerService.inquirer.prompt({
62+
type: 'list',
63+
name: 'model',
64+
message: 'Select running model to chat with:',
65+
choices: models.map((e) => ({
66+
name: e.modelId,
67+
value: e.modelId,
68+
})),
69+
});
70+
return model;
71+
};
72+
6973
@Option({
7074
flags: '-t, --thread <thread_id>',
7175
description: 'Thread Id. If not provided, will create new thread',

cortex-js/src/infrastructure/commanders/models/model-start.command.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { CommandRunner, SubCommand, Option } from 'nest-commander';
1+
import {
2+
CommandRunner,
3+
SubCommand,
4+
Option,
5+
InquirerService,
6+
} from 'nest-commander';
27
import { exit } from 'node:process';
38
import { ModelsCliUsecases } from '../usecases/models.cli.usecases';
49
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
@@ -9,16 +14,22 @@ type ModelStartOptions = {
914
@SubCommand({ name: 'start', description: 'Start a model by ID.' })
1015
export class ModelStartCommand extends CommandRunner {
1116
constructor(
17+
private readonly inquirerService: InquirerService,
1218
private readonly cortexUsecases: CortexUsecases,
1319
private readonly modelsCliUsecases: ModelsCliUsecases,
1420
) {
1521
super();
1622
}
1723

1824
async run(input: string[], options: ModelStartOptions): Promise<void> {
19-
if (input.length === 0) {
20-
console.error('Model ID is required');
21-
exit(1);
25+
let modelId = input[0];
26+
if (!modelId) {
27+
try {
28+
modelId = await this.modelInquiry();
29+
} catch {
30+
console.error('Model ID is required');
31+
exit(1);
32+
}
2233
}
2334

2435
await this.cortexUsecases
@@ -28,6 +39,21 @@ export class ModelStartCommand extends CommandRunner {
2839
.then(() => !options.attach && process.exit(0));
2940
}
3041

42+
modelInquiry = async () => {
43+
const models = await this.modelsCliUsecases.listAllModels();
44+
if (!models.length) throw 'No models found';
45+
const { model } = await this.inquirerService.inquirer.prompt({
46+
type: 'list',
47+
name: 'model',
48+
message: 'Select a model to start:',
49+
choices: models.map((e) => ({
50+
name: e.name,
51+
value: e.id,
52+
})),
53+
});
54+
return model;
55+
};
56+
3157
@Option({
3258
flags: '-a, --attach',
3359
description: 'Attach to interactive chat session',

cortex-js/src/infrastructure/commanders/usecases/ps.cli.usecases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from '@nestjs/common';
22
import { defaultCortexCppHost, defaultCortexCppPort } from 'constant';
33

4-
interface ModelStat {
4+
export interface ModelStat {
55
modelId: string;
66
engine?: string;
77
duration?: string;

0 commit comments

Comments
 (0)