fix: Add fs to read and write nitro engine settings
This commit is contained in:
parent
19637c40bf
commit
337da50840
@ -19,6 +19,7 @@ import {
|
||||
events,
|
||||
executeOnMain,
|
||||
getUserSpace,
|
||||
fs
|
||||
} from "@janhq/core";
|
||||
import { InferenceExtension } from "@janhq/core";
|
||||
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.
|
||||
*/
|
||||
export default class JanInferenceExtension implements InferenceExtension {
|
||||
private static readonly _homeDir = 'engines'
|
||||
private static readonly _engineMetadataFileName = 'nitro.json'
|
||||
|
||||
controller = new AbortController();
|
||||
isCancelled = false;
|
||||
/**
|
||||
@ -45,6 +49,8 @@ export default class JanInferenceExtension implements InferenceExtension {
|
||||
* Subscribes to events emitted by the @janhq/core package.
|
||||
*/
|
||||
onLoad(): void {
|
||||
fs.mkdir(JanInferenceExtension._homeDir)
|
||||
|
||||
events.on(EventName.OnMessageSent, (data) =>
|
||||
JanInferenceExtension.handleMessageRequest(data, this)
|
||||
);
|
||||
@ -68,10 +74,14 @@ export default class JanInferenceExtension implements InferenceExtension {
|
||||
): Promise<void> {
|
||||
const userSpacePath = await getUserSpace();
|
||||
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", {
|
||||
modelFullPath,
|
||||
settings,
|
||||
engine_settings,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -42,12 +42,10 @@ function initModel(wrapper: any): Promise<InitModelResponse> {
|
||||
|
||||
const settings = {
|
||||
llama_model_path: currentModelFile,
|
||||
ctx_len: 2048,
|
||||
ngl: 100,
|
||||
cont_batching: false,
|
||||
embedding: false, // Always enable embedding mode on
|
||||
...wrapper.settings,
|
||||
};
|
||||
|
||||
|
||||
log.info(`Load model settings: ${JSON.stringify(settings, null, 2)}`);
|
||||
|
||||
return (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user