From b89cecf89ebf372232f8a9511f5d554e1dd5e96a Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sun, 26 Nov 2023 10:43:47 +0000 Subject: [PATCH] Adjust read_file so it returns line numbers --- pkg/cli/functions.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/cli/functions.go b/pkg/cli/functions.go index c3c39f2..a882002 100644 --- a/pkg/cli/functions.go +++ b/pkg/cli/functions.go @@ -79,12 +79,15 @@ For directories, size represents the number of entries in that directory.`, "read_file": { Tool: openai.Tool{Type: "function", Function: openai.FunctionDefinition{ Name: "read_file", - Description: `Read the contents of a file relative to the current working directory. + Description: `Read the contents of a text file relative to the current working directory. -Result is returned as JSON in the following format: +Each line of the file is prefixed with its line number and a tabs (\t) to make +it make it easier to see which lines to change for other modifications. + +Example: { "message": "success", // if successful, or a different message indicating failure - "result": "the contents\nof the file\n" + "result": "1\tthe contents\n2\tof the file\n" }`, Parameters: FunctionParameters{ Type: "object", @@ -327,8 +330,15 @@ func ReadFile(path string) string { if err != nil { return resultToJson(FunctionResult{Message: fmt.Sprintf("Could not read path: %s", err.Error())}) } + + lines := strings.Split(string(data), "\n") + content := strings.Builder{} + for i, line := range lines { + content.WriteString(fmt.Sprintf("%d\t%s\n", i+1, line)) + } + return resultToJson(FunctionResult{ - Result: string(data), + Result: content.String(), }) }