chore: new cortex-cpp binary - model import option and model size
This commit is contained in:
parent
b913af9f88
commit
46d5faf59f
@ -15,7 +15,7 @@ export abstract class ModelExtension extends BaseExtension implements ModelInter
|
||||
abstract getModels(): Promise<Model[]>
|
||||
abstract pullModel(model: string, id?: string, name?: string): Promise<void>
|
||||
abstract cancelModelPull(modelId: string): Promise<void>
|
||||
abstract importModel(model: string, modePath: string, name?: string): Promise<void>
|
||||
abstract importModel(model: string, modePath: string, name?: string, optionType?: OptionType): Promise<void>
|
||||
abstract updateModel(modelInfo: Partial<Model>): Promise<Model>
|
||||
abstract deleteModel(model: string): Promise<void>
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export type OptionType = 'SYMLINK' | 'MOVE_BINARY_FILE'
|
||||
export type OptionType = 'symlink' | 'copy'
|
||||
|
||||
export type ModelImportOption = {
|
||||
type: OptionType
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { Model } from './modelEntity'
|
||||
import { OptionType } from './modelImport'
|
||||
|
||||
/**
|
||||
* Model extension for managing models.
|
||||
@ -43,5 +44,10 @@ export interface ModelInterface {
|
||||
* @param model id of the model to import
|
||||
* @param modelPath - path of the model file
|
||||
*/
|
||||
importModel(model: string, modePath: string, name?: string): Promise<void>
|
||||
importModel(
|
||||
model: string,
|
||||
modePath: string,
|
||||
name?: string,
|
||||
optionType?: OptionType
|
||||
): Promise<void>
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
1.0.2-rc2
|
||||
1.0.2-rc4
|
||||
@ -9,7 +9,7 @@ interface ICortexAPI {
|
||||
getModel(model: string): Promise<Model>
|
||||
getModels(): Promise<Model[]>
|
||||
pullModel(model: string, id?: string, name?: string): Promise<void>
|
||||
importModel(path: string, modelPath: string, name?: string): Promise<void>
|
||||
importModel(path: string, modelPath: string, name?: string, option?: string): Promise<void>
|
||||
deleteModel(model: string): Promise<void>
|
||||
updateModel(model: object): Promise<void>
|
||||
cancelModelPull(model: string): Promise<void>
|
||||
@ -85,10 +85,17 @@ export class CortexAPI implements ICortexAPI {
|
||||
* @param model
|
||||
* @returns
|
||||
*/
|
||||
importModel(model: string, modelPath: string, name?: string): Promise<void> {
|
||||
importModel(
|
||||
model: string,
|
||||
modelPath: string,
|
||||
name?: string,
|
||||
option?: string
|
||||
): Promise<void> {
|
||||
return this.queue.add(() =>
|
||||
ky
|
||||
.post(`${API_URL}/v1/models/import`, { json: { model, modelPath, name } })
|
||||
.post(`${API_URL}/v1/models/import`, {
|
||||
json: { model, modelPath, name, option },
|
||||
})
|
||||
.json()
|
||||
.catch((e) => console.debug(e)) // Ignore error
|
||||
.then()
|
||||
@ -208,6 +215,7 @@ export class CortexAPI implements ICortexAPI {
|
||||
}
|
||||
model.metadata = model.metadata ?? {
|
||||
tags: [],
|
||||
size: model.size ?? model.metadata?.size ?? 0
|
||||
}
|
||||
return model as Model
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
DownloadState,
|
||||
events,
|
||||
DownloadEvent,
|
||||
OptionType
|
||||
} from '@janhq/core'
|
||||
import { CortexAPI } from './cortex'
|
||||
import { scanModelsFolder } from './legacy/model-json'
|
||||
@ -228,9 +229,10 @@ export default class JanModelExtension extends ModelExtension {
|
||||
async importModel(
|
||||
model: string,
|
||||
modelPath: string,
|
||||
name?: string
|
||||
name?: string,
|
||||
option?: OptionType
|
||||
): Promise<void> {
|
||||
return this.cortexAPI.importModel(model, modelPath, name)
|
||||
return this.cortexAPI.importModel(model, modelPath, name, option)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -3,6 +3,7 @@ import { useCallback } from 'react'
|
||||
import {
|
||||
ExtensionTypeEnum,
|
||||
ImportingModel,
|
||||
LocalImportModelEvent,
|
||||
Model,
|
||||
ModelEvent,
|
||||
ModelExtension,
|
||||
@ -66,10 +67,13 @@ const useImportModel = () => {
|
||||
addDownloadingModel(modelId)
|
||||
extensionManager
|
||||
.get<ModelExtension>(ExtensionTypeEnum.Model)
|
||||
?.importModel(modelId, model.path, model.name)
|
||||
?.importModel(modelId, model.path, model.name, optionType)
|
||||
.finally(() => {
|
||||
removeDownloadingModel(modelId)
|
||||
events.emit(ModelEvent.OnModelsUpdate, {})
|
||||
events.emit(LocalImportModelEvent.onLocalImportModelSuccess, {
|
||||
importId: model.importId,
|
||||
modelId: modelId,
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@ -43,7 +43,19 @@ const useModels = () => {
|
||||
.models.values()
|
||||
.toArray()
|
||||
.filter((e) => !isLocalEngine(e.engine))
|
||||
setDownloadedModels([...localModels, ...remoteModels])
|
||||
const toUpdate = [...localModels, ...remoteModels]
|
||||
setDownloadedModels(toUpdate)
|
||||
|
||||
let isUpdated = false
|
||||
toUpdate.forEach((model) => {
|
||||
if (!ModelManager.instance().models.has(model.id)) {
|
||||
ModelManager.instance().models.set(model.id, model)
|
||||
isUpdated = true
|
||||
}
|
||||
})
|
||||
if (isUpdated) {
|
||||
getExtensionModels()
|
||||
}
|
||||
}
|
||||
|
||||
const getExtensionModels = async () => {
|
||||
@ -52,7 +64,7 @@ const useModels = () => {
|
||||
}
|
||||
|
||||
// Fetch all data
|
||||
Promise.all([getDownloadedModels(), getExtensionModels()])
|
||||
getExtensionModels().then(getDownloadedModels)
|
||||
}, [setDownloadedModels, setExtensionModels])
|
||||
|
||||
const reloadData = useDebouncedCallback(() => getData(), 300)
|
||||
|
||||
@ -15,13 +15,13 @@ import { importingModelsAtom } from '@/helpers/atoms/Model.atom'
|
||||
|
||||
const importOptions: ModelImportOption[] = [
|
||||
{
|
||||
type: 'SYMLINK',
|
||||
type: 'symlink',
|
||||
title: 'Keep Original Files & Symlink',
|
||||
description:
|
||||
'You maintain your model files outside of Jan. Keeping your files where they are, and Jan will create a smart link to them.',
|
||||
},
|
||||
{
|
||||
type: 'MOVE_BINARY_FILE',
|
||||
type: 'copy',
|
||||
title: 'Move model binary file',
|
||||
description:
|
||||
'Jan will move your model binary file from your current folder into Jan Data Folder.',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user