Skip to content

Commit

Permalink
correct file path
Browse files Browse the repository at this point in the history
  • Loading branch information
hiento09 committed Dec 28, 2023
1 parent f3ba1cb commit efbe9f7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
15 changes: 11 additions & 4 deletions electron/handlers/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ipcMain } from 'electron'

import { FileSystemRoute } from '@janhq/core'
import { userSpacePath } from '../utils/path'
import { join } from 'path'
import { join, sep } from 'path'
/**
* Handles file system operations.
*/
Expand All @@ -13,12 +13,19 @@ export function handleFsIPCs() {
return import(moduleName).then((mdl) =>
mdl[route](
...args.map((arg) =>
typeof arg === 'string' && arg.includes('file:/')
? join(userSpacePath, arg.replace('file:/', ''))
typeof arg === 'string' &&
(arg.includes(`file:/`) || arg.includes(`file:\\`))
? join(
userSpacePath,
arg.replace(`file://`, '')
.replace(`file:/`, '')
.replace(`file:\\\\`, '')
.replace(`file:\\`, '')
)
: arg
)
)
)
})
})
}
}
4 changes: 2 additions & 2 deletions extensions/inference-nitro-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export default class JanInferenceNitroExtension implements InferenceExtension {
// Attempt to fetch nvidia info
await executeOnMain(MODULE, "updateNvidiaInfo", {});

const gpuDriverConf = await fs.readFile(
join(__dirname, "bin", "nvidia.json")
const gpuDriverConf = await fs.readFileSync(
join(JanInferenceNitroExtension._settingsDir, "settings.json")
);
if (gpuDriverConf.notify && gpuDriverConf.run_mode === "cpu") {
// Driver is fully installed, but not in use
Expand Down
41 changes: 38 additions & 3 deletions extensions/inference-nitro-extension/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,26 @@ const NITRO_HTTP_KILL_URL = `${NITRO_HTTP_SERVER_URL}/processmanager/destroy`;
const SUPPORTED_MODEL_FORMAT = ".gguf";
const NVIDIA_INFO_FILE = path.join(
require("os").homedir(),
"jan",
"settings",
"settings.json"
);

const DEFALT_SETTINGS = {
"notify": false,
"run_mode": "cpu",
"nvidia_driver": {
"exist": false,
"version": ""
},
"cuda": {
"exist": false,
"version": ""
},
"gpus": [],
"gpu_highest_vram": ""
}

// The subprocess instance for Nitro
let subprocess = undefined;
let currentModelFile: string = undefined;
Expand All @@ -43,7 +59,13 @@ async function updateNvidiaDriverInfo(): Promise<void> {
exec(
"nvidia-smi --query-gpu=driver_version --format=csv,noheader",
(error, stdout) => {
let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8"));
let data;
try {
data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8"));
} catch (error) {
data = DEFALT_SETTINGS;
}
// let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8"));

if (!error) {
const firstLine = stdout.split("\n")[0].trim();
Expand Down Expand Up @@ -86,7 +108,14 @@ function updateCudaExistence() {
(file) => existsSync(file) || checkFileExistenceInPaths(file, paths)
);

let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8"));
let data;
try {
data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8"));
} catch (error) {
data = DEFALT_SETTINGS;
}

// let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8"));
data["cuda"].exist = cudaExists;
writeFileSync(NVIDIA_INFO_FILE, JSON.stringify(data, null, 2));
}
Expand All @@ -95,7 +124,13 @@ async function updateGpuInfo(): Promise<void> {
exec(
"nvidia-smi --query-gpu=index,memory.total --format=csv,noheader,nounits",
(error, stdout) => {
let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8"));
let data;
try {
data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8"));
} catch (error) {
data = DEFALT_SETTINGS;
}
// let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8"));

if (!error) {
// Get GPU info and gpu has higher memory first
Expand Down

0 comments on commit efbe9f7

Please sign in to comment.