fix: Add fs to read and write nitro engine settings

This commit is contained in:
hiro 2023-12-01 18:14:13 +07:00
parent 19637c40bf
commit 337da50840
2 changed files with 14 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import {
events, events,
executeOnMain, executeOnMain,
getUserSpace, getUserSpace,
fs
} from "@janhq/core"; } from "@janhq/core";
import { InferenceExtension } from "@janhq/core"; import { InferenceExtension } from "@janhq/core";
import { requestInference } from "./helpers/sse"; import { requestInference } from "./helpers/sse";
@ -31,6 +32,9 @@ import { join } from "path";
* It also subscribes to events emitted by the @janhq/core package and handles new message requests. * It also subscribes to events emitted by the @janhq/core package and handles new message requests.
*/ */
export default class JanInferenceExtension implements InferenceExtension { export default class JanInferenceExtension implements InferenceExtension {
private static readonly _homeDir = 'engines'
private static readonly _engineMetadataFileName = 'nitro.json'
controller = new AbortController(); controller = new AbortController();
isCancelled = false; isCancelled = false;
/** /**
@ -45,6 +49,8 @@ export default class JanInferenceExtension implements InferenceExtension {
* Subscribes to events emitted by the @janhq/core package. * Subscribes to events emitted by the @janhq/core package.
*/ */
onLoad(): void { onLoad(): void {
fs.mkdir(JanInferenceExtension._homeDir)
events.on(EventName.OnMessageSent, (data) => events.on(EventName.OnMessageSent, (data) =>
JanInferenceExtension.handleMessageRequest(data, this) JanInferenceExtension.handleMessageRequest(data, this)
); );
@ -68,10 +74,14 @@ export default class JanInferenceExtension implements InferenceExtension {
): Promise<void> { ): Promise<void> {
const userSpacePath = await getUserSpace(); const userSpacePath = await getUserSpace();
const modelFullPath = join(userSpacePath, "models", modelId, modelId); const modelFullPath = join(userSpacePath, "models", modelId, modelId);
let engine_settings = JSON.parse(await fs.readFile(join(JanInferenceExtension._homeDir, JanInferenceExtension._engineMetadataFileName)))
engine_settings = {
engine_settings
...settings,
};
return executeOnMain(MODULE, "initModel", { return executeOnMain(MODULE, "initModel", {
modelFullPath, modelFullPath,
settings, engine_settings,
}); });
} }

View File

@ -42,12 +42,10 @@ function initModel(wrapper: any): Promise<InitModelResponse> {
const settings = { const settings = {
llama_model_path: currentModelFile, llama_model_path: currentModelFile,
ctx_len: 2048,
ngl: 100,
cont_batching: false,
embedding: false, // Always enable embedding mode on
...wrapper.settings, ...wrapper.settings,
}; };
log.info(`Load model settings: ${JSON.stringify(settings, null, 2)}`); log.info(`Load model settings: ${JSON.stringify(settings, null, 2)}`);
return ( return (