Pārlūkot izejas kodu

Merge pull request #833 from discovertomorrow/leadingspace

Fix Issue with Leading Whitespaces in Decoded Context
Michael Yang 1 gadu atpakaļ
vecāks
revīzija
235e43d7f6
1 mainītis faili ar 3 papildinājumiem un 3 dzēšanām
  1. 3 3
      llm/llama.go

+ 3 - 3
llm/llama.go

@@ -479,6 +479,9 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string,
 		return err
 		return err
 	}
 	}
 
 
+	// Remove leading spaces from prevConvo if present
+	prevConvo = strings.TrimPrefix(prevConvo, " ")
+
 	var nextContext strings.Builder
 	var nextContext strings.Builder
 	nextContext.WriteString(prevConvo)
 	nextContext.WriteString(prevConvo)
 	nextContext.WriteString(prompt)
 	nextContext.WriteString(prompt)
@@ -688,9 +691,6 @@ func (llm *llama) Decode(ctx context.Context, tokens []int) (string, error) {
 		return "", fmt.Errorf("unmarshal encode response: %w", err)
 		return "", fmt.Errorf("unmarshal encode response: %w", err)
 	}
 	}
 
 
-	// decoded content contains a leading whitespace
-	decoded.Content, _ = strings.CutPrefix(decoded.Content, "")
-
 	return decoded.Content, nil
 	return decoded.Content, nil
 }
 }