update
This commit is contained in:
parent
08e024a998
commit
80bfb09972
3
.gitignore
vendored
3
.gitignore
vendored
@ -7,4 +7,5 @@ __pycache__
|
||||
package.json.md5
|
||||
cache.json
|
||||
stats.html
|
||||
models
|
||||
*.pth
|
||||
*.bin
|
@ -2,7 +2,11 @@ package backend_golang
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/cavaliergopher/grab/v3"
|
||||
)
|
||||
@ -42,16 +46,46 @@ func (a *App) FileExists(fileName string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
func (a *App) FileInfo(fileName string) (any, error) {
|
||||
type FileInfo struct {
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
IsDir bool `json:"isDir"`
|
||||
ModTime string `json:"modTime"`
|
||||
}
|
||||
|
||||
func (a *App) ReadFileInfo(fileName string) (FileInfo, error) {
|
||||
info, err := os.Stat(fileName)
|
||||
if err != nil {
|
||||
return FileInfo{}, err
|
||||
}
|
||||
return FileInfo{
|
||||
Name: info.Name(),
|
||||
Size: info.Size(),
|
||||
IsDir: info.IsDir(),
|
||||
ModTime: info.ModTime().Format(time.RFC3339),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *App) ListDirFiles(dirPath string) ([]FileInfo, error) {
|
||||
files, err := os.ReadDir(dirPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return map[string]any{
|
||||
"name": info.Name(),
|
||||
"size": info.Size(),
|
||||
"isDir": info.IsDir(),
|
||||
}, nil
|
||||
|
||||
var filesInfo []FileInfo
|
||||
for _, file := range files {
|
||||
info, err := file.Info()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filesInfo = append(filesInfo, FileInfo{
|
||||
Name: info.Name(),
|
||||
Size: info.Size(),
|
||||
IsDir: info.IsDir(),
|
||||
ModTime: info.ModTime().Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
return filesInfo, nil
|
||||
}
|
||||
|
||||
func (a *App) DownloadFile(path string, url string) error {
|
||||
@ -61,3 +95,19 @@ func (a *App) DownloadFile(path string, url string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) OpenFileFolder(path string) error {
|
||||
switch os := runtime.GOOS; os {
|
||||
case "windows":
|
||||
cmd := exec.Command("explorer", "/select,", path)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "darwin":
|
||||
fmt.Println("Running on macOS")
|
||||
case "linux":
|
||||
fmt.Println("Running on Linux")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
)
|
||||
|
||||
func (a *App) StartServer(strategy string, modelPath string) (string, error) {
|
||||
//cmd := exec.Command(`explorer`, `/select,`, `e:\RWKV-4-Raven-7B-v10-Eng49%25-Chn50%25-Other1%25-20230420-ctx4096.pth`)
|
||||
cmd := exec.Command("cmd-helper", "python", "./backend-python/main.py", strategy, modelPath)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
|
@ -13,11 +13,12 @@ import {
|
||||
Textarea
|
||||
} from '@fluentui/react-components';
|
||||
import {ToolTipButton} from '../components/ToolTipButton';
|
||||
import {ArrowClockwise20Regular, ArrowDownload20Regular, Open20Regular} from '@fluentui/react-icons';
|
||||
import {ArrowClockwise20Regular, ArrowDownload20Regular, Folder20Regular, Open20Regular} from '@fluentui/react-icons';
|
||||
import {observer} from 'mobx-react-lite';
|
||||
import commonStore, {ModelSourceItem} from '../stores/commonStore';
|
||||
import {BrowserOpenURL} from '../../wailsjs/runtime';
|
||||
import {DownloadFile} from '../../wailsjs/go/backend_golang/App';
|
||||
import {DownloadFile, OpenFileFolder} from '../../wailsjs/go/backend_golang/App';
|
||||
import manifest from '../../../manifest.json';
|
||||
|
||||
const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
createTableColumn<ModelSourceItem>({
|
||||
@ -39,7 +40,10 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
createTableColumn<ModelSourceItem>({
|
||||
columnId: 'desc',
|
||||
compare: (a, b) => {
|
||||
return a.desc['en'].localeCompare(b.desc['en']);
|
||||
if (a.desc && b.desc)
|
||||
return a.desc['en'].localeCompare(b.desc['en']);
|
||||
else
|
||||
return 0;
|
||||
},
|
||||
renderHeaderCell: () => {
|
||||
return 'Desc';
|
||||
@ -47,7 +51,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
renderCell: (item) => {
|
||||
return (
|
||||
<TableCellLayout>
|
||||
{item.desc['en']}
|
||||
{item.desc && item.desc['en']}
|
||||
</TableCellLayout>
|
||||
);
|
||||
}
|
||||
@ -75,7 +79,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
a.lastUpdatedMs = Date.parse(a.lastUpdated);
|
||||
if (!b.lastUpdatedMs)
|
||||
b.lastUpdatedMs = Date.parse(b.lastUpdated);
|
||||
return a.lastUpdatedMs - b.lastUpdatedMs;
|
||||
return b.lastUpdatedMs - a.lastUpdatedMs;
|
||||
},
|
||||
renderHeaderCell: () => {
|
||||
return 'Last updated';
|
||||
@ -88,7 +92,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
createTableColumn<ModelSourceItem>({
|
||||
columnId: 'actions',
|
||||
compare: (a, b) => {
|
||||
return a.isDownloading ? 0 : a.isLocal ? 1 : 2;
|
||||
return a.isDownloading ? 0 : a.isLocal ? -1 : 1;
|
||||
},
|
||||
renderHeaderCell: () => {
|
||||
return 'Actions';
|
||||
@ -97,12 +101,19 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
return (
|
||||
<TableCellLayout>
|
||||
<div className="flex gap-1">
|
||||
<ToolTipButton desc="Download" icon={<ArrowDownload20Regular/>} onClick={() => {
|
||||
DownloadFile(`./models/${item.name}`, item.downloadUrl);
|
||||
}}/>
|
||||
<ToolTipButton desc="Open Url" icon={<Open20Regular/>} onClick={() => {
|
||||
BrowserOpenURL(item.url);
|
||||
}}/>
|
||||
{
|
||||
item.isLocal &&
|
||||
<ToolTipButton desc="Open Folder" icon={<Folder20Regular/>} onClick={() => {
|
||||
OpenFileFolder(`.\\${manifest.localModelPath}\\${item.name}`);
|
||||
}}/>
|
||||
}
|
||||
{item.downloadUrl && !item.isLocal &&
|
||||
<ToolTipButton desc="Download" icon={<ArrowDownload20Regular/>} onClick={() => {
|
||||
DownloadFile(`./${manifest.localModelPath}/${item.name}`, item.downloadUrl!);
|
||||
}}/>}
|
||||
{item.url && <ToolTipButton desc="Open Url" icon={<Open20Regular/>} onClick={() => {
|
||||
BrowserOpenURL(item.url!);
|
||||
}}/>}
|
||||
</div>
|
||||
</TableCellLayout>
|
||||
);
|
||||
|
@ -1,5 +1,5 @@
|
||||
import commonStore, {ModelSourceItem} from './stores/commonStore';
|
||||
import {ReadJson, SaveJson} from '../wailsjs/go/backend_golang/App';
|
||||
import {ListDirFiles, ReadJson, SaveJson} from '../wailsjs/go/backend_golang/App';
|
||||
import manifest from '../../manifest.json';
|
||||
|
||||
export async function startup() {
|
||||
@ -15,14 +15,53 @@ async function initConfig() {
|
||||
await ReadJson('cache.json').then((cacheData: Cache) => {
|
||||
cache = cacheData;
|
||||
}).catch(
|
||||
() => {
|
||||
async () => {
|
||||
cache = {models: manifest.models};
|
||||
SaveJson('cache.json', cache).catch(() => {
|
||||
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 && 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]);
|
||||
}
|
||||
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()));
|
||||
@ -40,7 +79,8 @@ async function initConfig() {
|
||||
cache.models = cache.models.filter((model, index, self) => {
|
||||
return model.name.endsWith('.pth') && index === self.findIndex(m => m.SHA256 === model.SHA256 && m.size === model.size);
|
||||
});
|
||||
// remote files
|
||||
commonStore.setModelSourceList(cache.models);
|
||||
SaveJson('cache.json', cache).catch(() => {
|
||||
await SaveJson('cache.json', cache).catch(() => {
|
||||
});
|
||||
}
|
@ -9,12 +9,12 @@ export enum ModelStatus {
|
||||
|
||||
export type ModelSourceItem = {
|
||||
name: string;
|
||||
desc: { [lang: string]: string; };
|
||||
size: number;
|
||||
lastUpdated: string;
|
||||
SHA256: string;
|
||||
url: string;
|
||||
downloadUrl: string;
|
||||
desc?: { [lang: string]: string; };
|
||||
SHA256?: string;
|
||||
url?: string;
|
||||
downloadUrl?: string;
|
||||
isLocal?: boolean;
|
||||
isDownloading?: boolean;
|
||||
lastUpdatedMs?: number;
|
||||
|
7
frontend/wailsjs/go/backend_golang/App.d.ts
vendored
7
frontend/wailsjs/go/backend_golang/App.d.ts
vendored
@ -1,11 +1,16 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
import {backend_golang} from '../models';
|
||||
|
||||
export function DownloadFile(arg1:string,arg2:string):Promise<void>;
|
||||
|
||||
export function FileExists(arg1:string):Promise<boolean>;
|
||||
|
||||
export function FileInfo(arg1:string):Promise<any>;
|
||||
export function ListDirFiles(arg1:string):Promise<Array<backend_golang.FileInfo>>;
|
||||
|
||||
export function OpenFileFolder(arg1:string):Promise<void>;
|
||||
|
||||
export function ReadFileInfo(arg1:string):Promise<backend_golang.FileInfo>;
|
||||
|
||||
export function ReadJson(arg1:string):Promise<any>;
|
||||
|
||||
|
@ -10,8 +10,16 @@ export function FileExists(arg1) {
|
||||
return window['go']['backend_golang']['App']['FileExists'](arg1);
|
||||
}
|
||||
|
||||
export function FileInfo(arg1) {
|
||||
return window['go']['backend_golang']['App']['FileInfo'](arg1);
|
||||
export function ListDirFiles(arg1) {
|
||||
return window['go']['backend_golang']['App']['ListDirFiles'](arg1);
|
||||
}
|
||||
|
||||
export function OpenFileFolder(arg1) {
|
||||
return window['go']['backend_golang']['App']['OpenFileFolder'](arg1);
|
||||
}
|
||||
|
||||
export function ReadFileInfo(arg1) {
|
||||
return window['go']['backend_golang']['App']['ReadFileInfo'](arg1);
|
||||
}
|
||||
|
||||
export function ReadJson(arg1) {
|
||||
|
23
frontend/wailsjs/go/models.ts
Normal file
23
frontend/wailsjs/go/models.ts
Normal file
@ -0,0 +1,23 @@
|
||||
export namespace backend_golang {
|
||||
|
||||
export class FileInfo {
|
||||
name: string;
|
||||
size: number;
|
||||
isDir: boolean;
|
||||
modTime: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new FileInfo(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.name = source["name"];
|
||||
this.size = source["size"];
|
||||
this.isDir = source["isDir"];
|
||||
this.modTime = source["modTime"];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"program-files": [
|
||||
"localModelPath": "models",
|
||||
"programFiles": [
|
||||
{
|
||||
"url": "https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/backend-python/main.py",
|
||||
"path": "backend-python/main.py"
|
||||
|
Loading…
Reference in New Issue
Block a user