Skip to content

Commit cbe222a

Browse files
author
James
committed
feat: deprecate model catalog
Signed-off-by: James <[email protected]>
1 parent 86e693b commit cbe222a

File tree

28 files changed

+237
-545
lines changed

28 files changed

+237
-545
lines changed

core/src/core.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const executeOnMain: (
1212
method: string,
1313
...args: any[]
1414
) => Promise<any> = (plugin, method, ...args) =>
15-
window.coreAPI?.invokePluginFunc(plugin, method, ...args)
15+
window.coreAPI?.invokePluginFunc(plugin, method, ...args);
1616

1717
/**
1818
* Downloads a file from a URL and saves it to the local file system.
@@ -54,6 +54,9 @@ const getUserSpace = (): Promise<string> => window.coreAPI?.getUserSpace();
5454
const openFileExplorer: (path: string) => Promise<any> = (path) =>
5555
window.coreAPI?.openFileExplorer(path);
5656

57+
const getResourcePath: () => Promise<string> = () =>
58+
window.coreAPI?.getResourcePath();
59+
5760
/**
5861
* Register extension point function type definition
5962
*/
@@ -74,4 +77,5 @@ export {
7477
appDataPath,
7578
getUserSpace,
7679
openFileExplorer,
80+
getResourcePath,
7781
};

core/src/fs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ const deleteFile: (path: string) => Promise<any> = (path) =>
6262
const appendFile: (path: string, data: string) => Promise<any> = (path, data) =>
6363
window.coreAPI?.appendFile(path, data);
6464

65+
const copyFile: (src: string, dest: string) => Promise<any> = (src, dest) =>
66+
window.coreAPI?.copyFile(src, dest);
67+
6568
/**
6669
* Reads a file line by line.
6770
* @param {string} path - The path of the file to read.
@@ -80,4 +83,5 @@ export const fs = {
8083
deleteFile,
8184
appendFile,
8285
readLineByLine,
86+
copyFile,
8387
};

core/src/plugins/model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @abstract
44
*/
55
import { JanPlugin } from "../plugin";
6-
import { Model, ModelCatalog } from "../types/index";
6+
import { Model } from "../types/index";
77

88
/**
99
* An abstract class representing a plugin for managing machine learning models.
@@ -47,5 +47,5 @@ export abstract class ModelPlugin extends JanPlugin {
4747
* Gets a list of configured models.
4848
* @returns A Promise that resolves with an array of configured models.
4949
*/
50-
abstract getConfiguredModels(): Promise<ModelCatalog[]>;
50+
abstract getConfiguredModels(): Promise<Model[]>;
5151
}

