Skip to content

Commit

Permalink
Merge pull request #578 from janhq/chore/remove-start-cortex-cli
Browse files Browse the repository at this point in the history
chore: remove start cortex cli command
  • Loading branch information
louis-jan authored May 16, 2024
2 parents 96bc7c7 + 33d9faa commit 3b0da0f
Show file tree
Hide file tree
Showing 30 changed files with 596 additions and 353 deletions.
Empty file added cortex-js/.env.development
Empty file.
1 change: 0 additions & 1 deletion cortex-js/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
EXTENSIONS_PATH=<EXTENSIONS_PATH>
CORTEX_MODELS_DIR=<CORTEX_MODELS_DIR>
CORTEX_BINARY_PATH=<CORTEX_BINARY_PATH>
1 change: 1 addition & 0 deletions cortex-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"typeorm": "typeorm-ts-node-esm"
},
"dependencies": {
"@huggingface/gguf": "^0.1.5",
"@nestjs/axios": "^3.0.2",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.2",
Expand Down
26 changes: 17 additions & 9 deletions cortex-js/src/command.module.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { Module } from '@nestjs/common';
import { BasicCommand } from './infrastructure/commanders/basic-command.commander';
import { ModelsModule } from './usecases/models/models.module';
import { DatabaseModule } from './infrastructure/database/database.module';
import { ConfigModule } from '@nestjs/config';
import { CortexModule } from './usecases/cortex/cortex.module';
import { ServeCommand } from './infrastructure/commanders/serve.command';
import { ChatCommand } from './infrastructure/commanders/chat.command';
import { ModelsCommand } from './infrastructure/commanders/models.command';
import { StartCommand } from './infrastructure/commanders/start.command';
import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module';
import { ChatModule } from './usecases/chat/chat.module';
import { InitCommand } from './infrastructure/commanders/init.command';
import { HttpModule } from '@nestjs/axios';
import { CreateInitQuestions } from './infrastructure/commanders/inquirer/init.questions';
import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions';
import { ModelListCommand } from './infrastructure/commanders/models/model-list.command';
import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command';
import { CortexCommand } from './infrastructure/commanders/cortex-command.commander';
import { ChatCommand } from './infrastructure/commanders/chat.command';
import { ModelStartCommand } from './infrastructure/commanders/models/model-start.command';
import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command';
import { ModelListCommand } from './infrastructure/commanders/models/model-list.command';
import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command';
import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command';
import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.command';
import { RunCommand } from './infrastructure/commanders/shortcuts/run.command';
import { InitCudaQuestions } from './infrastructure/commanders/questions/cuda.questions';
import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module';

@Module({
imports: [
Expand All @@ -33,15 +35,18 @@ import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.
ChatModule,
ExtensionModule,
HttpModule,
CliUsecasesModule
],
providers: [
BasicCommand,
CortexCommand,
ModelsCommand,
ServeCommand,
ChatCommand,
StartCommand,
InitCommand,
CreateInitQuestions,

// Questions
InitRunModeQuestions,
InitCudaQuestions,

// Model commands
ModelStartCommand,
Expand All @@ -50,6 +55,9 @@ import { ModelPullCommand } from './infrastructure/commanders/models/model-pull.
ModelGetCommand,
ModelRemoveCommand,
ModelPullCommand,

// Shortcuts
RunCommand,
],
})
export class CommandModule {}
66 changes: 66 additions & 0 deletions cortex-js/src/domain/models/huggingface.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
export interface HuggingFaceRepoData {
id: string;
modelId: string;
modelUrl?: string;
author: string;
sha: string;
downloads: number;
lastModified: string;
private: boolean;
disabled: boolean;
gated: boolean;
pipeline_tag: 'text-generation';
tags: Array<'transformers' | 'pytorch' | 'safetensors' | string>;
cardData: Record<CardDataKeys | string, unknown>;
siblings: {
rfilename: string;
downloadUrl?: string;
fileSize?: number;
quantization?: Quantization;
stopWord?: string;
}[];
createdAt: string;
}

const CardDataKeys = [
'base_model',
'datasets',
'inference',
'language',
'library_name',
'license',
'model_creator',
'model_name',
'model_type',
'pipeline_tag',
'prompt_template',
'quantized_by',
'tags',
] as const;
export type CardDataKeysTuple = typeof CardDataKeys;
export type CardDataKeys = CardDataKeysTuple[number];

export const AllQuantizations = [
'Q3_K_S',
'Q3_K_M',
'Q3_K_L',
'Q4_K_S',
'Q4_K_M',
'Q5_K_S',
'Q5_K_M',
'Q4_0',
'Q4_1',
'Q5_0',
'Q5_1',
'IQ2_XXS',
'IQ2_XS',
'Q2_K',
'Q2_K_S',
'Q6_K',
'Q8_0',
'F16',
'F32',
'COPY',
];
export type QuantizationsTuple = typeof AllQuantizations;
export type Quantization = QuantizationsTuple[number];
61 changes: 0 additions & 61 deletions cortex-js/src/infrastructure/commanders/basic-command.commander.ts

This file was deleted.

38 changes: 32 additions & 6 deletions cortex-js/src/infrastructure/commanders/chat.command.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
import { ChatUsecases } from '@/usecases/chat/chat.usecases';
import { CommandRunner, SubCommand } from 'nest-commander';
import { CommandRunner, SubCommand, Option } from 'nest-commander';
import { ChatCliUsecases } from './usecases/chat.cli.usecases';
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
import { exit } from 'node:process';

@SubCommand({ name: 'chat' })
type ChatOptions = {
model?: string;
};

@SubCommand({ name: 'chat', description: 'Start a chat with a model' })
export class ChatCommand extends CommandRunner {
constructor(private readonly chatUsecases: ChatUsecases) {
constructor(
private readonly chatUsecases: ChatUsecases,
private readonly cortexUsecases: CortexUsecases,
) {
super();
}

async run(input: string[]): Promise<void> {
const chatCliService = new ChatCliUsecases(this.chatUsecases);
return chatCliService.run(input);
async run(_input: string[], option: ChatOptions): Promise<void> {
const modelId = option.model;
if (!modelId) {
console.error('Model ID is required');
exit(1);
}

const chatCliUsecases = new ChatCliUsecases(
this.chatUsecases,
this.cortexUsecases,
);
return chatCliUsecases.chat(modelId);
}

@Option({
flags: '--model <model_id>',
description: 'Model Id to start chat with',
})
parseModelId(value: string) {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { RootCommand, CommandRunner } from 'nest-commander';
import { ServeCommand } from './serve.command';
import { ChatCommand } from './chat.command';
import { ModelsCommand } from './models.command';
import { InitCommand } from './init.command';
import { RunCommand } from './shortcuts/run.command';

@RootCommand({
subCommands: [
ModelsCommand,
ServeCommand,
ChatCommand,
InitCommand,
RunCommand,
],
description: 'Cortex CLI',
})
export class CortexCommand extends CommandRunner {
async run(): Promise<void> {}
}
Loading

0 comments on commit 3b0da0f

Please sign in to comment.