From a96e4550a3edb9aedf3ae02beb1b784dc88d3d79 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 6 Jun 2024 20:45:18 +0700 Subject: [PATCH] chore: drop model entity --- .../controllers/models.controller.ts | 6 +- .../database/database.module.ts | 9 +-- .../database/providers/model.providers.ts | 11 ---- .../dtos/models/list-model-response.dto.ts | 2 +- ...ccessfully-created.dto.ts => model.dto.ts} | 7 +++ .../infrastructure/entities/model.entity.ts | 60 ------------------- .../src/usecases/models/models.usecases.ts | 3 +- 7 files changed, 14 insertions(+), 84 deletions(-) delete mode 100644 cortex-js/src/infrastructure/database/providers/model.providers.ts rename cortex-js/src/infrastructure/dtos/models/{model-successfully-created.dto.ts => model.dto.ts} (96%) delete mode 100644 cortex-js/src/infrastructure/entities/model.entity.ts diff --git a/cortex-js/src/infrastructure/controllers/models.controller.ts b/cortex-js/src/infrastructure/controllers/models.controller.ts index 5d6340e1a..b3f5b4ac5 100644 --- a/cortex-js/src/infrastructure/controllers/models.controller.ts +++ b/cortex-js/src/infrastructure/controllers/models.controller.ts @@ -12,7 +12,7 @@ import { import { ModelsUsecases } from '@/usecases/models/models.usecases'; import { CreateModelDto } from '@/infrastructure/dtos/models/create-model.dto'; import { UpdateModelDto } from '@/infrastructure/dtos/models/update-model.dto'; -import { ModelDto } from '@/infrastructure/dtos/models/model-successfully-created.dto'; +import { ModelDto } from '@/infrastructure/dtos/models/model.dto'; import { ListModelsResponseDto } from '@/infrastructure/dtos/models/list-model-response.dto'; import { DeleteModelResponseDto } from '@/infrastructure/dtos/models/delete-model.dto'; import { DownloadModelResponseDto } from '@/infrastructure/dtos/models/download-model.dto'; @@ -120,7 +120,9 @@ export class ModelsController { }) @Get() findAll() { - return this.modelsUsecases.findAll(); + return this.modelsUsecases + .findAll() + .then((data) => data.map((e) => ({ id: e.model, ...e }))); } @HttpCode(200) diff --git a/cortex-js/src/infrastructure/database/database.module.ts b/cortex-js/src/infrastructure/database/database.module.ts index 9a42f47e2..6ff802705 100644 --- a/cortex-js/src/infrastructure/database/database.module.ts +++ b/cortex-js/src/infrastructure/database/database.module.ts @@ -1,7 +1,6 @@ import { Module } from '@nestjs/common'; import { threadProviders } from './providers/thread.providers'; import { sqliteDatabaseProviders } from './sqlite-database.providers'; -import { modelProviders } from './providers/model.providers'; import { assistantProviders } from './providers/assistant.providers'; import { messageProviders } from './providers/message.providers'; import { FileManagerModule } from '@/file-manager/file-manager.module'; @@ -11,15 +10,9 @@ import { FileManagerModule } from '@/file-manager/file-manager.module'; providers: [ ...sqliteDatabaseProviders, ...threadProviders, - ...modelProviders, - ...assistantProviders, - ...messageProviders, - ], - exports: [ - ...threadProviders, - ...modelProviders, ...assistantProviders, ...messageProviders, ], + exports: [...threadProviders, ...assistantProviders, ...messageProviders], }) export class DatabaseModule {} diff --git a/cortex-js/src/infrastructure/database/providers/model.providers.ts b/cortex-js/src/infrastructure/database/providers/model.providers.ts deleted file mode 100644 index 30dcf2645..000000000 --- a/cortex-js/src/infrastructure/database/providers/model.providers.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { ModelEntity } from '@/infrastructure/entities/model.entity'; -import { DataSource } from 'typeorm'; - -export const modelProviders = [ - { - provide: 'MODEL_REPOSITORY', - useFactory: (dataSource: DataSource) => - dataSource.getRepository(ModelEntity), - inject: ['DATA_SOURCE'], - }, -]; diff --git a/cortex-js/src/infrastructure/dtos/models/list-model-response.dto.ts b/cortex-js/src/infrastructure/dtos/models/list-model-response.dto.ts index 4b861746b..ed4c1e98d 100644 --- a/cortex-js/src/infrastructure/dtos/models/list-model-response.dto.ts +++ b/cortex-js/src/infrastructure/dtos/models/list-model-response.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { ModelDto } from './model-successfully-created.dto'; // Import the ModelDto class +import { ModelDto } from './model.dto'; // Import the ModelDto class export class ListModelsResponseDto { @ApiProperty({ example: 'list', enum: ['list'] }) diff --git a/cortex-js/src/infrastructure/dtos/models/model-successfully-created.dto.ts b/cortex-js/src/infrastructure/dtos/models/model.dto.ts similarity index 96% rename from cortex-js/src/infrastructure/dtos/models/model-successfully-created.dto.ts rename to cortex-js/src/infrastructure/dtos/models/model.dto.ts index 97ab21617..003f602ce 100644 --- a/cortex-js/src/infrastructure/dtos/models/model-successfully-created.dto.ts +++ b/cortex-js/src/infrastructure/dtos/models/model.dto.ts @@ -3,6 +3,13 @@ import { ApiProperty } from '@nestjs/swagger'; import { IsArray, IsBoolean, IsNumber, IsOptional } from 'class-validator'; export class ModelDto implements Partial { + @ApiProperty({ + example: 'llama3', + description: 'Model ID', + }) + @IsOptional() + id: string; + // Prompt Settings @ApiProperty({ example: 'system\n{system_message}\nuser\n{prompt}\nassistant', diff --git a/cortex-js/src/infrastructure/entities/model.entity.ts b/cortex-js/src/infrastructure/entities/model.entity.ts deleted file mode 100644 index 052eb7d22..000000000 --- a/cortex-js/src/infrastructure/entities/model.entity.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { Model, ModelArtifact } from '@/domain/models/model.interface'; -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('models') -export class ModelEntity implements Model { - // Cortex Meta - @PrimaryColumn() - model: string; - - @Column() - name: string; - - @Column() - version: string; - - @Column({ type: 'simple-json' }) - files: string[] | ModelArtifact; - - // Model Input / Output Syntax - @Column() - prompt_template: string; - - @Column({ type: 'simple-json' }) - stop: string[]; - - @Column() - max_tokens: number; - - // Results Preferences - @Column() - top_p: number; - - @Column() - temperature: number; - - @Column() - frequency_penalty: number; - - @Column() - presence_penalty: number; - - @Column() - stream: boolean; - - // Engine Settings - @Column() - ctx_len: number; - - @Column() - ngl: number; - - @Column() - n_parallel: number; - - @Column() - cpu_threads: number; - - @Column() - engine: string; -} diff --git a/cortex-js/src/usecases/models/models.usecases.ts b/cortex-js/src/usecases/models/models.usecases.ts index 925101745..b7793d9d5 100644 --- a/cortex-js/src/usecases/models/models.usecases.ts +++ b/cortex-js/src/usecases/models/models.usecases.ts @@ -20,7 +20,6 @@ import { firstValueFrom } from 'rxjs'; import { FileManagerService } from '@/file-manager/file-manager.service'; import { AxiosError } from 'axios'; import { ModelRepository } from '@/domain/repositories/model.interface'; -import { ModelDto } from '@/infrastructure/dtos/models/model-successfully-created.dto'; import { ModelParameterParser } from '@/infrastructure/commanders/utils/model-parameter.parser'; @Injectable() @@ -81,7 +80,7 @@ export class ModelsUsecases { async startModel( modelId: string, - settings?: ModelDto, + settings?: ModelSettingParams, ): Promise { const model = await this.getModelOrThrow(modelId); const extensions = (await this.extensionRepository.findAll()) ?? [];