core/src/types/index.ts

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export interface Model {
180180
/**
181181
* The version of the model.
182182
*/
183-
version: string;
183+
version: number;
184184

185185
/**
186186
* The model download source. It can be an external url or a local filepath.
@@ -197,12 +197,6 @@ export interface Model {
197197
*/
198198
name: string;
199199

200-
/**
201-
* The organization that owns the model (you!)
202-
* Default: "you"
203-
*/
204-
owned_by: string;
205-
206200
/**
207201
* The Unix timestamp (in seconds) for when the model was created
208202
*/
@@ -236,11 +230,16 @@ export interface Model {
236230
metadata: ModelMetadata;
237231
}
238232

233+
export type ModelMetadata = {
234+
author: string;
235+
tags: string[];
236+
size: number;
237+
};
238+
239239
/**
240240
* The Model transition states.
241241
*/
242242
export enum ModelState {
243-
ToDownload = "to_download",
244243
Downloading = "downloading",
245244
Ready = "ready",
246245
Running = "running",
@@ -250,65 +249,27 @@ export enum ModelState {
250249
* The available model settings.
251250
*/
252251
export type ModelSettingParams = {
253-
ctx_len: number;
254-
ngl: number;
255-
embedding: boolean;
256-
n_parallel: number;
252+
ctx_len?: number;
253+
ngl?: number;
254+
embedding?: boolean;
255+
n_parallel?: number;
256+
system_prompt?: string;
257+
user_prompt?: string;
258+
ai_prompt?: string;
257259
};
258260

259261
/**
260262
* The available model runtime parameters.
261263
*/
262264
export type ModelRuntimeParam = {
263-
temperature: number;
264-
token_limit: number;
265-
top_k: number;
266-
top_p: number;
267-
stream: boolean;
265+
temperature?: number;
266+
token_limit?: number;
267+
top_k?: number;
268+
top_p?: number;
269+
stream?: boolean;
270+
max_tokens?: number;
268271
};
269272

270-
/**
271-
* The metadata of the model.
272-
*/
273-
export type ModelMetadata = {
274-
engine: string;
275-
quantization: string;
276-
size: number;
277-
binaries: string[];
278-
maxRamRequired: number;
279-
author: string;
280-
avatarUrl: string;
281-
};
282-
283-
/**
284-
* Model type of the presentation object which will be presented to the user
285-
* @data_transfer_object
286-
*/
287-
export interface ModelCatalog {
288-
/** The unique id of the model.*/
289-
id: string;
290-
/** The name of the model.*/
291-
name: string;
292-
/** The avatar url of the model.*/
293-
avatarUrl: string;
294-
/** The short description of the model.*/
295-
shortDescription: string;
296-
/** The long description of the model.*/
297-
longDescription: string;
298-
/** The author name of the model.*/
299-
author: string;
300-
/** The version of the model.*/
301-
version: string;
302-
/** The origin url of the model repo.*/
303-
modelUrl: string;
304-
/** The timestamp indicating when this model was released.*/
305-
releaseDate: number;
306-
/** The tags attached to the model description **/
307-
tags: string[];
308-
/** The available versions of this model to download. */
309-
availableVersions: Model[];
310-
}
311-
312273
/**
313274
* Assistant type defines the shape of an assistant object.
314275
* @stored

electron/handlers/download.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ export function handleDownloaderIPCs() {
3737
rq?.abort()
3838
})
3939

40+
ipcMain.handle('getResourcePath', async (_event) => {
41+
let appPath = app.getAppPath()
42+
appPath = join(appPath, '..', 'app.asar.unpacked')
43+
44+
if (!app.isPackaged) {
45+
// for development mode
46+
appPath = join(__dirname, '..', '..')
47+
}
48+
49+
return appPath
50+
})
51+
4052
/**
4153
* Downloads a file from a given URL.
4254
* @param _event - The IPC event object.

electron/handlers/fs.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { app, ipcMain } from 'electron'
22
import * as fs from 'fs'
33
import { join } from 'path'
44
import readline from 'readline'
5+
import fse from 'fs-extra'
56

67
/**
78
* Handles file system operations.
@@ -174,6 +175,14 @@ export function handleFsIPCs() {
174175
})
175176
})
176177

178+
ipcMain.handle('copyFile', async (_event, src: string, dest: string) => {
179+
// copy over model file using fse
180+
const destPath = join(userSpacePath, dest)
181+
console.debug(`Copying file from ${src} to ${destPath}`)
182+
183+
return fse.copySync(src, destPath, { overwrite: false })
184+
})
185+
177186
ipcMain.handle('readLineByLine', async (_event, path: string) => {
178187
const fullPath = join(userSpacePath, path)
179188

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"source_url": "https://huggingface.co/TheBloke/Nous-Capybara-34B-GGUF/blob/main/nous-capybara-34b.Q5_K_M.gguf",
3+
"id": "capybara-34b",
4+
"object": "model",
5+
"name": "Capybara 200k 34B",
6+
"version": 1.0,
7+
"description": "Nous Capybara 34B, a variant of the Yi-34B model, is the first Nous model with a 200K context length, trained for three epochs on the innovative Capybara dataset.",
8+
"format": "gguf",
9+
"settings": {
10+
"ctx_len": 200000,
11+
"system_prompt": "",
12+
"user_prompt": "USER: ",
13+
"ai_prompt": "ASSISTANT: "
14+
},
15+
"parameters": {
16+
"max_tokens": 200000
17+
},
18+
"metadata": {
19+
"author": "NousResearch, The Bloke",
20+
"tags": ["General", "Big Context Length"],
21+
"size": 24320000000
22+
}
23+
}

electron/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
"build/*.{js,map}",
1515
"build/**/*.{js,map}",
1616
"core/pre-install",
17-
"core/plugin-manager/facade"
17+
"core/plugin-manager/facade",
18+
"models/**/*"
1819
],
1920
"asarUnpack": [
20-
"core/pre-install"
21+
"core/pre-install",
22+
"models"
2123
],
2224
"publish": [
2325
{
@@ -71,6 +73,7 @@
7173
"@uiball/loaders": "^1.3.0",
7274
"electron-store": "^8.1.0",
7375
"electron-updater": "^6.1.4",
76+
"fs-extra": "^11.2.0",
7477
"pacote": "^17.0.4",
7578
"request": "^2.88.2",
7679
"request-progress": "^3.0.0",

electron/preload.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
104104
appendFile: (path: string, data: string) =>
105105
ipcRenderer.invoke('appendFile', path, data),
106106

107+
copyFile: (src: string, dest: string) =>
108+
ipcRenderer.invoke('copyFile', src, dest),
109+
110+
getResourcePath: () => ipcRenderer.invoke('getResourcePath'),
111+
107112
readLineByLine: (path: string) => ipcRenderer.invoke('readLineByLine', path),
108113

109114
mkdir: (path: string) => ipcRenderer.invoke('mkdir', path),

plugins/inference-plugin/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ export default class JanInferencePlugin implements InferencePlugin {
146146
object: "thread.message",
147147
};
148148
events.emit(EventName.OnNewMessageResponse, message);
149-
console.log(JSON.stringify(data, null, 2));
150149

151150
instance.isCancelled = false;
152151
instance.controller = new AbortController();

0 commit comments

Comments
 (0)