Model Source Manifest List
- }/>
+ } onClick={() => {
+ refreshModels(false);
+ }}/>
Provide JSON file URLs for the models manifest. Separate URLs with semicolons. The "models"
@@ -146,6 +149,7 @@ export const Models: FC = observer(() => {
items={commonStore.modelSourceList}
columns={columns}
sortable={true}
+ defaultSortState={{sortColumn: 'actions', sortDirection: 'ascending'}}
style={{display: 'flex'}}
className="flex-col w-full"
>
diff --git a/frontend/src/startup.ts b/frontend/src/startup.ts
index 29359ed..171740b 100644
--- a/frontend/src/startup.ts
+++ b/frontend/src/startup.ts
@@ -1,18 +1,14 @@
-import commonStore, {defaultModelConfigs, ModelSourceItem} from './stores/commonStore';
-import {ListDirFiles, ReadJson, SaveJson} from '../wailsjs/go/backend_golang/App';
-import manifest from '../../manifest.json';
+import commonStore, {defaultModelConfigs} from './stores/commonStore';
+import {ReadJson} from '../wailsjs/go/backend_golang/App';
+import {LocalConfig, refreshModels} from './utils';
export async function startup() {
initCache();
await initConfig();
}
-type Cache = {
- models: ModelSourceItem[]
-}
-
async function initConfig() {
- await ReadJson('config.json').then((configData) => {
+ await ReadJson('config.json').then((configData: LocalConfig) => {
if (configData.modelSourceManifestList)
commonStore.setModelSourceManifestList(configData.modelSourceManifestList);
if (configData.modelConfigs && Array.isArray(configData.modelConfigs))
@@ -27,80 +23,5 @@ async function initConfig() {
}
async function initCache() {
- let cache: Cache = {models: []};
- await ReadJson('cache.json').then((cacheData: Cache) => {
- cache = cacheData;
- }).catch(
- async () => {
- cache = {models: manifest.models};
- await SaveJson('cache.json', cache).catch(() => {
- });
- }
- );
- // built-in
- commonStore.setModelSourceList(cache.models);
-
- await ListDirFiles(manifest.localModelPath).then((data) => {
- cache.models.push(...data.flatMap(d => {
- if (!d.isDir && d.name.endsWith('.pth'))
- return [{
- name: d.name,
- size: d.size,
- lastUpdated: d.modTime,
- isLocal: true
- }];
- return [];
- }));
- }).catch(() => {
- });
-
- for (let i = 0; i < cache.models.length; i++) {
- if (!cache.models[i].lastUpdatedMs)
- cache.models[i].lastUpdatedMs = Date.parse(cache.models[i].lastUpdated);
-
- for (let j = i + 1; j < cache.models.length; j++) {
- if (!cache.models[j].lastUpdatedMs)
- cache.models[j].lastUpdatedMs = Date.parse(cache.models[j].lastUpdated);
-
- if (cache.models[i].name === cache.models[j].name) {
- if (cache.models[i].size === cache.models[j].size) {
- if (cache.models[i].lastUpdatedMs! < cache.models[j].lastUpdatedMs!) {
- cache.models[i] = Object.assign({}, cache.models[i], cache.models[j]);
- } else {
- cache.models[i] = Object.assign({}, cache.models[j], cache.models[i]);
- }
- } // else is bad local file
- cache.models.splice(j, 1);
- j--;
- }
- }
- }
- // local files
- commonStore.setModelSourceList(cache.models);
- await SaveJson('cache.json', cache).catch(() => {
- });
-
- const manifestUrls = commonStore.modelSourceManifestList.split(/[,,;;\n]/);
- const requests = manifestUrls.filter(url => url.endsWith('.json')).map(
- url => fetch(url, {cache: 'no-cache'}).then(r => r.json()));
-
- await Promise.allSettled(requests)
- .then((data: PromiseSettledResult[]) => {
- cache.models.push(...data.flatMap(d => {
- if (d.status === 'fulfilled')
- return d.value.models;
- return [];
- }));
- })
- .catch(() => {
- });
- cache.models = cache.models.filter((model, index, self) => {
- return model.name.endsWith('.pth')
- && index === self.findIndex(
- m => m.name === model.name || (m.SHA256 === model.SHA256 && m.size === model.size));
- });
- // remote files
- commonStore.setModelSourceList(cache.models);
- await SaveJson('cache.json', cache).catch(() => {
- });
+ await refreshModels(true);
}
\ No newline at end of file
diff --git a/frontend/src/stores/commonStore.ts b/frontend/src/stores/commonStore.ts
index aec52b3..9695744 100644
--- a/frontend/src/stores/commonStore.ts
+++ b/frontend/src/stores/commonStore.ts
@@ -1,5 +1,5 @@
import {makeAutoObservable} from 'mobx';
-import {SaveJson} from '../../wailsjs/go/backend_golang/App';
+import {saveConfigs} from '../utils';
export enum ModelStatus {
Offline,
@@ -83,28 +83,6 @@ class CommonStore {
modelSourceManifestList: string = 'https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/manifest.json;';
modelSourceList: ModelSourceItem[] = [];
- async saveConfigs() {
- await SaveJson('config.json', {
- modelSourceManifestList: this.modelSourceManifestList,
- currentModelConfigIndex: this.currentModelConfigIndex,
- modelConfigs: this.modelConfigs
- });
- }
-
- getStrategy(modelConfig: ModelConfig | undefined = undefined) {
- let params: ModelParameters;
- if (modelConfig) params = modelConfig.modelParameters;
- else params = this.getCurrentModelConfig().modelParameters;
- let strategy = '';
- strategy += (params.device === 'CPU' ? 'cpu' : 'cuda') + ' ';
- strategy += (params.precision === 'fp16' ? 'fp16' : params.precision === 'int8' ? 'fp16i8' : 'fp32');
- if (params.storedLayers < params.maxStoredLayers)
- strategy += ` *${params.storedLayers}+`;
- if (params.enableHighPrecisionForLastLayer)
- strategy += ' -> cpu fp32 *1';
- return strategy;
- }
-
getCurrentModelConfig = () => {
return this.modelConfigs[this.currentModelConfigIndex];
};
@@ -116,19 +94,19 @@ class CommonStore {
setCurrentConfigIndex = (index: number, saveConfig: boolean = true) => {
this.currentModelConfigIndex = index;
if (saveConfig)
- this.saveConfigs();
+ saveConfigs();
};
setModelConfig = (index: number, config: ModelConfig, saveConfig: boolean = true) => {
this.modelConfigs[index] = config;
if (saveConfig)
- this.saveConfigs();
+ saveConfigs();
};
setModelConfigs = (configs: ModelConfig[], saveConfig: boolean = true) => {
this.modelConfigs = configs;
if (saveConfig)
- this.saveConfigs();
+ saveConfigs();
};
createModelConfig = (config: ModelConfig = defaultModelConfigs[0], saveConfig: boolean = true) => {
@@ -136,7 +114,7 @@ class CommonStore {
config.name = new Date().toLocaleString();
this.modelConfigs.push(config);
if (saveConfig)
- this.saveConfigs();
+ saveConfigs();
};
deleteModelConfig = (index: number, saveConfig: boolean = true) => {
@@ -151,7 +129,7 @@ class CommonStore {
this.setCurrentConfigIndex(this.modelConfigs.length - 1);
}
if (saveConfig)
- this.saveConfigs();
+ saveConfigs();
};
setModelSourceManifestList = (value: string) => {
diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts
new file mode 100644
index 0000000..52d5ad3
--- /dev/null
+++ b/frontend/src/utils/index.ts
@@ -0,0 +1,135 @@
+import {ListDirFiles, ReadJson, SaveJson} from '../../wailsjs/go/backend_golang/App';
+import manifest from '../../../manifest.json';
+import commonStore, {ModelConfig, ModelParameters, ModelSourceItem} from '../stores/commonStore';
+
+export type Cache = {
+ models: ModelSourceItem[]
+}
+
+export type LocalConfig = {
+ modelSourceManifestList: string
+ currentModelConfigIndex: number
+ modelConfigs: ModelConfig[]
+}
+
+export async function refreshBuiltInModels(readCache: boolean = false) {
+ let cache: Cache = {models: []};
+ if (readCache)
+ await ReadJson('cache.json').then((cacheData: Cache) => {
+ cache = cacheData;
+ }).catch(
+ async () => {
+ cache = {models: manifest.models};
+ }
+ );
+ else cache = {models: manifest.models};
+
+ commonStore.setModelSourceList(cache.models);
+ await saveCache().catch(() => {
+ });
+ return cache;
+}
+
+export async function refreshLocalModels(cache: Cache) {
+ cache.models = cache.models.filter(m => !m.isLocal);
+
+ await ListDirFiles(manifest.localModelDir).then((data) => {
+ cache.models.push(...data.flatMap(d => {
+ if (!d.isDir && d.name.endsWith('.pth'))
+ return [{
+ name: d.name,
+ size: d.size,
+ lastUpdated: d.modTime,
+ isLocal: true
+ }];
+ return [];
+ }));
+ }).catch(() => {
+ });
+
+ for (let i = 0; i < cache.models.length; i++) {
+ if (!cache.models[i].lastUpdatedMs)
+ cache.models[i].lastUpdatedMs = Date.parse(cache.models[i].lastUpdated);
+
+ for (let j = i + 1; j < cache.models.length; j++) {
+ if (!cache.models[j].lastUpdatedMs)
+ cache.models[j].lastUpdatedMs = Date.parse(cache.models[j].lastUpdated);
+
+ if (cache.models[i].name === cache.models[j].name) {
+ if (cache.models[i].size === cache.models[j].size) {
+ if (cache.models[i].lastUpdatedMs! < cache.models[j].lastUpdatedMs!) {
+ cache.models[i] = Object.assign({}, cache.models[i], cache.models[j]);
+ } else {
+ cache.models[i] = Object.assign({}, cache.models[j], cache.models[i]);
+ }
+ } // else is bad local file
+ cache.models.splice(j, 1);
+ j--;
+ }
+ }
+ }
+ commonStore.setModelSourceList(cache.models);
+ await saveCache().catch(() => {
+ });
+}
+
+export async function refreshRemoteModels(cache: Cache) {
+ const manifestUrls = commonStore.modelSourceManifestList.split(/[,,;;\n]/);
+ const requests = manifestUrls.filter(url => url.endsWith('.json')).map(
+ url => fetch(url, {cache: 'no-cache'}).then(r => r.json()));
+
+ await Promise.allSettled(requests)
+ .then((data: PromiseSettledResult[]) => {
+ cache.models.push(...data.flatMap(d => {
+ if (d.status === 'fulfilled')
+ return d.value.models;
+ return [];
+ }));
+ })
+ .catch(() => {
+ });
+ cache.models = cache.models.filter((model, index, self) => {
+ return model.name.endsWith('.pth')
+ && index === self.findIndex(
+ m => m.name === model.name || (m.SHA256 === model.SHA256 && m.size === model.size));
+ });
+ commonStore.setModelSourceList(cache.models);
+ await saveCache().catch(() => {
+ });
+}
+
+export const refreshModels = async (readCache: boolean = false) => {
+ const cache = await refreshBuiltInModels(readCache);
+ await refreshLocalModels(cache);
+ await refreshRemoteModels(cache);
+};
+
+export const getStrategy = (modelConfig: ModelConfig | undefined = undefined) => {
+ let params: ModelParameters;
+ if (modelConfig) params = modelConfig.modelParameters;
+ else params = commonStore.getCurrentModelConfig().modelParameters;
+ let strategy = '';
+ strategy += (params.device === 'CPU' ? 'cpu' : 'cuda') + ' ';
+ strategy += (params.precision === 'fp16' ? 'fp16' : params.precision === 'int8' ? 'fp16i8' : 'fp32');
+ if (params.storedLayers < params.maxStoredLayers)
+ strategy += ` *${params.storedLayers}+`;
+ if (params.enableHighPrecisionForLastLayer)
+ strategy += ' -> cpu fp32 *1';
+ return strategy;
+};
+
+export const saveConfigs = async () => {
+ const data: LocalConfig = {
+ modelSourceManifestList: commonStore.modelSourceManifestList,
+ currentModelConfigIndex: commonStore.currentModelConfigIndex,
+ modelConfigs: commonStore.modelConfigs
+ };
+ return SaveJson('config.json', data);
+};
+
+export const saveCache = async () => {
+ const data: Cache = {
+ models: commonStore.modelSourceList
+ };
+ return SaveJson('cache.json', data);
+};
\ No newline at end of file
diff --git a/frontend/wailsjs/go/backend_golang/App.d.ts b/frontend/wailsjs/go/backend_golang/App.d.ts
index ec0f035..3f3c108 100644
--- a/frontend/wailsjs/go/backend_golang/App.d.ts
+++ b/frontend/wailsjs/go/backend_golang/App.d.ts
@@ -2,6 +2,8 @@
// This file is automatically generated. DO NOT EDIT
import {backend_golang} from '../models';
+export function ConvertModel(arg1:string,arg2:string,arg3:string):Promise;
+
export function DownloadFile(arg1:string,arg2:string):Promise;
export function FileExists(arg1:string):Promise;
diff --git a/frontend/wailsjs/go/backend_golang/App.js b/frontend/wailsjs/go/backend_golang/App.js
index 51eb3ad..cb3b2d4 100644
--- a/frontend/wailsjs/go/backend_golang/App.js
+++ b/frontend/wailsjs/go/backend_golang/App.js
@@ -2,6 +2,10 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
+export function ConvertModel(arg1, arg2, arg3) {
+ return window['go']['backend_golang']['App']['ConvertModel'](arg1, arg2, arg3);
+}
+
export function DownloadFile(arg1, arg2) {
return window['go']['backend_golang']['App']['DownloadFile'](arg1, arg2);
}
diff --git a/manifest.json b/manifest.json
index 2d24e73..316ba15 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,6 +1,6 @@
{
"version": "1.0.0",
- "localModelPath": "models",
+ "localModelDir": "models",
"programFiles": [
{
"url": "https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/cmd-helper.bat",
@@ -18,6 +18,10 @@
"url": "https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/backend-python/global_var.py",
"path": "backend-python/global_var.py"
},
+ {
+ "url": "https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/backend-python/convert_model.py",
+ "path": "backend-python/convert_model.py"
+ },
{
"url": "https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/backend-python/routes/completion.py",
"path": "backend-python/routes/completion.py"