Skip to content

Commit e245027

Browse files
Jameslouis-jan
authored andcommitted
feat: deprecate model catalog
Signed-off-by: James <[email protected]>
1 parent 1143bd3 commit e245027

File tree

44 files changed

+337
-627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+337
-627
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dist
1111
build
1212
.DS_Store
1313
electron/renderer
14+
electron/models
1415
package-lock.json
1516

1617
*.log

core/src/core.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ const getUserSpace = (): Promise<string> => window.core.api?.getUserSpace();
5454
const openFileExplorer: (path: string) => Promise<any> = (path) =>
5555
window.core.api?.openFileExplorer(path);
5656

57+
const getResourcePath: () => Promise<string> = () =>
58+
window.core.api?.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/extensions/model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseExtension } from "../extension";
2-
import { Model, ModelCatalog } from "../types/index";
2+
import { Model } from "../types/index";
33

44
/**
55
* Model extension for managing models.
@@ -43,5 +43,5 @@ export abstract class ModelExtension extends BaseExtension {
4343
* Gets a list of configured models.
4444
* @returns A Promise that resolves with an array of configured models.
4545
*/
46-
abstract getConfiguredModels(): Promise<ModelCatalog[]>;
46+
abstract getConfiguredModels(): Promise<Model[]>;
4747
}

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.core.api?.appendFile(path, data);
6464

65+
const copyFile: (src: string, dest: string) => Promise<any> = (src, dest) =>
66+
window.core.api?.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/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/app.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { app, ipcMain, shell } from 'electron'
2-
import { ModuleManager } from '../managers/module'
2+
import { ModuleManager } from './../managers/module'
33
import { join } from 'path'
4-
import { ExtensionManager } from '../managers/extension'
5-
import { WindowManager } from '../managers/window'
6-
import { userSpacePath } from '../utils/path'
4+
import { ExtensionManager } from './../managers/extension'
5+
import { WindowManager } from './../managers/window'
6+
import { userSpacePath } from './../utils/path'
77

88
export function handleAppIPCs() {
99
/**

electron/handlers/download.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { app, ipcMain } from 'electron'
2-
import { DownloadManager } from '../managers/download'
2+
import { DownloadManager } from './../managers/download'
33
import { resolve, join } from 'path'
4-
import { WindowManager } from '../managers/window'
4+
import { WindowManager } from './../managers/window'
55
import request from 'request'
6-
import { createWriteStream, unlink } from 'fs'
6+
import { createWriteStream } from 'fs'
7+
import { getResourcePath } from './../utils/path'
78
const progress = require('request-progress')
89

910
export function handleDownloaderIPCs() {
@@ -37,6 +38,10 @@ export function handleDownloaderIPCs() {
3738
rq?.abort()
3839
})
3940

41+
ipcMain.handle('getResourcePath', async (_event) => {
42+
return getResourcePath()
43+
})
44+
4045
/**
4146
* Downloads a file from a given URL.
4247
* @param _event - The IPC event object.

electron/handlers/extension.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
import { app, ipcMain, webContents } from 'electron'
2-
import { readdirSync, rmdir, writeFileSync } from 'fs'
3-
import { ModuleManager } from '../managers/module'
1+
import { ipcMain, webContents } from 'electron'
2+
import { readdirSync } from 'fs'
3+
import { ModuleManager } from './../managers/module'
44
import { join, extname } from 'path'
5-
import { ExtensionManager } from '../managers/extension'
6-
import { WindowManager } from '../managers/window'
7-
import { manifest, tarball } from 'pacote'
85
import {
96
getActiveExtensions,
107
getAllExtensions,
118
installExtensions,
12-
} from '../extension/store'
13-
import { getExtension } from '../extension/store'
14-
import { removeExtension } from '../extension/store'
15-
import Extension from '../extension/extension'
16-
import { userSpacePath } from '../utils/path'
9+
} from './../extension/store'
10+
import { getExtension } from './../extension/store'
11+
import { removeExtension } from './../extension/store'
12+
import Extension from './../extension/extension'
13+
import { getResourcePath, userSpacePath } from './../utils/path'
1714

1815
export function handleExtensionIPCs() {
1916
/**MARK: General handlers */
@@ -48,11 +45,7 @@ export function handleExtensionIPCs() {
4845
* @returns An array of paths to the base extensions.
4946
*/
5047
ipcMain.handle('extension:baseExtensions', async (_event) => {
51-
const baseExtensionPath = join(
52-
__dirname,
53-
'../',
54-
app.isPackaged ? '../../app.asar.unpacked/pre-install' : '../pre-install'
55-
)
48+
const baseExtensionPath = join(getResourcePath(), 'pre-install')
5649
return readdirSync(baseExtensionPath)
5750
.filter((file) => extname(file) === '.tgz')
5851
.map((file) => join(baseExtensionPath, file))

electron/handlers/fs.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { app, ipcMain } from 'electron'
1+
import { ipcMain } from 'electron'
22
import * as fs from 'fs'
3+
import fse from 'fs-extra'
34
import { join } from 'path'
45
import readline from 'readline'
5-
import { userSpacePath } from '../utils/path'
6+
import { userSpacePath } from './../utils/path'
67

78
/**
89
* Handles file system operations.
@@ -145,6 +146,12 @@ export function handleFsIPCs() {
145146
}
146147
})
147148

149+
ipcMain.handle('copyFile', async (_event, src: string, dest: string) => {
150+
console.debug(`Copying file from ${src} to ${dest}`)
151+
152+
return fse.copySync(src, dest, { overwrite: false })
153+
})
154+
148155
/**
149156
* Reads a file line by line.
150157
* @param event - The event object.

electron/handlers/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { app, dialog } from "electron";
2-
import { WindowManager } from "../managers/window";
2+
import { WindowManager } from "./../managers/window";
33
import { autoUpdater } from "electron-updater";
44

55
export function handleAppUpdates() {

0 commit comments

Comments
 (0)