RWKV-Runner/backend-golang/rwkv.go

29 lines
688 B
Go
Raw Normal View History

2023-05-06 23:39:23 +08:00
package backend_golang
import (
"os/exec"
2023-05-17 11:39:00 +08:00
"path/filepath"
"strconv"
2023-05-06 23:39:23 +08:00
)
2023-05-17 23:27:52 +08:00
func cmd(args ...string) (string, error) {
2023-05-17 11:39:00 +08:00
cmdHelper, err := filepath.Abs("./cmd-helper")
if err != nil {
return "", err
}
2023-05-17 23:27:52 +08:00
cmd := exec.Command(cmdHelper, args...)
2023-05-06 23:39:23 +08:00
out, err := cmd.CombinedOutput()
if err != nil {
2023-05-13 20:15:18 +08:00
return "", err
2023-05-06 23:39:23 +08:00
}
2023-05-13 20:15:18 +08:00
return string(out), nil
2023-05-06 23:39:23 +08:00
}
2023-05-17 21:20:41 +08:00
2023-05-17 23:27:52 +08:00
func (a *App) StartServer(port int) (string, error) {
return cmd("python", "./backend-python/main.py", strconv.Itoa(port))
}
2023-05-17 21:20:41 +08:00
func (a *App) ConvertModel(modelPath string, strategy string, outPath string) (string, error) {
2023-05-17 23:27:52 +08:00
return cmd("python", "./backend-python/convert_model.py", "--in", modelPath, "--out", outPath, "--strategy", strategy)
2023-05-17 21:20:41 +08:00
}