This commit is contained in:
josc146 2023-05-18 22:48:37 +08:00
parent 18db41fd76
commit de7d6b3417
6 changed files with 38 additions and 20 deletions

View File

@ -39,12 +39,9 @@ func (a *App) ReadJson(fileName string) (any, error) {
return data, nil
}
func (a *App) FileExists(fileName string) (bool, error) {
func (a *App) FileExists(fileName string) bool {
_, err := os.Stat(fileName)
if err == nil {
return true, nil
}
return false, err
return err == nil
}
type FileInfo struct {

View File

@ -59,5 +59,6 @@
"Failed to switch model": "切换模型失败",
"Start Converting": "开始转换",
"Convert Success": "转换成功",
"Convert Failed": "转换失败"
"Convert Failed": "转换失败",
"Model Not Found": "模型不存在"
}

View File

@ -13,7 +13,7 @@ import {Page} from '../components/Page';
import {useNavigate} from 'react-router';
import {RunButton} from '../components/RunButton';
import {updateConfig} from '../apis';
import {ConvertModel} from '../../wailsjs/go/backend_golang/App';
import {ConvertModel, FileExists} from '../../wailsjs/go/backend_golang/App';
import manifest from '../../../manifest.json';
import {getStrategy, refreshLocalModels} from '../utils';
import {useTranslation} from 'react-i18next';
@ -178,17 +178,21 @@ export const Configs: FC = observer(() => {
}}/>
</div>
}/>
<ToolTipButton text={t('Convert')} desc={t('Convert model with these configs')} onClick={() => {
<ToolTipButton text={t('Convert')} desc={t('Convert model with these configs')} onClick={async () => {
const modelPath = `${manifest.localModelDir}/${selectedConfig.modelParameters.modelName}`;
const strategy = getStrategy(selectedConfig);
const newModelPath = modelPath + '-' + strategy.replace(/[> *+]/g, '-');
toast(t('Start Converting'), {autoClose: 1000, type: 'info'});
ConvertModel(modelPath, strategy, newModelPath).then(() => {
toast(`${t('Convert Success')} - ${newModelPath}`, {type: 'success'});
refreshLocalModels({models: commonStore.modelSourceList});
}).catch(e => {
toast(`${t('Convert Failed')} - ${e}`, {type: 'error'});
});
if (await FileExists(modelPath)) {
const strategy = getStrategy(selectedConfig);
const newModelPath = modelPath + '-' + strategy.replace(/[> *+]/g, '-');
toast(t('Start Converting'), {autoClose: 1000, type: 'info'});
ConvertModel(modelPath, strategy, newModelPath).then(() => {
toast(`${t('Convert Success')} - ${newModelPath}`, {type: 'success'});
refreshLocalModels({models: commonStore.modelSourceList});
}).catch(e => {
toast(`${t('Convert Failed')} - ${e}`, {type: 'error'});
});
} else {
toast(`${t('Model Not Found')} - ${modelPath}`, {type: 'error'});
}
}}/>
<Labeled label={t('Device')} content={
<Dropdown style={{minWidth: 0}} className="grow" value={selectedConfig.modelParameters.device}

View File

@ -1,8 +1,9 @@
import commonStore, {defaultModelConfigs} from './stores/commonStore';
import {ReadJson} from '../wailsjs/go/backend_golang/App';
import {LocalConfig, refreshModels} from './utils';
import {downloadProgramFiles, LocalConfig, refreshModels} from './utils';
export async function startup() {
downloadProgramFiles();
initCache();
await initConfig();
}

View File

@ -1,4 +1,4 @@
import {ListDirFiles, ReadJson, SaveJson} from '../../wailsjs/go/backend_golang/App';
import {DownloadFile, FileExists, ListDirFiles, ReadJson, SaveJson} from '../../wailsjs/go/backend_golang/App';
import manifest from '../../../manifest.json';
import commonStore, {ModelConfig, ModelParameters, ModelSourceItem} from '../stores/commonStore';
@ -160,4 +160,19 @@ export function getUserLanguage(): Language {
export function isSystemLightMode() {
return window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches;
}
export function downloadProgramFiles() {
manifest.programFiles.forEach(({url, path}) => {
FileExists(path).then(exists => {
if (!exists)
DownloadFile(path, url);
});
});
}
export function forceDownloadProgramFiles() {
manifest.programFiles.forEach(({url, path}) => {
DownloadFile(path, url);
});
}

View File

@ -3,7 +3,7 @@
"localModelDir": "models",
"programFiles": [
{
"url": "https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/cmd-helper.bat",
"url": "https://raw.githubusercontent.com/josStorer/RWKV-Runner/master/cmd-helper.bat",
"path": "cmd-helper.bat"
},
{