From 8fa3f366ad0491d1e53fc0b2a87bb6f048b1e8ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20M=C3=BCller?= Date: Tue, 17 Oct 2023 08:17:35 +0200 Subject: [PATCH] Removed newline trimming and used buffer directly in POST request. --- llm/llama.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/llm/llama.go b/llm/llama.go index ab491291..650550aa 100644 --- a/llm/llama.go +++ b/llm/llama.go @@ -545,18 +545,15 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string, } // Handling JSON marshaling with special characters unescaped. - buf := &bytes.Buffer{} - enc := json.NewEncoder(buf) + buffer := &bytes.Buffer{} + enc := json.NewEncoder(buffer) enc.SetEscapeHTML(false) if err := enc.Encode(predReq); err != nil { return fmt.Errorf("failed to marshal data: %v", err) } - // Remove trailing newline added by Encode. - data := buf.Bytes()[:buf.Len()-1] - - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewBuffer(data)) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, buffer) if err != nil { return fmt.Errorf("error creating POST request: %v", err) }