Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change init engine syntax #889

Merged
merged 7 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 37 additions & 3 deletions cortex-js/src/infrastructure/commanders/engines.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,53 @@ import { ContextService } from '@/infrastructure/services/context/context.servic
import { EnginesListCommand } from './engines/engines-list.command';
import { EnginesGetCommand } from './engines/engines-get.command';
import { EnginesInitCommand } from './engines/engines-init.command';
import { ModuleRef } from '@nestjs/core';
import { EngineNamesMap } from './types/engine.interface';
import _ from 'lodash';
marknguyen1302 marked this conversation as resolved.
Show resolved Hide resolved

@SubCommand({
name: 'engines',
subCommands: [EnginesListCommand, EnginesGetCommand, EnginesInitCommand],
description: 'Get cortex engines',
arguments: '<command|parameter> [subcommand]',
})
@SetCommandContext()
export class EnginesCommand extends CommandRunner {
constructor(readonly contextService: ContextService) {
commandMap: { [key: string]: any } = {
list: EnginesListCommand,
get: EnginesGetCommand,
init: EnginesInitCommand,
};

constructor(
readonly contextService: ContextService,
private readonly moduleRef: ModuleRef,
) {
super();
}
async run(passedParam: string[]): Promise<void> {
const [parameter, command] = passedParam;
if (command !== 'list' && !parameter) {
console.error('Engine name is required.');
return;
}

// Handle the commands accordingly
const commandClass = this.commandMap[command as string];
if (!commandClass) {
this.command?.help();
return;
}
const engine = _.invert(EngineNamesMap)[parameter] || parameter;
await this.runCommand(commandClass, [engine]);
}

async run(): Promise<void> {
this.command?.help();
private async runCommand(commandClass: any, params: string[] = []) {
const commandInstance = this.moduleRef.get(commandClass, { strict: false });
if (commandInstance) {
await commandInstance.run(params);
} else {
console.error('Command not found.');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { ContextService } from '@/infrastructure/services/context/context.servic
import { EnginesUsecases } from '@/usecases/engines/engines.usecase';

@SubCommand({
name: 'get',
name: '<name> get',
description: 'Get an engine',
arguments: '<name>',
argsDescription: {
name: 'Engine name to get',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
import { FileManagerService } from '@/infrastructure/services/file-manager/file-manager.service';

@SubCommand({
name: 'init',
name: '<name> init',
description: 'Setup engine',
arguments: '<name>',
argsDescription: {
name: 'Engine name to setup',
},
Expand Down Expand Up @@ -49,7 +48,7 @@ export class EnginesInitCommand extends CommandRunner {
params,
engine.includes('@') ? engine.split('@')[1] : 'latest',
engine,
true
true,
)
.then(() => console.log('Engine installed successfully!'))
.catch((e) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CommandRunner, SubCommand } from 'nest-commander';
import { SetCommandContext } from '../decorators/CommandContext';
import { ContextService } from '@/infrastructure/services/context/context.service';
import { EnginesUsecases } from '@/usecases/engines/engines.usecase';
import { EngineNamesMap, Engines } from '../types/engine.interface';

@SubCommand({
name: 'list',
Expand All @@ -17,6 +18,12 @@ export class EnginesListCommand extends CommandRunner {
}

async run(): Promise<void> {
return this.enginesUsecases.getEngines().then(console.table);
return this.enginesUsecases.getEngines().then((engines) => {
const enginesTable = engines.map((engine) => ({
...engine,
name: EngineNamesMap[engine.name as Engines],
}));
console.table(enginesTable);
});
}
}
10 changes: 10 additions & 0 deletions cortex-js/src/infrastructure/commanders/types/engine.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ export enum Engines {
openai = 'openai',
anthropic = 'anthropic',
}

export const EngineNamesMap = {
[Engines.llamaCPP]: 'llamacpp',
[Engines.onnx]: 'onnx',
[Engines.tensorrtLLM]: 'tensorrtLLM',
[Engines.groq]: 'groq',
[Engines.mistral]: 'mistral',
[Engines.openai]: 'openai',
[Engines.anthropic]: 'anthropic',
};
3 changes: 1 addition & 2 deletions cortex-js/src/infrastructure/dtos/engines/engines.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export class EngineDto implements Partial<Extension> {
@ApiProperty({
type: String,
example: 'cortex.llamacpp',
description:
'The name of the engine that you want to retrieve.',
description: 'The name of the engine that you want to retrieve.',
})
@IsString()
name: string;
Expand Down
5 changes: 3 additions & 2 deletions cortex-js/src/infrastructure/dtos/models/model.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ModelDto implements Partial<Model> {

@ApiProperty({
type: [String],
example: ["End"],
example: ['End'],
description:
'Defines specific tokens or phrases that signal the model to stop producing further output.',
})
Expand Down Expand Up @@ -116,7 +116,8 @@ export class ModelDto implements Partial<Model> {

@ApiProperty({
description: 'The prompt to use for internal configuration',
example: "You are an assistant with expert knowledge in {subject}. Please provide a detailed and accurate response to the following query: {query}. Ensure that your response is clear, concise, and informative."
example:
'You are an assistant with expert knowledge in {subject}. Please provide a detailed and accurate response to the following query: {query}. Ensure that your response is clear, concise, and informative.',
})
@IsOptional()
@IsString()
Expand Down
Loading