diff --git a/backend-golang/rwkv.go b/backend-golang/rwkv.go index 6bfd3df1..1e8cdacd 100644 --- a/backend-golang/rwkv.go +++ b/backend-golang/rwkv.go @@ -7,24 +7,33 @@ import ( "strconv" ) -func (a *App) StartServer(port int, host string) (string, error) { - python, err := GetPython() +func (a *App) StartServer(python string, port int, host string) (string, error) { + var err error + if python == "" { + python, err = GetPython() + } if err != nil { return "", err } return Cmd(python, "./backend-python/main.py", strconv.Itoa(port), host) } -func (a *App) ConvertModel(modelPath string, strategy string, outPath string) (string, error) { - python, err := GetPython() +func (a *App) ConvertModel(python string, modelPath string, strategy string, outPath string) (string, error) { + var err error + if python == "" { + python, err = GetPython() + } if err != nil { return "", err } return Cmd(python, "./backend-python/convert_model.py", "--in", modelPath, "--out", outPath, "--strategy", strategy) } -func (a *App) DepCheck() error { - python, err := GetPython() +func (a *App) DepCheck(python string) error { + var err error + if python == "" { + python, err = GetPython() + } if err != nil { return err } @@ -35,8 +44,11 @@ func (a *App) DepCheck() error { return nil } -func (a *App) InstallPyDep(cnMirror bool) (string, error) { - python, err := GetPython() +func (a *App) InstallPyDep(python string, cnMirror bool) (string, error) { + var err error + if python == "" { + python, err = GetPython() + } if err != nil { return "", err } diff --git a/frontend/src/components/RunButton.tsx b/frontend/src/components/RunButton.tsx index ffc835cc..916f4b78 100644 --- a/frontend/src/components/RunButton.tsx +++ b/frontend/src/components/RunButton.tsx @@ -59,7 +59,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean if (!commonStore.depComplete) { let depErrorMsg = ''; - await DepCheck().catch((e) => { + await DepCheck(commonStore.settings.customPythonPath).catch((e) => { depErrorMsg = e.message || e; WindowShow(); if (depErrorMsg === 'python zip not found') { @@ -71,7 +71,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean }); } else if (depErrorMsg.includes('DepCheck Error')) { toastWithButton(t('Python dependencies are incomplete, would you like to install them?'), t('Install'), () => { - InstallPyDep(commonStore.settings.cnMirror); + InstallPyDep(commonStore.settings.customPythonPath, commonStore.settings.cnMirror); setTimeout(WindowShow, 1000); }); } else { @@ -83,7 +83,8 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean return; } commonStore.setDepComplete(true); - CopyFile('./backend-python/wkv_cuda_utils/wkv_cuda_model.py', './py310/Lib/site-packages/rwkv/model.py'); + if (commonStore.platform === 'windows') + CopyFile('./backend-python/wkv_cuda_utils/wkv_cuda_model.py', './py310/Lib/site-packages/rwkv/model.py'); saveCache(); } @@ -109,7 +110,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean await exit(1000).catch(() => { }); - StartServer(port, commonStore.settings.host !== '127.0.0.1' ? '0.0.0.0' : '127.0.0.1'); + StartServer(commonStore.settings.customPythonPath, port, commonStore.settings.host !== '127.0.0.1' ? '0.0.0.0' : '127.0.0.1'); setTimeout(WindowShow, 1000); let timeoutCount = 6; @@ -137,7 +138,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean let customCudaFile = ''; if (modelConfig.modelParameters.device != 'CPU' && modelConfig.modelParameters.useCustomCuda) { customCudaFile = getSupportedCustomCudaFile(); - if (customCudaFile) { + if (customCudaFile && commonStore.platform === 'windows') { FileExists('./py310/Lib/site-packages/rwkv/model.py').then((exist) => { // defensive measure. As Python has already been launched, will only take effect the next time it runs. if (!exist) CopyFile('./backend-python/wkv_cuda_utils/wkv_cuda_model.py', './py310/Lib/site-packages/rwkv/model.py'); diff --git a/frontend/src/pages/Configs.tsx b/frontend/src/pages/Configs.tsx index 6e80e919..bb9f0333 100644 --- a/frontend/src/pages/Configs.tsx +++ b/frontend/src/pages/Configs.tsx @@ -840,7 +840,7 @@ export const Configs: FC = observer(() => { const strategy = getStrategy(selectedConfig); const newModelPath = modelPath + '-' + strategy.replace(/[:> *+]/g, '-'); toast(t('Start Converting'), { autoClose: 1000, type: 'info' }); - ConvertModel(modelPath, strategy, newModelPath).then(() => { + ConvertModel(commonStore.settings.customPythonPath, modelPath, strategy, newModelPath).then(() => { toast(`${t('Convert Success')} - ${newModelPath}`, { type: 'success' }); refreshLocalModels({ models: commonStore.modelSourceList }, false); }).catch(e => { diff --git a/frontend/wailsjs/go/backend_golang/App.d.ts b/frontend/wailsjs/go/backend_golang/App.d.ts index 28eb46ef..f90a5f51 100644 --- a/frontend/wailsjs/go/backend_golang/App.d.ts +++ b/frontend/wailsjs/go/backend_golang/App.d.ts @@ -6,13 +6,13 @@ export function AddToDownloadList(arg1:string,arg2:string):Promise; export function ContinueDownload(arg1:string):Promise; -export function ConvertModel(arg1:string,arg2:string,arg3:string):Promise; +export function ConvertModel(arg1:string,arg2:string,arg3:string,arg4:string):Promise; export function CopyFile(arg1:string,arg2:string):Promise; export function DeleteFile(arg1:string):Promise; -export function DepCheck():Promise; +export function DepCheck(arg1:string):Promise; export function DownloadFile(arg1:string,arg2:string):Promise; @@ -20,7 +20,7 @@ export function FileExists(arg1:string):Promise; export function GetPlatform():Promise; -export function InstallPyDep(arg1:boolean):Promise; +export function InstallPyDep(arg1:string,arg2:boolean):Promise; export function ListDirFiles(arg1:string):Promise>; @@ -34,6 +34,6 @@ export function ReadJson(arg1:string):Promise; export function SaveJson(arg1:string,arg2:any):Promise; -export function StartServer(arg1:number,arg2:string):Promise; +export function StartServer(arg1:string,arg2:number,arg3:string):Promise; export function UpdateApp(arg1:string):Promise; diff --git a/frontend/wailsjs/go/backend_golang/App.js b/frontend/wailsjs/go/backend_golang/App.js index 92cad3a1..5b7bc5fe 100644 --- a/frontend/wailsjs/go/backend_golang/App.js +++ b/frontend/wailsjs/go/backend_golang/App.js @@ -10,8 +10,8 @@ export function ContinueDownload(arg1) { return window['go']['backend_golang']['App']['ContinueDownload'](arg1); } -export function ConvertModel(arg1, arg2, arg3) { - return window['go']['backend_golang']['App']['ConvertModel'](arg1, arg2, arg3); +export function ConvertModel(arg1, arg2, arg3, arg4) { + return window['go']['backend_golang']['App']['ConvertModel'](arg1, arg2, arg3, arg4); } export function CopyFile(arg1, arg2) { @@ -22,8 +22,8 @@ export function DeleteFile(arg1) { return window['go']['backend_golang']['App']['DeleteFile'](arg1); } -export function DepCheck() { - return window['go']['backend_golang']['App']['DepCheck'](); +export function DepCheck(arg1) { + return window['go']['backend_golang']['App']['DepCheck'](arg1); } export function DownloadFile(arg1, arg2) { @@ -38,8 +38,8 @@ export function GetPlatform() { return window['go']['backend_golang']['App']['GetPlatform'](); } -export function InstallPyDep(arg1) { - return window['go']['backend_golang']['App']['InstallPyDep'](arg1); +export function InstallPyDep(arg1, arg2) { + return window['go']['backend_golang']['App']['InstallPyDep'](arg1, arg2); } export function ListDirFiles(arg1) { @@ -66,8 +66,8 @@ export function SaveJson(arg1, arg2) { return window['go']['backend_golang']['App']['SaveJson'](arg1, arg2); } -export function StartServer(arg1, arg2) { - return window['go']['backend_golang']['App']['StartServer'](arg1, arg2); +export function StartServer(arg1, arg2, arg3) { + return window['go']['backend_golang']['App']['StartServer'](arg1, arg2, arg3); } export function UpdateApp(arg1) {