Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions cortex-js/src/infrastructure/commanders/chat.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'nest-commander';
import { ChatCliUsecases } from './usecases/chat.cli.usecases';
import { exit } from 'node:process';
import { PSCliUsecases } from './usecases/ps.cli.usecases';
import { ModelStat, PSCliUsecases } from './usecases/ps.cli.usecases';
import { ModelsUsecases } from '@/usecases/models/models.usecases';

type ChatOptions = {
Expand Down Expand Up @@ -41,16 +41,7 @@ export class ChatCommand extends CommandRunner {
if (models.length === 1) {
modelId = models[0].modelId;
} else if (models.length > 0) {
const { model } = await this.inquirerService.inquirer.prompt({
type: 'list',
name: 'model',
message: 'Select running model to chat with:',
choices: models.map((e) => ({
name: e.modelId,
value: e.modelId,
})),
});
modelId = model;
modelId = await this.modelInquiry(models);
} else {
console.error('Model ID is required');
exit(1);
Expand All @@ -66,6 +57,19 @@ export class ChatCommand extends CommandRunner {
);
}

modelInquiry = async (models: ModelStat[]) => {
const { model } = await this.inquirerService.inquirer.prompt({
type: 'list',
name: 'model',
message: 'Select running model to chat with:',
choices: models.map((e) => ({
name: e.modelId,
value: e.modelId,
})),
});
return model;
};

@Option({
flags: '-t, --thread <thread_id>',
description: 'Thread Id. If not provided, will create new thread',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { CommandRunner, SubCommand, Option } from 'nest-commander';
import {
CommandRunner,
SubCommand,
Option,
InquirerService,
} from 'nest-commander';
import { exit } from 'node:process';
import { ModelsCliUsecases } from '../usecases/models.cli.usecases';
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
Expand All @@ -9,16 +14,22 @@ type ModelStartOptions = {
@SubCommand({ name: 'start', description: 'Start a model by ID.' })
export class ModelStartCommand extends CommandRunner {
constructor(
private readonly inquirerService: InquirerService,
private readonly cortexUsecases: CortexUsecases,
private readonly modelsCliUsecases: ModelsCliUsecases,
) {
super();
}

async run(input: string[], options: ModelStartOptions): Promise<void> {
if (input.length === 0) {
console.error('Model ID is required');
exit(1);
let modelId = input[0];
if (!modelId) {
try {
modelId = await this.modelInquiry();
} catch {
console.error('Model ID is required');
exit(1);
}
}

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

modelInquiry = async () => {
const models = await this.modelsCliUsecases.listAllModels();
if (!models.length) throw 'No models found';
const { model } = await this.inquirerService.inquirer.prompt({
type: 'list',
name: 'model',
message: 'Select a model to start:',
choices: models.map((e) => ({
name: e.name,
value: e.id,
})),
});
return model;
};

@Option({
flags: '-a, --attach',
description: 'Attach to interactive chat session',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { defaultCortexCppHost, defaultCortexCppPort } from 'constant';

interface ModelStat {
export interface ModelStat {
modelId: string;
engine?: string;
duration?: string;
Expand Down