RWKV-Runner/backend-golang/rwkv.go

64 lines
1.7 KiB
Go
Raw Normal View History

2023-05-06 15:39:23 +00:00
package backend_golang
import (
2023-05-20 15:34:33 +00:00
"errors"
2023-05-06 15:39:23 +00:00
"os/exec"
2023-05-27 06:40:59 +00:00
"runtime"
2023-05-17 03:39:00 +00:00
"strconv"
2023-05-06 15:39:23 +00:00
)
2023-05-24 14:03:30 +00:00
func (a *App) StartServer(port int, host string) (string, error) {
2023-05-20 15:34:33 +00:00
python, err := GetPython()
2023-05-17 03:39:00 +00:00
if err != nil {
return "", err
}
2023-05-24 14:03:30 +00:00
return Cmd(python, "./backend-python/main.py", strconv.Itoa(port), host)
2023-05-20 15:34:33 +00:00
}
func (a *App) ConvertModel(modelPath string, strategy string, outPath string) (string, error) {
python, err := GetPython()
2023-05-06 15:39:23 +00:00
if err != nil {
2023-05-13 12:15:18 +00:00
return "", err
2023-05-06 15:39:23 +00:00
}
2023-05-20 15:34:33 +00:00
return Cmd(python, "./backend-python/convert_model.py", "--in", modelPath, "--out", outPath, "--strategy", strategy)
2023-05-06 15:39:23 +00:00
}
2023-05-17 13:20:41 +00:00
2023-05-20 15:34:33 +00:00
func (a *App) DepCheck() error {
python, err := GetPython()
if err != nil {
return err
}
out, err := exec.Command(python, "./backend-python/dep_check.py").CombinedOutput()
if err != nil {
return errors.New("DepCheck Error: " + string(out))
}
return nil
2023-05-17 15:27:52 +00:00
}
2023-05-21 02:49:45 +00:00
func (a *App) InstallPyDep(cnMirror bool) (string, error) {
2023-05-20 15:34:33 +00:00
python, err := GetPython()
if err != nil {
return "", err
}
2023-05-27 06:40:59 +00:00
if runtime.GOOS == "windows" {
ChangeFileLine("./py310/python310._pth", 3, "Lib\\site-packages")
}
2023-05-21 02:49:45 +00:00
if cnMirror {
_, err = Cmd(python, "./backend-python/get-pip.py", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple")
} else {
_, err = Cmd(python, "./backend-python/get-pip.py")
}
2023-05-20 15:34:33 +00:00
if err != nil {
return "", err
}
_, err = Cmd(python, "-m", "pip", "install", "torch==1.13.1", "torchvision==0.14.1", "torchaudio==0.13.1", "--index-url", "https://download.pytorch.org/whl/cu117")
2023-05-20 15:34:33 +00:00
if err != nil {
return "", err
}
2023-05-21 02:49:45 +00:00
if cnMirror {
2023-05-21 04:18:03 +00:00
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple")
2023-05-21 02:49:45 +00:00
} else {
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_versions.txt")
}
2023-05-17 13:20:41 +00:00
}