Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Jul 30, 2024
1 parent d0dec36 commit 4de62ef
Show file tree
Hide file tree
Showing 32 changed files with 291 additions and 213 deletions.
14 changes: 7 additions & 7 deletions cortex-js/src/infrastructure/commanders/chat.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class ChatCommand extends BaseCommand {
) {
console.log('Downloading engine...');
await this.cortex.engines.init(engine);
await downloadProgress(this.cortex, undefined, DownloadType.Engine)
await downloadProgress(this.cortex, undefined, DownloadType.Engine);
}

if (!message) options.attach = true;
Expand All @@ -108,13 +108,13 @@ export class ChatCommand extends BaseCommand {
);

const preset = await this.fileService.getPreset(options.preset);

return this.chatClient.chat(
modelId,
options.threadId,
message, // Accept both message from inputs or arguments
preset ? preset : {},
)
modelId,
options.threadId,
message, // Accept both message from inputs or arguments
preset ? preset : {},
);
}

modelInquiry = async (models: Cortex.Model[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ export class CortexCommand extends CommandRunner {
return this.startServer(showLogs, dataFolderPath);
}

private async startServer(
attach: boolean,
dataFolderPath?: string,
) {
private async startServer(attach: boolean, dataFolderPath?: string) {
const config = await this.fileManagerService.getConfig();
try {
const startEngineSpinner = ora('Starting Cortex engine...');
Expand Down Expand Up @@ -119,9 +116,13 @@ export class CortexCommand extends CommandRunner {
} else {
await this.cortexUseCases.startServerDetached(this.host, this.port);
}
console.log(chalk.blue(`Started server at http://${this.host}:${this.port}`));
console.log(
chalk.blue(`API Playground available at http://${this.host}:${this.port}/api`),
chalk.blue(`Started server at http://${this.host}:${this.port}`),
);
console.log(
chalk.blue(
`API Playground available at http://${this.host}:${this.port}/api`,
),
);
await this.fileManagerService.writeConfigFile({
...config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ export class ChatClient {
});

rl.on('line', (input) =>
this.sendCompletionMessage(input, messages, modelId, thread.id, rl, settings),
this.sendCompletionMessage(
input,
messages,
modelId,
thread.id,
rl,
settings,
),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ describe('Helper commands', () => {
'Show stop running models',
async () => {
// const tableMock = stubMethod(console, 'table');

// const logMock = stubMethod(console, 'log');
// await CommandTestFactory.run(commandInstance, ['stop']);
// await CommandTestFactory.run(commandInstance, ['ps']);

// expect(logMock.firstCall?.args[0]).toEqual('API server stopped');
// expect(tableMock.firstCall?.args[0]).toBeInstanceOf(Array);
// expect(tableMock.firstCall?.args[0].length).toEqual(0);
Expand All @@ -114,7 +112,6 @@ describe('Helper commands', () => {
// expect(stdoutSpy.firstCall?.args).toBeInstanceOf(Array);
// expect(stdoutSpy.firstCall?.args.length).toBe(1);
// expect(stdoutSpy.firstCall?.args[0]).toContain('display help for command');

// expect(exitSpy.callCount).toBeGreaterThan(1);
// expect(exitSpy.firstCall?.args[0]).toBe(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export interface ModelMetadata {
stopWord?: string;
promptTemplate: string;
version: number;
name?: string
name?: string;
}
2 changes: 1 addition & 1 deletion cortex-js/src/infrastructure/constants/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const defaultBenchmarkConfiguration: BenchmarkConfig = {
min: 1024,
max: 2048,
samples: 10,
},
},
output: 'table',
hardware: ['cpu', 'gpu', 'psu', 'chassis', 'ram'],
concurrency: 1,
Expand Down
20 changes: 12 additions & 8 deletions cortex-js/src/infrastructure/controllers/engines.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,19 @@ export class EnginesController {
description: 'The unique identifier of the engine.',
})
@Post(':name(*)/init')
initialize(@Param('name') name: string, @Body() body: InitEngineDto | undefined, @Res() res: Response) {
try{
this.initUsescases.installEngine(body, name, true);
res.json({
initialize(
@Param('name') name: string,
@Body() body: InitEngineDto | undefined,
@Res() res: Response,
) {
try {
this.initUsescases.installEngine(body, name, true);
res.json({
message: 'Engine initialization started successfully.',
})
} catch (error) {
res.status(400).send(error.message);
}
});
} catch (error) {
res.status(400).send(error.message);
}
}

@HttpCode(200)
Expand Down
5 changes: 3 additions & 2 deletions cortex-js/src/infrastructure/controllers/models.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ export class ModelsController {
@Post(':modelId(*)/pull')
pullModel(
@Param('modelId') modelId: string,
@Body() body?: {
@Body()
body?: {
fileName?: string;
persistedModelId?: string;
}
},
) {
const { fileName, persistedModelId } = body || {};
this.modelsUsecases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class SystemController {
}

@ApiOperation({
summary: "Get health status",
summary: 'Get health status',
description: "Retrieves the health status of your Cortex's system.",
})
@HttpCode(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Sequelize } from 'sequelize-typescript';
export const assistantProviders = [
{
provide: 'ASSISTANT_REPOSITORY',
useFactory: async(sequelize: Sequelize) =>{
useFactory: async (sequelize: Sequelize) => {
return sequelize.getRepository(AssistantEntity);
},
inject: ['DATA_SOURCE'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MessageEntity } from "@/infrastructure/entities/message.entity";
import { Sequelize } from "sequelize-typescript";
import { MessageEntity } from '@/infrastructure/entities/message.entity';
import { Sequelize } from 'sequelize-typescript';

export const messageProviders = [
{
provide: 'MESSAGE_REPOSITORY',
useFactory: async(sequelize: Sequelize) =>{
useFactory: async (sequelize: Sequelize) => {
return sequelize.getRepository(MessageEntity);
},
inject: ['DATA_SOURCE'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { Sequelize } from 'sequelize-typescript';
export const threadProviders = [
{
provide: 'THREAD_REPOSITORY',
useFactory: async(sequelize: Sequelize) =>{
useFactory: async (sequelize: Sequelize) => {
return sequelize.getRepository(ThreadEntity);
},
inject: ['DATA_SOURCE'],
},
];

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class ChatCompletionMessage {
@ApiProperty({ description: 'The Content of the chat message.', })
@ApiProperty({ description: 'The Content of the chat message.' })
@IsString()
content: string;

@ApiProperty({
description: 'The role of the entity in the chat completion.',
example: 'user'
example: 'user',
})
role: 'user' | 'assistant';
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CreateChatCompletionDto {
@ApiProperty({
description:
'Determines the format for output generation. If set to `true`, the output is generated continuously, allowing for real-time streaming of responses. If set to `false`, the output is delivered in a single JSON file.',
example: true,
example: true,
})
@IsOptional()
@IsBoolean()
Expand All @@ -39,7 +39,7 @@ export class CreateChatCompletionDto {
@ApiProperty({
description:
'Sets the upper limit on the number of tokens the model can generate in a single output.',
example: 4096,
example: 4096,
})
@IsOptional()
@IsNumber()
Expand All @@ -48,7 +48,7 @@ export class CreateChatCompletionDto {
@ApiProperty({
description:
'Defines specific tokens or phrases that signal the model to stop producing further output.',
example: ["End"],
example: ['End'],
})
@IsOptional()
@IsArray()
Expand All @@ -57,7 +57,7 @@ export class CreateChatCompletionDto {
@ApiProperty({
description:
'Modifies the likelihood of the model repeating the same words or phrases within a single output.',
example: 0.2,
example: 0.2,
})
@IsOptional()
@IsNumber()
Expand All @@ -66,7 +66,7 @@ export class CreateChatCompletionDto {
@ApiProperty({
description:
'Reduces the likelihood of repeating tokens, promoting novelty in the output.',
example: 0.6,
example: 0.6,
})
@IsOptional()
@IsNumber()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ export class EmbeddingsResponseDto {
model: string;

@ApiProperty({
description: 'The embedding vector represented as an array of floating-point numbers. ',
description:
'The embedding vector represented as an array of floating-point numbers. ',
type: [Number],
})
embedding: [number];

@ApiProperty({
description: 'Details of token usage, including prompt_tokens and total_tokens.',
description:
'Details of token usage, including prompt_tokens and total_tokens.',
type: UsageDto,
})
usage: UsageDto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class CreateMessageDto implements Partial<Message> {
example: [
{
type: 'text',
data: 'Hello, how can I help you today?'
}
data: 'Hello, how can I help you today?',
},
],
description: 'The content of the messages.',
})
Expand All @@ -44,7 +44,8 @@ export class CreateMessageDto implements Partial<Message> {

@ApiProperty({
example: { urgency: 'high', tags: ['customer_support'] },
description: 'Optional dictionary for additional unstructured message information.',
description:
'Optional dictionary for additional unstructured message information.',
})
metadata?: Record<string, unknown>;

Expand All @@ -55,4 +56,3 @@ export class CreateMessageDto implements Partial<Message> {
@IsString()
type?: string;
}

31 changes: 21 additions & 10 deletions cortex-js/src/infrastructure/dtos/models/create-model.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { ApiProperty, getSchemaPath } from '@nestjs/swagger';

export class CreateModelDto implements Partial<Model> {
// Cortex Meta
@ApiProperty({ description: 'The unique identifier of the model.', example: 'mistral' })
@ApiProperty({
description: 'The unique identifier of the model.',
example: 'mistral',
})
@IsString()
model: string;

Expand All @@ -21,7 +24,8 @@ export class CreateModelDto implements Partial<Model> {
name?: string;

@ApiProperty({
description: 'The URL sources from which the model downloaded or accessed.', example: ['https://huggingface.co/cortexso/mistral/tree/gguf'],
description: 'The URL sources from which the model downloaded or accessed.',
example: ['https://huggingface.co/cortexso/mistral/tree/gguf'],
oneOf: [
{ type: 'array', items: { type: 'string' } },
{ $ref: getSchemaPath(ModelArtifactDto) },
Expand All @@ -33,16 +37,18 @@ export class CreateModelDto implements Partial<Model> {
// Model Input / Output Syntax
@ApiProperty({
description:
"A predefined text or framework that guides the AI model's response generation.", example: `
You are an expert in {subject}. Provide a detailed and thorough explanation on the topic of {topic}.`
"A predefined text or framework that guides the AI model's response generation.",
example: `
You are an expert in {subject}. Provide a detailed and thorough explanation on the topic of {topic}.`,
})
@IsOptional()
@IsString()
prompt_template?: string;

@ApiProperty({
description:
'Defines specific tokens or phrases that signal the model to stop producing further output.', example: ['End']
'Defines specific tokens or phrases that signal the model to stop producing further output.',
example: ['End'],
})
@IsOptional()
@IsArray()
Expand All @@ -59,38 +65,43 @@ export class CreateModelDto implements Partial<Model> {
max_tokens?: number;

@ApiProperty({
description: 'Sets probability threshold for more relevant outputs.', example: 0.9
description: 'Sets probability threshold for more relevant outputs.',
example: 0.9,
})
@IsOptional()
@IsNumber()
top_p?: number;

@ApiProperty({
description: "Influences the randomness of the model's output.", example: 0.7
description: "Influences the randomness of the model's output.",
example: 0.7,
})
@IsOptional()
@IsNumber()
temperature?: number;

@ApiProperty({
description:
'Modifies the likelihood of the model repeating the same words or phrases within a single output.', example: 0.5
'Modifies the likelihood of the model repeating the same words or phrases within a single output.',
example: 0.5,
})
@IsOptional()
@IsNumber()
frequency_penalty?: number;

@ApiProperty({
description:
'Reduces the likelihood of repeating tokens, promoting novelty in the output.', example: 0.6
'Reduces the likelihood of repeating tokens, promoting novelty in the output.',
example: 0.6,
})
@IsOptional()
@IsNumber()
presence_penalty?: number;

@ApiProperty({
description:
'Determines the format for output generation. If set to `true`, the output is generated continuously, allowing for real-time streaming of responses. If set to `false`, the output is delivered in a single JSON file.', example: true
'Determines the format for output generation. If set to `true`, the output is generated continuously, allowing for real-time streaming of responses. If set to `false`, the output is delivered in a single JSON file.',
example: true,
})
@IsOptional()
@IsBoolean()
Expand Down
Loading

0 comments on commit 4de62ef

Please sign in to comment.