From b36b0b71f8753acc99ec5ddab748223c21ada3f2 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Mon, 16 Oct 2023 16:31:56 -0700 Subject: [PATCH] use cut prefix --- llm/llama.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/llm/llama.go b/llm/llama.go index 1f6b7c0b..6577abbc 100644 --- a/llm/llama.go +++ b/llm/llama.go @@ -531,16 +531,14 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string, // This handles the request cancellation return ctx.Err() default: - line := scanner.Text() - if line == "" { + line := scanner.Bytes() + if len(line) == 0 { continue } - // Read data from the server-side event stream - if strings.HasPrefix(line, "data: ") { - evt := line[6:] + if evt, ok := bytes.CutPrefix(line, []byte("data: ")); ok { var p prediction - if err := json.Unmarshal([]byte(evt), &p); err != nil { + if err := json.Unmarshal(evt, &p); err != nil { return fmt.Errorf("error unmarshaling llm prediction response: %v", err) }