Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

prompt improvement, reply test fix

Dane Schneider05d3360d3326
diff --git a/server/model/context.go b/server/model/context.go
index 5ef03d94..507c374c 100644
--- a/server/model/context.go
+++ b/server/model/context.go
@@ -12,11 +12,11 @@ func FormatModelContext(context shared.ModelContext) string {
for _, part := range context {
var message string
if part.FilePath != "" {
- message = fmt.Sprintf("\n\n-file: %s\n\n```%s```", part.FilePath, part.Body)
+ message = fmt.Sprintf("\n\n- %s:\n\n```%s```", part.FilePath, part.Body)
} else if part.Url != "" {
- message = fmt.Sprintf("\n\n-url: %s\n\n```%s```", part.Url, part.Body)
+ message = fmt.Sprintf("\n\n- %s:\n\n```%s```", part.Url, part.Body)
} else {
- message = fmt.Sprintf("\n\n-content%s:\n\n```%s```", part.Name, part.Body)
+ message = fmt.Sprintf("\n\n- content%s:\n\n```%s```", part.Name, part.Body)
}
contextMessages = append(contextMessages, message)
diff --git a/server/model/proposal/create.go b/server/model/proposal/create.go
index 5b44e968..aec821ce 100644
--- a/server/model/proposal/create.go
+++ b/server/model/proposal/create.go
@@ -34,6 +34,7 @@ const systemMessageHead = `You are Plandex, an AI programming and system adminis
- lib/utils.go:
- main.py:
File paths should always come *before* the opening triple backticks of a code block. They should *not* be included in the code block itself.
+ File paths should appear *immediately* before the opening triple backticks of a code block. There should be *no other lines* between the file path and the code block. Any explanations or comments should come either *before the file path or after the code block.*
b. If not:
- Explicitly say "I will break this large task into subtasks."
- Divide the task into smaller subtasks and list them in a numbered list. Stop there.
diff --git a/server/model/summarize.go b/server/model/summarize.go
index da6ab279..1f867dac 100644
--- a/server/model/summarize.go
+++ b/server/model/summarize.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
+ "strings"
"github.com/davecgh/go-spew/spew"
"github.com/plandex/plandex/shared"
@@ -66,6 +67,11 @@ func Summarize(text string) ([]byte, error) {
for _, choice := range resp.Choices {
if choice.FinishReason == "function_call" && choice.Message.FunctionCall != nil && choice.Message.FunctionCall.Name == "summarize" {
fnCall := choice.Message.FunctionCall
+
+ if strings.HasSuffix(fnCall.Arguments, ",\n}") { // remove trailing comma
+ fnCall.Arguments = strings.TrimSuffix(fnCall.Arguments, ",\n}") + "\n}"
+ }
+
byteRes = []byte(fnCall.Arguments)
}
}
diff --git a/shared/reply.go b/shared/reply.go
index 97e8e647..59d2c8a0 100644
--- a/shared/reply.go
+++ b/shared/reply.go
@@ -81,11 +81,11 @@ func (r *replyInfo) AddChunk(chunk string) {
r.currentFilePath = r.maybeFilePath
r.maybeFilePath = ""
// fmt.Println("Confirmed file path:", r.currentFilePath) // Logging the confirmed file path
+ return
} else if prevFullLineTrimmed != "" {
// turns out previous maybeFilePath was not a file path since there's a non-empty line before finding opening ticks
r.maybeFilePath = ""
}
- return
}
if r.currentFilePath == "" {
diff --git a/shared/reply_test.go b/shared/reply_test.go
index 73bac4a5..412f0ede 100644
--- a/shared/reply_test.go
+++ b/shared/reply_test.go
@@ -32,6 +32,10 @@ var examples = []TestExample{
N: 5,
NumPaths: 2,
},
+ {
+ N: 6,
+ NumPaths: 1,
+ },
}
func TestReplyTokenCounter(t *testing.T) {
diff --git a/shared/reply_test_examples/6.md b/shared/reply_test_examples/6.md
new file mode 100644
index 00000000..979f60e3
--- /dev/null
+++ b/shared/reply_test_examples/6.md
@@ -0,0 +1,50 @@
+In the following implementation for error handling and conversation summarization in `server/model/proposal/create.go`, the changes will help anticipate any token limit errors. After collecting and formatting all the necessary context, we will check if the token number exceeds the permitted limit. If so, we will initialize a process for summarizing conversation pairs.
+
+Changes will include:
+
+- A check for the token limit before calling `CreateChatCompletionStream`
+- A mechanism to iterate through conversation pairs for summarization
+- Recursive calls of `CreateProposal` with summarized conversation, if necessary
+
+-server/model/proposal/create.go:
+
+```go
+// Add this at the start of the CreateProposal function
+const maxTokens = 8192 // The maximum tokens allowed by the model
+
+...
+
+// After preparation of the main conversation context, we add checks for tokens
+tokenNumbers := GetTokenNumber(messages) // Assuming you have a function for this
+
+if tokenNumbers > maxTokens {
+
+ // Iterate the Conversation pairs
+ for i := 1; i < len(req.Conversation)-1; i++ {
+
+ // Check if the assistant's part has been summarized before
+ if req.Conversation[i].Role == openai.ChatMessageRoleAssistant && !req.Conversation[i].Summarized {
+ // Summarize the conversation, assuming we have a function Summarize() returning summarized text
+ summarizedContent := Summarize(req.Conversation[i].Content)
+ req.Conversation[i].Content = summarizedContent
+ req.Conversation[i].Summarized = true // Mark the message as summarized
+ break
+ }
+ }
+ // Recursive call to CreateProposal after summarizing
+ err := CreateProposal(req, onStream)
+ if err != nil {
+ return fmt.Errorf("Error recreating proposal: %s\n", err)
+ }
+}
+
+...
+
+// Proceed the rest of the function as usual
+```
+
+This block of code handles the error arising from exceeding the maximum tokens supported by the model. If the tokens exceeded are detected, we start the process of summarizing conversation pairs till we are within allowed token limits. This is implemented via a recursive call to `CreateProposal`.
+
+Lastly, you should address the "superfluous response.WriteHeader call" error. This issue is usually due to an unnecessary double setting of headers in HTTP responses - HTTP headers should only be written once. The fix would involve a careful review of your HTTP response handling process ensuring that the response's headers aren't set after `WriteHeader()` has been called or body written into.
+
+Please integrate these changes into your respective function to handle the errors as described. Additional iterations might be required to fine-tune and resolve adjacent issues arising from these changes. Please also ensure your token counting and text summarization functions are accurate and performant as they play a crucial role in this error handling process.