ok except caching means segfault so tahts weird
parent
a5b98e6fda
commit
9e1b252af2
|
|
@ -295,19 +295,48 @@ func handleAPIChatBotPut(w http.ResponseWriter, r *http.Request) error {
|
||||||
promptF := path.Join(sessionD, "prompt.txt")
|
promptF := path.Join(sessionD, "prompt.txt")
|
||||||
inputF := path.Join(sessionD, "input.txt")
|
inputF := path.Join(sessionD, "input.txt")
|
||||||
cacheF := path.Join(sessionD, "cache.bin")
|
cacheF := path.Join(sessionD, "cache.bin")
|
||||||
|
reversePrompt := cookie.Name + "///"
|
||||||
if err := copyFile(inputF, promptF); err != nil {
|
if err := copyFile(inputF, promptF); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := appendFile(inputF, message); err != nil {
|
if err := appendFile(inputF, reversePrompt+message); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if _, err := os.Stat(cacheF); false && os.IsNotExist(err) {
|
||||||
|
if err := func() error {
|
||||||
|
commands := strings.Fields(Config.ChatBot.Command)
|
||||||
|
commands = append(commands,
|
||||||
|
"--batch-size", "8",
|
||||||
|
"--prompt-cache", cacheF,
|
||||||
|
"-f", inputF,
|
||||||
|
"--n_predict", "1",
|
||||||
|
)
|
||||||
|
command := exec.CommandContext(
|
||||||
|
r.Context(),
|
||||||
|
commands[0],
|
||||||
|
commands[1:]...,
|
||||||
|
)
|
||||||
|
command.Dir = Config.ChatBot.WD
|
||||||
|
|
||||||
|
Config.ChatBot.semaphore.Lock()
|
||||||
|
defer Config.ChatBot.semaphore.Unlock()
|
||||||
|
|
||||||
|
if b, err := command.CombinedOutput(); err != nil {
|
||||||
|
return fmt.Errorf("error generating cache: %w: %s", err, b)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
commands := strings.Fields(Config.ChatBot.Command)
|
commands := strings.Fields(Config.ChatBot.Command)
|
||||||
commands = append(commands,
|
commands = append(commands,
|
||||||
"-f", inputF,
|
"-f", inputF,
|
||||||
"--prompt-cache-all",
|
//"--prompt-cache-all",
|
||||||
"--prompt-cache", cacheF,
|
//"--prompt-cache", cacheF,
|
||||||
"-n", strconv.Itoa(Config.ChatBot.N),
|
"-n", strconv.Itoa(Config.ChatBot.N),
|
||||||
|
"--reverse-prompt", reversePrompt,
|
||||||
)
|
)
|
||||||
command := exec.CommandContext(
|
command := exec.CommandContext(
|
||||||
r.Context(),
|
r.Context(),
|
||||||
|
|
@ -323,6 +352,7 @@ func handleAPIChatBotPut(w http.ResponseWriter, r *http.Request) error {
|
||||||
}
|
}
|
||||||
buff := bytes.NewBuffer(nil)
|
buff := bytes.NewBuffer(nil)
|
||||||
go func() {
|
go func() {
|
||||||
|
stdout.Read(make([]byte, 1))
|
||||||
io.Copy(buff, stdout)
|
io.Copy(buff, stdout)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue