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

Commit 3b0da0f

Browse files
authored
Merge pull request #578 from janhq/chore/remove-start-cortex-cli
chore: remove start cortex cli command
2 parents 96bc7c7 + 33d9faa commit 3b0da0f

30 files changed

+596
-353
lines changed

cortex-js/.env.development

Whitespace-only changes.

cortex-js/.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
EXTENSIONS_PATH=<EXTENSIONS_PATH>
22
CORTEX_MODELS_DIR=<CORTEX_MODELS_DIR>
3-
CORTEX_BINARY_PATH=<CORTEX_BINARY_PATH>

cortex-js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"typeorm": "typeorm-ts-node-esm"
2626
},
2727
"dependencies": {
28+
"@huggingface/gguf": "^0.1.5",
2829
"@nestjs/axios": "^3.0.2",
2930
"@nestjs/common": "^10.0.0",
3031
"@nestjs/config": "^3.2.2",

cortex-js/src/command.module.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import { Module } from '@nestjs/common';
2-
import { BasicCommand } from './infrastructure/commanders/basic-command.commander';
32
import { ModelsModule } from './usecases/models/models.module';
43
import { DatabaseModule } from './infrastructure/database/database.module';
54
import { ConfigModule } from '@nestjs/config';
65
import { CortexModule } from './usecases/cortex/cortex.module';
76
import { ServeCommand } from './infrastructure/commanders/serve.command';
8-
import { ChatCommand } from './infrastructure/commanders/chat.command';
97
import { ModelsCommand } from './infrastructure/commanders/models.command';
10-
import { StartCommand } from './infrastructure/commanders/start.command';
118
import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module';
129
import { ChatModule } from './usecases/chat/chat.module';
1310
import { InitCommand } from './infrastructure/commanders/init.command';
1411
import { HttpModule } from '@nestjs/axios';
15-
import { CreateInitQuestions } from './infrastructure/commanders/inquirer/init.questions';
12+
import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions';
13+
import { ModelListCommand } from './infrastructure/commanders/models/model-list.command';
14+
import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command';
15+
import { CortexCommand } from './infrastructure/commanders/cortex-command.commander';
16+
import { ChatCommand } from './infrastructure/commanders/chat.command';
1617
import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command';
1718
import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command';
18-
import { ModelListCommand } from './infrastructure/commanders/models/model-list.command';
1919
import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command';
2020
import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command';
21-
import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command';
21+
import { RunCommand } from './infrastructure/commanders/shortcuts/run.command';
22+
import { InitCudaQuestions } from './infrastructure/commanders/questions/cuda.questions';
23+
import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module';
2224

2325
@Module({
2426
imports: [
@@ -33,15 +35,18 @@ import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.
3335
ChatModule,
3436
ExtensionModule,
3537
HttpModule,
38+
CliUsecasesModule
3639
],
3740
providers: [
38-
BasicCommand,
41+
CortexCommand,
3942
ModelsCommand,
4043
ServeCommand,
4144
ChatCommand,
42-
StartCommand,
4345
InitCommand,
44-
CreateInitQuestions,
46+
47+
// Questions
48+
InitRunModeQuestions,
49+
InitCudaQuestions,
4550

4651
// Model commands
4752
ModelStartCommand,
@@ -50,6 +55,9 @@ import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.
5055
ModelGetCommand,
5156
ModelRemoveCommand,
5257
ModelPullCommand,
58+
59+
// Shortcuts
60+
RunCommand,
5361
],
5462
})
5563
export class CommandModule {}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
export interface HuggingFaceRepoData {
2+
id: string;
3+
modelId: string;
4+
modelUrl?: string;
5+
author: string;
6+
sha: string;
7+
downloads: number;
8+
lastModified: string;
9+
private: boolean;
10+
disabled: boolean;
11+
gated: boolean;
12+
pipeline_tag: 'text-generation';
13+
tags: Array<'transformers' | 'pytorch' | 'safetensors' | string>;
14+
cardData: Record<CardDataKeys | string, unknown>;
15+
siblings: {
16+
rfilename: string;
17+
downloadUrl?: string;
18+
fileSize?: number;
19+
quantization?: Quantization;
20+
stopWord?: string;
21+
}[];
22+
createdAt: string;
23+
}
24+
25+
const CardDataKeys = [
26+
'base_model',
27+
'datasets',
28+
'inference',
29+
'language',
30+
'library_name',
31+
'license',
32+
'model_creator',
33+
'model_name',
34+
'model_type',
35+
'pipeline_tag',
36+
'prompt_template',
37+
'quantized_by',
38+
'tags',
39+
] as const;
40+
export type CardDataKeysTuple = typeof CardDataKeys;
41+
export type CardDataKeys = CardDataKeysTuple[number];
42+
43+
export const AllQuantizations = [
44+
'Q3_K_S',
45+
'Q3_K_M',
46+
'Q3_K_L',
47+
'Q4_K_S',
48+
'Q4_K_M',
49+
'Q5_K_S',
50+
'Q5_K_M',
51+
'Q4_0',
52+
'Q4_1',
53+
'Q5_0',
54+
'Q5_1',
55+
'IQ2_XXS',
56+
'IQ2_XS',
57+
'Q2_K',
58+
'Q2_K_S',
59+
'Q6_K',
60+
'Q8_0',
61+
'F16',
62+
'F32',
63+
'COPY',
64+
];
65+
export type QuantizationsTuple = typeof AllQuantizations;
66+
export type Quantization = QuantizationsTuple[number];

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

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
11
import { ChatUsecases } from '@/usecases/chat/chat.usecases';
2-
import { CommandRunner, SubCommand } from 'nest-commander';
2+
import { CommandRunner, SubCommand, Option } from 'nest-commander';
33
import { ChatCliUsecases } from './usecases/chat.cli.usecases';
4+
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
5+
import { exit } from 'node:process';
46

5-
@SubCommand({ name: 'chat' })
7+
type ChatOptions = {
8+
model?: string;
9+
};
10+
11+
@SubCommand({ name: 'chat', description: 'Start a chat with a model' })
612
export class ChatCommand extends CommandRunner {
7-
constructor(private readonly chatUsecases: ChatUsecases) {
13+
constructor(
14+
private readonly chatUsecases: ChatUsecases,
15+
private readonly cortexUsecases: CortexUsecases,
16+
) {
817
super();
918
}
1019

11-
async run(input: string[]): Promise<void> {
12-
const chatCliService = new ChatCliUsecases(this.chatUsecases);
13-
return chatCliService.run(input);
20+
async run(_input: string[], option: ChatOptions): Promise<void> {
21+
const modelId = option.model;
22+
if (!modelId) {
23+
console.error('Model ID is required');
24+
exit(1);
25+
}
26+
27+
const chatCliUsecases = new ChatCliUsecases(
28+
this.chatUsecases,
29+
this.cortexUsecases,
30+
);
31+
return chatCliUsecases.chat(modelId);
32+
}
33+
34+
@Option({
35+
flags: '--model <model_id>',
36+
description: 'Model Id to start chat with',
37+
})
38+
parseModelId(value: string) {
39+
return value;
1440
}
1541
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { RootCommand, CommandRunner } from 'nest-commander';
2+
import { ServeCommand } from './serve.command';
3+
import { ChatCommand } from './chat.command';
4+
import { ModelsCommand } from './models.command';
5+
import { InitCommand } from './init.command';
6+
import { RunCommand } from './shortcuts/run.command';
7+
8+
@RootCommand({
9+
subCommands: [
10+
ModelsCommand,
11+
ServeCommand,
12+
ChatCommand,
13+
InitCommand,
14+
RunCommand,
15+
],
16+
description: 'Cortex CLI',
17+
})
18+
export class CortexCommand extends CommandRunner {
19+
async run(): Promise<void> {}
20+
}

0 commit comments

Comments
 (0)