From 5dc0cff4592132635a2445ef6ed80103927e08af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20M=C3=BCller?= Date: Wed, 18 Oct 2023 08:15:27 +0200 Subject: [PATCH 1/5] fix whitespace removal --- llm/llama.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llm/llama.go b/llm/llama.go index 6577abbc..d2c6f76f 100644 --- a/llm/llama.go +++ b/llm/llama.go @@ -666,7 +666,7 @@ func (llm *llama) Decode(ctx context.Context, tokens []int) (string, error) { } // decoded content contains a leading whitespace - decoded.Content, _ = strings.CutPrefix(decoded.Content, "") + decoded.Content, _ = strings.CutPrefix(decoded.Content, " ") return decoded.Content, nil } From 90c49bed573fdc8e1c2851016edf9c957884a145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20M=C3=BCller?= Date: Wed, 18 Oct 2023 20:08:26 +0200 Subject: [PATCH 2/5] moved removal of leading space into Predict --- llm/llama.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/llm/llama.go b/llm/llama.go index d2c6f76f..97685645 100644 --- a/llm/llama.go +++ b/llm/llama.go @@ -464,6 +464,11 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string, return err } + // Remove first leading space from prevConvo if present + if len(prevConvo) > 0 && prevConvo[0] == ' ' { + prevConvo = prevConvo[1:] + } + var nextContext strings.Builder nextContext.WriteString(prevConvo) nextContext.WriteString(prompt) @@ -666,7 +671,7 @@ func (llm *llama) Decode(ctx context.Context, tokens []int) (string, error) { } // decoded content contains a leading whitespace - decoded.Content, _ = strings.CutPrefix(decoded.Content, " ") + decoded.Content, _ = strings.CutPrefix(decoded.Content, "") return decoded.Content, nil } From 46b9953f32d665010367f55362aff41b4b338a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20M=C3=BCller?= Date: Wed, 18 Oct 2023 22:41:19 +0200 Subject: [PATCH 3/5] use strings.TrimLeft to remove spaces --- llm/llama.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/llm/llama.go b/llm/llama.go index 97685645..bd5c3bb7 100644 --- a/llm/llama.go +++ b/llm/llama.go @@ -464,10 +464,8 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string, return err } - // Remove first leading space from prevConvo if present - if len(prevConvo) > 0 && prevConvo[0] == ' ' { - prevConvo = prevConvo[1:] - } + // Remove leading spaces from prevConvo if present + prevConvo = strings.TrimLeft(prevConvo, " ") var nextContext strings.Builder nextContext.WriteString(prevConvo) From ce6197a8e00cb8bc44d4fd1eb89d1b2d439ebf75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20M=C3=BCller?= Date: Wed, 18 Oct 2023 22:47:20 +0200 Subject: [PATCH 4/5] removed redundant strings.CutPrefix from Decode --- llm/llama.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/llm/llama.go b/llm/llama.go index bd5c3bb7..a51ae86e 100644 --- a/llm/llama.go +++ b/llm/llama.go @@ -668,9 +668,6 @@ func (llm *llama) Decode(ctx context.Context, tokens []int) (string, error) { return "", fmt.Errorf("unmarshal encode response: %w", err) } - // decoded content contains a leading whitespace - decoded.Content, _ = strings.CutPrefix(decoded.Content, "") - return decoded.Content, nil } From 730996e5306f50b9dd7e9159ca0f24aa22394144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20M=C3=BCller?= Date: Wed, 18 Oct 2023 22:51:30 +0200 Subject: [PATCH 5/5] use TrimPrefix instead of TrimLeft --- llm/llama.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llm/llama.go b/llm/llama.go index a51ae86e..997270a5 100644 --- a/llm/llama.go +++ b/llm/llama.go @@ -465,7 +465,7 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string, } // Remove leading spaces from prevConvo if present - prevConvo = strings.TrimLeft(prevConvo, " ") + prevConvo = strings.TrimPrefix(prevConvo, " ") var nextContext strings.Builder nextContext.WriteString(prevConvo)