Skip to content

Commit

Permalink
release version 0.2.0 (#44)
Browse files Browse the repository at this point in the history
* add preloader folder

Signed-off-by: cbh778899 <[email protected]>

* set model path to userPath after packaged

Signed-off-by: cbh778899 <[email protected]>

* update version to 0.2.0

Signed-off-by: cbh778899 <[email protected]>

---------

Signed-off-by: cbh778899 <[email protected]>
  • Loading branch information
cbh778899 authored Oct 15, 2024
1 parent 2380db3 commit 7a7bc71
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ directories:

files:
- dist/**/* # Include everything in the dist folder generated by Vite
- preloader/**/*
# - node_modules/**/* # Include necessary node modules
# - package.json
- electron.js
Expand Down
6 changes: 5 additions & 1 deletion electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function createWindow() {
if(app.isPackaged) {
// eslint-disable-next-line
win.loadFile(path.join(__dirname, 'dist/index.html'))
Menu.setApplicationMenu(null);
// Menu.setApplicationMenu(null);
} else {
win.loadURL("http://localhost:3000");
}
Expand All @@ -46,3 +46,7 @@ app.whenReady().then(() => {
BrowserWindow.getAllWindows().length === 0 && createWindow()
})
})

ipcMain.handle('electron-settings', ()=>{
return { userDataPath: app.getPath("userData"), isPackaged: app.isPackaged }
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Bohan Cheng",
"email": "[email protected]"
},
"version": "0.1.12",
"version": "0.2.0",
"main": "electron.js",
"scripts": {
"dev": "npm run start & npm run electron",
Expand Down
24 changes: 14 additions & 10 deletions preloader/node-llama-cpp-preloader.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
const { createWriteStream, existsSync, statSync } = require("fs");
const { ipcRenderer } = require("electron");
const { createWriteStream, existsSync, statSync, mkdirSync } = require("fs");
const path = require("path");

let llama, getLlama, LlamaChatSession, current_model;

async function importer() {
let model_path = '';
async function initer() {
const nodeLlamaCpp = await import('node-llama-cpp')
getLlama = nodeLlamaCpp.getLlama;
LlamaChatSession = nodeLlamaCpp.LlamaChatSession;
}
importer();

const model_path = path.join(__dirname, '..', 'models')
// const model_path = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'models')
const {isPackaged, userDataPath} = await ipcRenderer.invoke('electron-settings');
model_path = isPackaged ? path.join(userDataPath, 'models') : path.join(__dirname, '..', 'models')
if(!existsSync(model_path)) mkdirSync(model_path)
}
initer();

let llama_session, stop_signal;

Expand All @@ -22,14 +25,15 @@ let llama_session, stop_signal;
async function loadModel(model_name = '') {
if(!model_name || current_model === model_name) return;
current_model = model_name;
const modelPath = path.join(model_path, model_name)
if(!existsSync(modelPath)) {
return;
}

if(llama) await llama.dispose();

llama = await getLlama()
const model = await llama.loadModel({
modelPath: path.join(model_path, model_name)
})

const model = await llama.loadModel({modelPath})
const context = await model.createContext();
llama_session = new LlamaChatSession({
contextSequence: context.getSequence()
Expand Down

0 comments on commit 7a7bc71

Please sign in to comment.