Skip to content

Commit

Permalink
fix: add pre_prompt to engine settings (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan authored Jun 6, 2024
1 parent 31f5e14 commit ecc95c7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
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

0 comments on commit ecc95c7

Please sign in to comment.