Skip to content

Commit

Permalink
feat: deprecate model catalog
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
  • Loading branch information
James committed Dec 1, 2023
1 parent 86e693b commit cbe222a
Show file tree
Hide file tree
Showing 28 changed files with 237 additions and 545 deletions.
6 changes: 5 additions & 1 deletion core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 12,7 @@ const executeOnMain: (
method: string,
...args: any[]
) => Promise<any> = (plugin, method, ...args) =>
window.coreAPI?.invokePluginFunc(plugin, method, ...args)
window.coreAPI?.invokePluginFunc(plugin, method, ...args);

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

const getResourcePath: () => Promise<string> = () =>
window.coreAPI?.getResourcePath();

/**
* Register extension point function type definition
*/
Expand All @@ -74,4 77,5 @@ export {
appDataPath,
getUserSpace,
openFileExplorer,
getResourcePath,
};
4 changes: 4 additions & 0 deletions core/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 62,9 @@ const deleteFile: (path: string) => Promise<any> = (path) =>
const appendFile: (path: string, data: string) => Promise<any> = (path, data) =>
window.coreAPI?.appendFile(path, data);

const copyFile: (src: string, dest: string) => Promise<any> = (src, dest) =>
window.coreAPI?.copyFile(src, dest);

/**
* Reads a file line by line.
* @param {string} path - The path of the file to read.
Expand All @@ -80,4 83,5 @@ export const fs = {
deleteFile,
appendFile,
readLineByLine,
copyFile,
};
4 changes: 2 additions & 2 deletions core/src/plugins/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 3,7 @@
* @abstract
*/
import { JanPlugin } from "../plugin";
import { Model, ModelCatalog } from "../types/index";
import { Model } from "../types/index";

