Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions cortex-js/src/file-manager/file-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<string> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -395,11 +395,16 @@ export class ModelsCliUsecases {
}

private async parsePreset(preset?: string): Promise<object> {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class ModelParameterParser {
llama_model_path: 'string',
mmproj: 'string',
cont_batching: 'boolean',
pre_prompt: 'string',
};

private modelRuntimeParamTypes: { [key: string]: string } = {
Expand Down