From 287b72639d2ae9e6daa6638622df32d86a3e541f Mon Sep 17 00:00:00 2001 From: bel Date: Sat, 17 Jun 2023 14:01:13 -0600 Subject: [PATCH] break recurse generation if current output contains a delimiter using first OR last when combined with prev if not contains --- vicuna-tools.d/main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/vicuna-tools.d/main.go b/vicuna-tools.d/main.go index 56be30d..8cc5668 100644 --- a/vicuna-tools.d/main.go +++ b/vicuna-tools.d/main.go @@ -383,8 +383,8 @@ func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePr commands[1:]..., ) command.Dir = Config.ChatBot.WD - command.Stderr = io.Discard command.Stderr = log.Writer() + command.Stderr = io.Discard stdout, err := command.StdoutPipe() if err != nil { @@ -412,11 +412,13 @@ func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePr return nil, err } justNew := oldAndNew[len(priorContent):] - idx := bytes.LastIndex( + + if idx := bytes.Index(justNew, []byte(reversePrompt)); idx > 0 { + justNew = justNew[:idx] + } else if idx := bytes.LastIndex( append(priorContent, justNew...), []byte(reversePrompt), - ) - if idx+len(reversePrompt) > len(priorContent) { + ); idx+len(reversePrompt) > len(priorContent) { justNew = justNew[:idx+len(reversePrompt)-len(priorContent)] } if err := _appendFile(inputF, string(justNew)); err != nil {