that kinda works api/v0/chatbot

master
bel 2023-06-17 11:04:45 -06:00
parent c0c74b3e8f
commit 26da94f6d7
1 changed files with 7 additions and 27 deletions

View File

@ -263,8 +263,8 @@ func handleAPIChatBot(w http.ResponseWriter, r *http.Request) error {
func handleAPIChatBotPost(w http.ResponseWriter, r *http.Request) error {
cookie, _ := ParseCookie(r)
sessionD := path.Join(Config.ChatBot.SessionD, cookie.Name)
if _, err := os.Stat(path.Join(sessionD, "chat.d")); err == nil {
if err := os.RemoveAll(path.Join(sessionD, "chat.d")); err != nil {
if _, err := os.Stat(path.Join(sessionD)); err == nil {
if err := os.RemoveAll(path.Join(sessionD)); err != nil {
return err
}
}
@ -363,31 +363,11 @@ func handleAPIChatBotPut(w http.ResponseWriter, r *http.Request) error {
return err
}
log.Printf("OUTPUT: %s", buff.Bytes())
return errors.New("not impl: move input to prompt")
/*
go func() {
Config.ChatBot.semaphore.Lock()
defer Config.ChatBot.semaphore.Unlock()
commands := strings.Fields(Config.ChatBot.Command)
commands = append(commands,
"-f", promptF,
"--batch_size", "8",
"--prompt-cache", cacheF,
"--file", promptF,
"--n_predict", "1",
)
command := exec.CommandContext(
r.Context(),
commands[0],
commands[1:]...,
)
command.Dir = Config.ChatBot.WD
command.Run()
}()
*/
result := bytes.TrimSuffix(buff.Bytes(), []byte(reversePrompt))
if err := os.WriteFile(promptF, result, os.ModePerm); err != nil {
return err
}
w.Write(result)
return nil
}