fix: Update nitro with read/ write for engine.json
This commit is contained in:
parent
1bc5fe64f3
commit
2c648caa5f
@ -26,6 +26,13 @@ import { requestInference } from "./helpers/sse";
|
|||||||
import { ulid } from "ulid";
|
import { ulid } from "ulid";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
|
interface EngineSettings {
|
||||||
|
ctx_len: number;
|
||||||
|
ngl: number;
|
||||||
|
cont_batching: boolean;
|
||||||
|
embedding: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that implements the InferenceExtension interface from the @janhq/core package.
|
* A class that implements the InferenceExtension interface from the @janhq/core package.
|
||||||
* The class provides methods for initializing and stopping a model, and for making inference requests.
|
* The class provides methods for initializing and stopping a model, and for making inference requests.
|
||||||
@ -35,6 +42,13 @@ export default class JanInferenceNitroExtension implements InferenceExtension {
|
|||||||
private static readonly _homeDir = 'engines'
|
private static readonly _homeDir = 'engines'
|
||||||
private static readonly _engineMetadataFileName = 'nitro.json'
|
private static readonly _engineMetadataFileName = 'nitro.json'
|
||||||
|
|
||||||
|
private _engineSettings: EngineSettings = {
|
||||||
|
"ctx_len": 2048,
|
||||||
|
"ngl": 100,
|
||||||
|
"cont_batching": false,
|
||||||
|
"embedding": false
|
||||||
|
}
|
||||||
|
|
||||||
controller = new AbortController();
|
controller = new AbortController();
|
||||||
isCancelled = false;
|
isCancelled = false;
|
||||||
/**
|
/**
|
||||||
@ -100,21 +114,13 @@ export default class JanInferenceNitroExtension implements InferenceExtension {
|
|||||||
|
|
||||||
private async writeDefaultEngineSettings() {
|
private async writeDefaultEngineSettings() {
|
||||||
try {
|
try {
|
||||||
const destPath = join(JanInferenceNitroExtension._homeDir, JanInferenceNitroExtension._engineMetadataFileName)
|
const engine_json = join(JanInferenceNitroExtension._homeDir, JanInferenceNitroExtension._engineMetadataFileName)
|
||||||
// TODO: Check with @louis for adding new binding
|
if (await fs.checkFileExists(engine_json)) {
|
||||||
// if (await fs.checkFileExists(destPath)) {
|
this._engineSettings = JSON.parse(await fs.readFile(engine_json))
|
||||||
const default_engine_settings = {
|
}
|
||||||
"ctx_len": 2048,
|
else {
|
||||||
"ngl": 100,
|
await fs.writeFile(engine_json, JSON.stringify(this._engineSettings, null, 2))
|
||||||
"cont_batching": false,
|
|
||||||
"embedding": false
|
|
||||||
}
|
}
|
||||||
console.log(`Writing nitro engine settings to ${destPath}`)
|
|
||||||
await fs.writeFile(destPath, JSON.stringify(default_engine_settings, null, 2))
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// console.log(`Using existing nitro engine settings at ${destPath}`)
|
|
||||||
// }
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,9 @@ interface InitModelResponse {
|
|||||||
* TODO: Should it be startModel instead?
|
* TODO: Should it be startModel instead?
|
||||||
*/
|
*/
|
||||||
function initModel(wrapper: any): Promise<InitModelResponse> {
|
function initModel(wrapper: any): Promise<InitModelResponse> {
|
||||||
|
if (wrapper.settings.engine !== "llamacpp") {
|
||||||
|
return
|
||||||
|
}
|
||||||
// 1. Check if the model file exists
|
// 1. Check if the model file exists
|
||||||
currentModelFile = wrapper.modelFullPath;
|
currentModelFile = wrapper.modelFullPath;
|
||||||
log.info("Started to load model " + wrapper.modelFullPath);
|
log.info("Started to load model " + wrapper.modelFullPath);
|
||||||
@ -45,7 +48,6 @@ function initModel(wrapper: any): Promise<InitModelResponse> {
|
|||||||
...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 (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user