chore: clean
This commit is contained in:
parent
d98ad60422
commit
d133594db7
1
plugins/inference-plugin/@types/global.d.ts
vendored
1
plugins/inference-plugin/@types/global.d.ts
vendored
@ -1,2 +1,3 @@
|
|||||||
declare const PLUGIN_NAME: string;
|
declare const PLUGIN_NAME: string;
|
||||||
declare const MODULE_PATH: string;
|
declare const MODULE_PATH: string;
|
||||||
|
declare const INFERENCE_URL: string;
|
||||||
|
|||||||
@ -1,17 +1,23 @@
|
|||||||
import { EventName, InferenceService, NewMessageRequest, PluginService, core, events, store } from "@janhq/core";
|
import {
|
||||||
|
EventName,
|
||||||
|
InferenceService,
|
||||||
|
NewMessageRequest,
|
||||||
|
PluginService,
|
||||||
|
events,
|
||||||
|
store,
|
||||||
|
invokePluginFunc,
|
||||||
|
} from "@janhq/core";
|
||||||
import { Observable } from "rxjs";
|
import { Observable } from "rxjs";
|
||||||
|
|
||||||
const inferenceUrl = "http://127.0.0.1:3928/llama/chat_completion";
|
const initModel = async (product) => invokePluginFunc(MODULE_PATH, "initModel", product);
|
||||||
|
|
||||||
const initModel = async (product) => core.invokePluginFunc(MODULE_PATH, "initModel", product);
|
|
||||||
|
|
||||||
const stopModel = () => {
|
const stopModel = () => {
|
||||||
core.invokePluginFunc(MODULE_PATH, "killSubprocess");
|
invokePluginFunc(MODULE_PATH, "killSubprocess");
|
||||||
};
|
};
|
||||||
|
|
||||||
function requestInference(recentMessages: any[]): Observable<string> {
|
function requestInference(recentMessages: any[]): Observable<string> {
|
||||||
return new Observable((subscriber) => {
|
return new Observable((subscriber) => {
|
||||||
fetch(inferenceUrl, {
|
fetch(INFERENCE_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@ -22,11 +28,7 @@ function requestInference(recentMessages: any[]): Observable<string> {
|
|||||||
messages: recentMessages,
|
messages: recentMessages,
|
||||||
stream: true,
|
stream: true,
|
||||||
model: "gpt-3.5-turbo",
|
model: "gpt-3.5-turbo",
|
||||||
max_tokens: 2048,
|
max_tokens: 500,
|
||||||
stop: ["hello"],
|
|
||||||
frequency_penalty: 0,
|
|
||||||
presence_penalty: 0,
|
|
||||||
temperature: 0
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
|
|||||||
@ -5,8 +5,8 @@ const fs = require("fs");
|
|||||||
const tcpPortUsed = require("tcp-port-used");
|
const tcpPortUsed = require("tcp-port-used");
|
||||||
const { killPortProcess } = require("kill-port-process");
|
const { killPortProcess } = require("kill-port-process");
|
||||||
|
|
||||||
let subprocess = null;
|
|
||||||
const PORT = 3928;
|
const PORT = 3928;
|
||||||
|
let subprocess = null;
|
||||||
|
|
||||||
const initModel = (fileName) => {
|
const initModel = (fileName) => {
|
||||||
return (
|
return (
|
||||||
@ -15,9 +15,7 @@ const initModel = (fileName) => {
|
|||||||
reject("Model not found, please download again.");
|
reject("Model not found, please download again.");
|
||||||
}
|
}
|
||||||
if (subprocess) {
|
if (subprocess) {
|
||||||
console.error(
|
console.error("A subprocess is already running. Attempt to kill then reinit.");
|
||||||
"A subprocess is already running. Attempt to kill then reinit."
|
|
||||||
);
|
|
||||||
killSubprocess();
|
killSubprocess();
|
||||||
}
|
}
|
||||||
resolve(fileName);
|
resolve(fileName);
|
||||||
@ -32,26 +30,13 @@ const initModel = (fileName) => {
|
|||||||
// Spawn Nitro subprocess to load model
|
// Spawn Nitro subprocess to load model
|
||||||
.then(() => {
|
.then(() => {
|
||||||
let binaryFolder = path.join(__dirname, "nitro"); // Current directory by default
|
let binaryFolder = path.join(__dirname, "nitro"); // Current directory by default
|
||||||
|
|
||||||
const config = {
|
|
||||||
llama_model_path: "",
|
|
||||||
ctx_len: 2048,
|
|
||||||
ngl: 100,
|
|
||||||
embedding: true // Always enable embedding mode on
|
|
||||||
}
|
|
||||||
|
|
||||||
const modelPath = path.join(app.getPath("userData"), fileName);
|
|
||||||
|
|
||||||
config.llama_model_path = modelPath;
|
|
||||||
|
|
||||||
let binaryName;
|
let binaryName;
|
||||||
|
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
binaryName = "nitro_windows_amd64_cuda.exe";
|
binaryName = "nitro_windows_amd64_cuda.exe";
|
||||||
} else if (process.platform === "darwin") {
|
} else if (process.platform === "darwin") {
|
||||||
// Mac OS platform
|
// Mac OS platform
|
||||||
binaryName =
|
binaryName = process.arch === "arm64" ? "nitro_mac_arm64" : "nitro_mac_intel";
|
||||||
process.arch === "arm64" ? "nitro_mac_arm64" : "nitro_mac_amd64";
|
|
||||||
} else {
|
} else {
|
||||||
// Linux
|
// Linux
|
||||||
binaryName = "nitro_linux_amd64_cuda"; // For other platforms
|
binaryName = "nitro_linux_amd64_cuda"; // For other platforms
|
||||||
@ -60,7 +45,6 @@ const initModel = (fileName) => {
|
|||||||
const binaryPath = path.join(binaryFolder, binaryName);
|
const binaryPath = path.join(binaryFolder, binaryName);
|
||||||
|
|
||||||
// Execute the binary
|
// Execute the binary
|
||||||
|
|
||||||
subprocess = spawn(binaryPath, { cwd: binaryFolder });
|
subprocess = spawn(binaryPath, { cwd: binaryFolder });
|
||||||
|
|
||||||
// Handle subprocess output
|
// Handle subprocess output
|
||||||
@ -78,13 +62,24 @@ const initModel = (fileName) => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(() => tcpPortUsed.waitUntilUsed(PORT, 300, 30000))
|
.then(() => tcpPortUsed.waitUntilUsed(PORT, 300, 30000))
|
||||||
.then((config) => {
|
.then(() => {
|
||||||
const initModel = fetch(`http://127.0.0.1:${PORT}/inferences/llamacpp/loadmodel`, {
|
const llama_model_path = path.join(app.getPath("userData"), fileName);
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
llama_model_path,
|
||||||
|
ctx_len: 2048,
|
||||||
|
ngl: 100,
|
||||||
|
embedding: true, // Always enable embedding mode on
|
||||||
|
};
|
||||||
|
|
||||||
|
// Load model config
|
||||||
|
return fetch(`http://127.0.0.1:${PORT}/inferences/llamacpp/loadmodel`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(config),
|
body: JSON.stringify(config),
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@ -92,7 +87,6 @@ const initModel = (fileName) => {
|
|||||||
}
|
}
|
||||||
throw new Error("Nitro: Model failed to load.");
|
throw new Error("Nitro: Model failed to load.");
|
||||||
})
|
})
|
||||||
})
|
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
return { error: err };
|
return { error: err };
|
||||||
})
|
})
|
||||||
|
|||||||
@ -19,6 +19,7 @@ module.exports = {
|
|||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
PLUGIN_NAME: JSON.stringify(packageJson.name),
|
PLUGIN_NAME: JSON.stringify(packageJson.name),
|
||||||
MODULE_PATH: JSON.stringify(`${packageJson.name}/${packageJson.module}`),
|
MODULE_PATH: JSON.stringify(`${packageJson.name}/${packageJson.module}`),
|
||||||
|
INFERENCE_URL: JSON.stringify("http://127.0.0.1:3928/inferences/llamacpp/chat_completion"),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
output: {
|
output: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user