diff --git a/cortex-js/src/file-manager/file-manager.service.ts b/cortex-js/src/file-manager/file-manager.service.ts index 62431b98b..4d838db6f 100644 --- a/cortex-js/src/file-manager/file-manager.service.ts +++ b/cortex-js/src/file-manager/file-manager.service.ts @@ -10,6 +10,7 @@ export class FileManagerService { private configFile = '.cortexrc'; private cortexDirectoryName = 'cortex'; private modelFolderName = 'models'; + private presetFolderName = 'presets'; private extensionFoldername = 'extensions'; private cortexCppFolderName = 'cortex-cpp'; @@ -96,6 +97,16 @@ export class FileManagerService { return join(dataFolderPath, this.modelFolderName); } + /** + * Get the presets data folder path + * Usually it is located at the home directory > cortex > presets + * @returns the path to the presets folder + */ + async getPresetsPath(): Promise { + const dataFolderPath = await this.getDataFolderPath(); + return join(dataFolderPath, this.presetFolderName); + } + /** * Get the extensions data folder path * Usually it is located at the home directory > cortex > extensions diff --git a/cortex-js/src/infrastructure/commanders/usecases/models.cli.usecases.ts b/cortex-js/src/infrastructure/commanders/usecases/models.cli.usecases.ts index f4a40d2bd..df60ad0c0 100644 --- a/cortex-js/src/infrastructure/commanders/usecases/models.cli.usecases.ts +++ b/cortex-js/src/infrastructure/commanders/usecases/models.cli.usecases.ts @@ -27,7 +27,7 @@ import { UpdateModelDto } from '@/infrastructure/dtos/models/update-model.dto'; import { FileManagerService } from '@/file-manager/file-manager.service'; import { join, basename } from 'path'; import { load } from 'js-yaml'; -import { existsSync, readFileSync } from 'fs'; +import { existsSync, readdirSync, readFileSync } from 'fs'; import { isLocalModel, normalizeModelId } from '../utils/normalize-model-id'; import { HUGGING_FACE_DOWNLOAD_FILE_MAIN_URL, @@ -395,11 +395,16 @@ export class ModelsCliUsecases { } private async parsePreset(preset?: string): Promise { - const presetPath = join( - await this.fileService.getDataFolderPath(), - 'presets', - `${preset}.yaml`, + const presetsFolder = await this.fileService.getPresetsPath(); + + const presetFile = readdirSync(presetsFolder).find( + (file) => + file.toLowerCase() === `${preset?.toLowerCase()}.yaml` || + file.toLowerCase() === `${preset?.toLocaleLowerCase()}.yml`, ); + if (!presetFile) throw new Error(`Preset ${preset} not found`); + const presetPath = join(presetsFolder, presetFile); + if (!preset || !existsSync(presetPath)) return {}; return preset ? (load(readFileSync(join(presetPath), 'utf-8')) as object) diff --git a/cortex-js/src/infrastructure/commanders/utils/model-parameter.parser.ts b/cortex-js/src/infrastructure/commanders/utils/model-parameter.parser.ts index 7ea02e847..ad8136d6a 100644 --- a/cortex-js/src/infrastructure/commanders/utils/model-parameter.parser.ts +++ b/cortex-js/src/infrastructure/commanders/utils/model-parameter.parser.ts @@ -15,6 +15,7 @@ export class ModelParameterParser { llama_model_path: 'string', mmproj: 'string', cont_batching: 'boolean', + pre_prompt: 'string', }; private modelRuntimeParamTypes: { [key: string]: string } = {