try newline stuff

This commit is contained in:
Moby von Briesen 2023-05-15 19:42:17 -04:00
parent dfef07a1c0
commit be278a9162
3 changed files with 20 additions and 0 deletions

View File

@ -4,6 +4,10 @@ import (
"strings"
)
const (
newlineLiteral = "<|newline-literal|>"
)
// File represents a file in a git repository.
type File struct {
Path string
@ -56,6 +60,7 @@ func parseFiles(filesSection string) []File {
replacer := strings.NewReplacer(
"\\n", "\n",
newlineLiteral, "\\n",
"\\\"", "\"",
"```", "",
)

View File

@ -26,6 +26,11 @@ func (req DiffCommentRequest) GetPrompt() (string, error) {
return "", err
}
replacer := strings.NewReplacer(
"\\n", newlineLiteral,
)
req.File.Contents = replacer.Replace(req.File.Contents)
var result bytes.Buffer
err = tmpl.Execute(&result, req)
if err != nil {

View File

@ -27,6 +27,16 @@ func (req CodeChangeRequest) GetPrompt() (string, error) {
return "", err
}
replacer := strings.NewReplacer(
"\\n", newlineLiteral,
)
newFiles := make([]File, len(req.Files))
for i, f := range req.Files {
f.Contents = replacer.Replace(f.Contents)
newFiles[i] = f
}
req.Files = newFiles
var result bytes.Buffer
err = tmpl.Execute(&result, req)
if err != nil {