/**
* An abstract class representing a plugin for managing machine learning models.
Expand Down Expand Up @@ -47,5 47,5 @@ export abstract class ModelPlugin extends JanPlugin {
* Gets a list of configured models.
* @returns A Promise that resolves with an array of configured models.
*/
abstract getConfiguredModels(): Promise<ModelCatalog[]>;
abstract getConfiguredModels(): Promise<Model[]>;
}
79 changes: 20 additions & 59 deletions core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 180,7 @@ export interface Model {
/**
* The version of the model.
*/
version: string;
version: number;

/**
* The model download source. It can be an external url or a local filepath.
Expand All @@ -197,12 197,6 @@ export interface Model {
*/
name: string;

/**
* The organization that owns the model (you!)
* Default: "you"
*/
owned_by: string;

/**
* The Unix timestamp (in seconds) for when the model was created
*/
Expand Down Expand Up @@ -236,11 230,16 @@ export interface Model {
metadata: ModelMetadata;
}

export type ModelMetadata = {
author: string;
tags: string[];
size: number;
};

/**
* The Model transition states.
*/
export enum ModelState {
ToDownload = "to_download",
Downloading = "downloading",
Ready = "ready",
Running = "running",
Expand All @@ -250,65 249,27 @@ export enum ModelState {
* The available model settings.
*/
export type ModelSettingParams = {
ctx_len: number;
ngl: number;
embedding: boolean;
n_parallel: number;
ctx_len?: number;
ngl?: number;
embedding?: boolean;
n_parallel?: number;
system_prompt?: string;
user_prompt?: string;
ai_prompt?: string;
};

/**
* The available model runtime parameters.
*/
export type ModelRuntimeParam = {
temperature: number;
token_limit: number;
top_k: number;
top_p: number;
stream: boolean;
temperature?: number;
token_limit?: number;
top_k?: number;
top_p?: number;
stream?: boolean;
max_tokens?: number;
};

/**
* The metadata of the model.
*/
export type ModelMetadata = {
engine: string;
quantization: string;
size: number;
binaries: string[];
maxRamRequired: number;
author: string;
avatarUrl: string;
};

/**
* Model type of the presentation object which will be presented to the user
* @data_transfer_object
*/
export interface ModelCatalog {
/** The unique id of the model.*/
id: string;
/** The name of the model.*/
name: string;
/** The avatar url of the model.*/
avatarUrl: string;
/** The short description of the model.*/
shortDescription: string;
/** The long description of the model.*/
longDescription: string;
/** The author name of the model.*/
author: string;
/** The version of the model.*/
version: string;
/** The origin url of the model repo.*/
modelUrl: string;
/** The timestamp indicating when this model was released.*/
releaseDate: number;
/** The tags attached to the model description **/
tags: string[];
/** The available versions of this model to download. */
availableVersions: Model[];
}

/**
* Assistant type defines the shape of an assistant object.
* @stored
Expand Down
12 changes: 12 additions & 0 deletions electron/handlers/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 37,18 @@ export function handleDownloaderIPCs() {
rq?.abort()
})

ipcMain.handle('getResourcePath', async (_event) => {
let appPath = app.getAppPath()
appPath = join(appPath, '..', 'app.asar.unpacked')

if (!app.isPackaged) {
// for development mode
appPath = join(__dirname, '..', '..')
}

return appPath
})

/**
* Downloads a file from a given URL.
* @param _event - The IPC event object.
Expand Down
9 changes: 9 additions & 0 deletions electron/handlers/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,7 @@ import { app, ipcMain } from 'electron'
import * as fs from 'fs'
import { join } from 'path'
import readline from 'readline'
import fse from 'fs-extra'

/**
* Handles file system operations.
Expand Down Expand Up @@ -174,6 175,14 @@ export function handleFsIPCs() {
})
})

ipcMain.handle('copyFile', async (_event, src: string, dest: string) => {
// copy over model file using fse
const destPath = join(userSpacePath, dest)
console.debug(`Copying file from ${src} to ${destPath}`)

return fse.copySync(src, destPath, { overwrite: false })
})

ipcMain.handle('readLineByLine', async (_event, path: string) => {
const fullPath = join(userSpacePath, path)

Expand Down
23 changes: 23 additions & 0 deletions electron/models/capybara-34b/model.json
Original file line number Diff line number Diff line change
@@ -0,0 1,23 @@
{
"source_url": "https://huggingface.co/TheBloke/Nous-Capybara-34B-GGUF/blob/main/nous-capybara-34b.Q5_K_M.gguf",
"id": "capybara-34b",
"object": "model",
"name": "Capybara 200k 34B",
"version": 1.0,
"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.",
"format": "gguf",
"settings": {
"ctx_len": 200000,
"system_prompt": "",
"user_prompt": "USER: ",
"ai_prompt": "ASSISTANT: "
},
"parameters": {
"max_tokens": 200000
},
"metadata": {
"author": "NousResearch, The Bloke",
"tags": ["General", "Big Context Length"],
"size": 24320000000
}
}
7 changes: 5 additions & 2 deletions electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 14,12 @@
"build/*.{js,map}",
"build/**/*.{js,map}",
"core/pre-install",
"core/plugin-manager/facade"
"core/plugin-manager/facade",
"models/**/*"
],
"asarUnpack": [
"core/pre-install"
"core/pre-install",
"models"
],
"publish": [
{
Expand Down Expand Up @@ -71,6 73,7 @@
"@uiball/loaders": "^1.3.0",
"electron-store": "^8.1.0",
"electron-updater": "^6.1.4",
"fs-extra": "^11.2.0",
"pacote": "^17.0.4",
"request": "^2.88.2",
"request-progress": "^3.0.0",
Expand Down
5 changes: 5 additions & 0 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 104,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
appendFile: (path: string, data: string) =>
ipcRenderer.invoke('appendFile', path, data),

copyFile: (src: string, dest: string) =>
ipcRenderer.invoke('copyFile', src, dest),

getResourcePath: () => ipcRenderer.invoke('getResourcePath'),

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

mkdir: (path: string) => ipcRenderer.invoke('mkdir', path),
Expand Down
1 change: 0 additions & 1 deletion plugins/inference-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 146,6 @@ export default class JanInferencePlugin implements InferencePlugin {
object: "thread.message",
};
events.emit(EventName.OnNewMessageResponse, message);
console.log(JSON.stringify(data, null, 2));

instance.isCancelled = false;
instance.controller = new AbortController();
Expand Down
5 changes: 2 additions & 3 deletions plugins/model-plugin/src/@types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 1,2 @@
declare const PLUGIN_NAME: string;
declare const MODULE_PATH: string;
declare const MODEL_CATALOG_URL: string;
declare const PLUGIN_NAME: string
declare const MODULE_PATH: string
21 changes: 0 additions & 21 deletions plugins/model-plugin/src/@types/schema.ts

This file was deleted.

46 changes: 0 additions & 46 deletions plugins/model-plugin/src/helpers/modelParser.ts

This file was deleted.

Loading

0 comments on commit cbe222a

Please sign in to comment.