master
bel 2023-06-17 13:58:33 -06:00
parent 4f08abbb61
commit 68a87dc3db
2 changed files with 5 additions and 4 deletions

View File

@ -328,6 +328,7 @@ func handleAPIChatBotPut(w http.ResponseWriter, r *http.Request) error {
if err != nil {
return err
}
//log.Printf("generated for %s via %s: [%s]", cookie.MyName(), r.URL.Path, justNew)
if err := os.Rename(inputF, promptF); err != nil {
return err
}
@ -382,6 +383,7 @@ func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePr
commands[1:]...,
)
command.Dir = Config.ChatBot.WD
command.Stderr = io.Discard
command.Stderr = log.Writer()
stdout, err := command.StdoutPipe()
@ -405,7 +407,6 @@ func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePr
}
oldAndNew := buff.Bytes()
log.Printf("generated: [%s]", oldAndNew)
priorContent, err := os.ReadFile(inputF)
if err != nil {
return nil, err
@ -415,14 +416,12 @@ func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePr
append(priorContent, justNew...),
[]byte(reversePrompt),
)
log.Printf("found lastindex(%d priorContent + %d newContent, %s) = %v", len(priorContent), len(justNew), reversePrompt, idx)
if idx+len(reversePrompt) > len(priorContent) {
justNew = justNew[:idx+len(reversePrompt)-len(priorContent)]
}
if err := _appendFile(inputF, string(justNew)); err != nil {
return nil, err
}
log.Printf("newly generated: [%s]", justNew)
if !bytes.HasSuffix(append(priorContent, justNew...), []byte(reversePrompt)) {
more, err := chatBotGenerateAndFillInputF(ctx, cacheF, inputF, reversePrompt)

View File

@ -36,7 +36,9 @@ func TestAPIV0ChatBot(t *testing.T) {
t.Error(string(got))
}
resp2 := httpDo(t, http.MethodPut, "/api/v0/chatbot", body().Encode())
body2 := body()
body2.Set("Message", "I don't know, boss....")
resp2 := httpDo(t, http.MethodPut, "/api/v0/chatbot", body2.Encode())
got2, err := io.ReadAll(resp2.Body)
if err != nil {
t.Fatal(err)