Skip to content

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

working on auto verification and syntax checks

Dane Schneider0b9f0e3dd9df
diff --git a/app/server/go.mod b/app/server/go.mod
index 058b617c..aa13bbf7 100644
--- a/app/server/go.mod
+++ b/app/server/go.mod
@@ -38,7 +38,7 @@ require (
github.com/golang-migrate/migrate/v4 v4.17.0
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.9
- golang.org/x/sync v0.7.0
+ github.com/smacker/go-tree-sitter v0.0.0-20240423010953-8ba036550382
)
replace github.com/plandex/plandex/shared => ../shared
diff --git a/app/server/go.sum b/app/server/go.sum
index 047431e0..434f0a11 100644
--- a/app/server/go.sum
+++ b/app/server/go.sum
@@ -87,7 +87,12 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/sashabaranov/go-openai v1.21.0 h1:isAf3zPSD3VLd0pC2/2Q6ZyRK7jzPAaz+X3rjsviaYQ=
github.com/sashabaranov/go-openai v1.21.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
+github.com/smacker/go-tree-sitter v0.0.0-20240423010953-8ba036550382 h1:Cb8njhEbNgGk5lQMM/r1FWvrKT+ysH8H0WV9NAIKAu8=
+github.com/smacker/go-tree-sitter v0.0.0-20240423010953-8ba036550382/go.mod h1:q99oHDsbP0xRwmn7Vmob8gbSMNyvJ83OauXPSuHQuKE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
@@ -98,8 +103,6 @@ golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
-golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
-golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
@@ -109,5 +112,6 @@ golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/app/server/model/plan/build_exec.go b/app/server/model/plan/build_exec.go
index e0ecefa3..6322586a 100644
--- a/app/server/model/plan/build_exec.go
+++ b/app/server/model/plan/build_exec.go
@@ -285,7 +285,7 @@ func (fileState *activeBuildStreamFileState) buildFileLineNums() {
// log.Println("currentState:", currentState)
- sysPrompt := prompts.GetBuildLineNumbersSysPrompt(filePath, originalFile, activeBuild.FileDescription, activeBuild.FileContent)
+ sysPrompt := prompts.GetBuildLineNumbersSysPrompt(filePath, originalFile, fmt.Sprintf("%s\n\n```%s```", activeBuild.FileDescription, activeBuild.FileContent))
fileMessages := []openai.ChatCompletionMessage{
{
diff --git a/app/server/model/plan/build_fix.go b/app/server/model/plan/build_fix.go
index 40b071bb..08c7da49 100644
--- a/app/server/model/plan/build_fix.go
+++ b/app/server/model/plan/build_fix.go
@@ -34,7 +34,7 @@ func (fileState *activeBuildStreamFileState) fixFileLineNums() {
log.Println("fixFileLineNums - getting file from model: " + filePath)
// log.Println("File context:", fileContext)
- sysPrompt := prompts.GetBuildFixesLineNumbersSysPrompt(activeBuild.FileDescription, activeBuild.FileContent, incorrectlyUpdated, reasoning)
+ sysPrompt := prompts.GetBuildFixesLineNumbersSysPrompt(fileState.preBuildState, fmt.Sprintf("%s\n\n```%s```", activeBuild.FileDescription, activeBuild.FileContent), incorrectlyUpdated, reasoning)
fileMessages := []openai.ChatCompletionMessage{
{
diff --git a/app/server/model/plan/build_fix_stream.go b/app/server/model/plan/build_fix_stream.go
index 1bf39c38..994cf371 100644
--- a/app/server/model/plan/build_fix_stream.go
+++ b/app/server/model/plan/build_fix_stream.go
@@ -23,7 +23,6 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *open
currentOrgId := fileState.currentOrgId
planId := fileState.plan.Id
branch := fileState.branch
- activeBuild := fileState.activeBuild
activePlan := GetActivePlan(planId, branch)
@@ -174,17 +173,16 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *open
overlapStrategy = OverlapStrategySkip
}
- planFileResult, _, allSucceeded, err := getPlanResult(
- planResultParams{
- orgId: currentOrgId,
- planId: planId,
- planBuildId: build.Id,
- convoMessageId: build.ConvoMessageId,
- filePath: filePath,
- preBuildState: fileState.updated,
- fileContent: activeBuild.FileContent,
- streamedChangesWithLineNums: streamed.Changes,
- overlapStrategy: overlapStrategy,
+ planFileResult, _, allSucceeded, err := GetPlanResult(
+ PlanResultParams{
+ OrgId: currentOrgId,
+ PlanId: planId,
+ PlanBuildId: build.Id,
+ ConvoMessageId: build.ConvoMessageId,
+ FilePath: filePath,
+ PreBuildState: fileState.updated,
+ StreamedChangesWithLineNums: streamed.Changes,
+ OverlapStrategy: overlapStrategy,
},
)
diff --git a/app/server/model/plan/build_result.go b/app/server/model/plan/build_result.go
index 578c9290..38f33158 100644
--- a/app/server/model/plan/build_result.go
+++ b/app/server/model/plan/build_result.go
@@ -18,31 +18,28 @@ const (
OverlapStrategyError
)
-type planResultParams struct {
- orgId string
- planId string
- planBuildId string
- convoMessageId string
- filePath string
- preBuildState string
- fileContent string
- overlapStrategy OverlapStrategy
- streamedChangesWithLineNums []*shared.StreamedChangeWithLineNums
+type PlanResultParams struct {
+ OrgId string
+ PlanId string
+ PlanBuildId string
+ ConvoMessageId string
+ FilePath string
+ PreBuildState string
+ OverlapStrategy OverlapStrategy
+ StreamedChangesWithLineNums []*shared.StreamedChangeWithLineNums
}
-func getPlanResult(params planResultParams) (*db.PlanFileResult, string, bool, error) {
- orgId := params.orgId
- planId := params.planId
- planBuildId := params.planBuildId
- filePath := params.filePath
- preBuildState := params.preBuildState
- streamedChangesWithLineNums := params.streamedChangesWithLineNums
- // fileContent := params.fileContent
+func GetPlanResult(params PlanResultParams) (*db.PlanFileResult, string, bool, error) {
+ orgId := params.OrgId
+ planId := params.PlanId
+ planBuildId := params.PlanBuildId
+ filePath := params.FilePath
+ preBuildState := params.PreBuildState
+ streamedChangesWithLineNums := params.StreamedChangesWithLineNums
preBuildState = shared.AddLineNums(preBuildState)
preBuildStateLines := strings.Split(preBuildState, "\n")
- // fileContentLines := strings.Split(fileContent, "\n")
// log.Printf("\n\ngetPlanResult - path: %s\n", filePath)
// log.Println("getPlanResult - preBuildState:")
@@ -93,7 +90,7 @@ func getPlanResult(params planResultParams) (*db.PlanFileResult, string, bool, e
if startLine < highestEndLine {
log.Printf("Start line is less than highestEndLine: %d < %d\n", startLine, highestEndLine)
- if params.overlapStrategy == OverlapStrategyError {
+ if params.OverlapStrategy == OverlapStrategyError {
return nil, "", false, fmt.Errorf("start line is less than highestEndLine: %d < %d", startLine,
highestEndLine)
} else {
@@ -102,7 +99,7 @@ func getPlanResult(params planResultParams) (*db.PlanFileResult, string, bool, e
}
if endLine < highestEndLine {
- if params.overlapStrategy == OverlapStrategyError {
+ if params.OverlapStrategy == OverlapStrategyError {
log.Printf("End line is less than highestEndLine: %d < %d\n", endLine, highestEndLine)
return nil, "", false, fmt.Errorf("end line is less than highestEndLine: %d < %d", endLine, highestEndLine)
} else {
@@ -164,7 +161,7 @@ func getPlanResult(params planResultParams) (*db.PlanFileResult, string, bool, e
OrgId: orgId,
PlanId: planId,
PlanBuildId: planBuildId,
- ConvoMessageId: params.convoMessageId,
+ ConvoMessageId: params.ConvoMessageId,
Content: "",
Path: filePath,
Replacements: replacements,
diff --git a/app/server/model/plan/build_stream_line_nums.go b/app/server/model/plan/build_stream_line_nums.go
index 6fd2d356..57a34784 100644
--- a/app/server/model/plan/build_stream_line_nums.go
+++ b/app/server/model/plan/build_stream_line_nums.go
@@ -24,7 +24,6 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str
planId := fileState.plan.Id
branch := fileState.branch
preBuildState := fileState.preBuildState
- activeBuild := fileState.activeBuild
activePlan := GetActivePlan(planId, branch)
@@ -136,17 +135,16 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str
overlapStrategy = OverlapStrategySkip
}
- planFileResult, updatedFile, allSucceeded, err := getPlanResult(
- planResultParams{
- orgId: currentOrgId,
- planId: planId,
- planBuildId: build.Id,
- convoMessageId: build.ConvoMessageId,
- filePath: filePath,
- preBuildState: preBuildState,
- fileContent: activeBuild.FileContent,
- streamedChangesWithLineNums: streamed.Changes,
- overlapStrategy: overlapStrategy,
+ planFileResult, updatedFile, allSucceeded, err := GetPlanResult(
+ PlanResultParams{
+ OrgId: currentOrgId,
+ PlanId: planId,
+ PlanBuildId: build.Id,
+ ConvoMessageId: build.ConvoMessageId,
+ FilePath: filePath,
+ PreBuildState: preBuildState,
+ StreamedChangesWithLineNums: streamed.Changes,
+ OverlapStrategy: overlapStrategy,
},
)
diff --git a/app/server/model/plan/build_verify.go b/app/server/model/plan/build_verify.go
index 6dad012a..07dbe801 100644
--- a/app/server/model/plan/build_verify.go
+++ b/app/server/model/plan/build_verify.go
@@ -35,7 +35,9 @@ func (fileState *activeBuildStreamFileState) verifyFileBuild() {
// log.Printf("activeBuild.FileDescription has content: %v\n", activeBuild.FileDescription != "")
// log.Printf("activeBuild.FileContent has content: %v\n", activeBuild.FileContent != "")
- sysPrompt := prompts.GetVerifyPrompt(preBuildState, updated, activeBuild.FileDescription, activeBuild.FileContent)
+ sysPrompt := prompts.GetVerifyPrompt(preBuildState, updated,
+ fmt.Sprintf("%s\n\n```%s```", activeBuild.FileDescription, activeBuild.FileContent),
+ )
log.Println("verify sysPrompt:\n", sysPrompt)
diff --git a/app/server/model/plan/build_verify_stream.go b/app/server/model/plan/build_verify_stream.go
index e826cf70..5a1c9299 100644
--- a/app/server/model/plan/build_verify_stream.go
+++ b/app/server/model/plan/build_verify_stream.go
@@ -140,7 +140,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op
log.Printf("listenStreamVerifyOutput - File %s: Parsed streamed verify result\n", filePath)
// spew.Dump(streamed)
- if streamed.IsCorrect {
+ if streamed.IsCorrect() {
buildInfo := &shared.BuildInfo{
Path: filePath,
NumTokens: 0,
@@ -153,9 +153,10 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op
log.Println("build verify - streamed.IsCorrect")
fileState.onFinishBuildFile(nil)
} else {
- log.Printf("listenStreamVerifyOutput - File %s: Streamed verify result is incorrect: %s\n", filePath, streamed.Reasoning)
- fileState.incorrectlyUpdatedReasoning = streamed.Reasoning
+ log.Printf("listenStreamVerifyOutput - File %s: Streamed verify result is incorrect\n", filePath)
+
+ fileState.incorrectlyUpdatedReasoning = streamed.GetReasoning()
select {
case <-activePlan.Ctx.Done():
diff --git a/app/server/model/prompts/build.go b/app/server/model/prompts/build.go
index cb26d0e3..d8f4806e 100644
--- a/app/server/model/prompts/build.go
+++ b/app/server/model/prompts/build.go
@@ -8,7 +8,7 @@ import (
"github.com/sashabaranov/go-openai/jsonschema"
)
-func GetBuildLineNumbersSysPrompt(filePath, preBuildState, desc, changes string) string {
+func GetBuildLineNumbersSysPrompt(filePath, preBuildState, changes string) string {
// hash := sha256.Sum256([]byte(currentState))
// sha := hex.EncodeToString(hash[:])
@@ -16,26 +16,22 @@ func GetBuildLineNumbersSysPrompt(filePath, preBuildState, desc, changes string)
preBuildStateWithLineNums := shared.AddLineNums(preBuildState)
- return getListChangesLineNumsPrompt() + "\n\n" + getPreBuildStatePrompt(filePath, preBuildStateWithLineNums) + "\n\n" + getBuildPromptWithLineNums(desc, changes)
+ return getListChangesLineNumsPrompt() + "\n\n" + getPreBuildStatePrompt(filePath, preBuildStateWithLineNums) + "\n\n" + getBuildPromptWithLineNums(changes)
}
-func GetBuildFixesLineNumbersSysPrompt(desc, changes, updated, reasoning string) string {
+func GetBuildFixesLineNumbersSysPrompt(original, changes, updated, reasoning string) string {
// hash := sha256.Sum256([]byte(updated))
// sha := hex.EncodeToString(hash[:])
// log.Println("GetBuildFixesLineNumbersSysPrompt updated sha:", sha)
updatedWithLineNums := shared.AddLineNums(updated)
- return getFixChangesLineNumsPrompt() + "\n\n" + getBuildPromptForFixesWithLineNums(desc, changes, updatedWithLineNums, reasoning)
+ return getFixChangesLineNumsPrompt() + "\n\n" + getBuildPromptForFixesWithLineNums(original, changes, updatedWithLineNums, reasoning)
}
-func getBuildPromptWithLineNums(desc, changes string) string {
+func getBuildPromptWithLineNums(changes string) string {
s := ""
- if desc != "" {
- s += "Description of the proposed updates from AI-generated plan:\n```\n" + desc + "\n```\n\n"
- }
-
s += "Proposed updates:\n```\n" + changes + "\n```"
s += "\n\n" + "Now call the 'listChangesWithLineNums' function with a valid JSON array of changes according to your instructions. You must always call 'listChangesWithLineNums' with one or more valid changes. Don't call any other function."
@@ -43,16 +39,16 @@ func getBuildPromptWithLineNums(desc, changes string) string {
return s
}
-func getBuildPromptForFixesWithLineNums(desc, changes, updated, reasoning string) string {
+func getBuildPromptForFixesWithLineNums(original, changes, updated, reasoning string) string {
s := ""
- if desc != "" {
- s += "Description of the proposed updates from AI-generated plan:\n```\n" + desc + "\n```\n\n"
+ if original != "" {
+ s += "**Original file:**\n```\n" + original + "\n```"
}
- s += "Proposed updates:\n```\n" + changes + "\n```"
+ s += "**Proposed updates**:\n```\n" + changes + "\n```"
- s += fmt.Sprintf("**The incorrect updated file is:**\n```\n%s\n```\n\n**The problems with the file are:**\n\n%s", updated, reasoning)
+ s += fmt.Sprintf("**The incorrectly updated file is:**\n```\n%s\n```\n\n**The problems with the file are:**\n\n%s", updated, reasoning)
s += "\n\n" + "Now call the 'listChangesWithLineNums' function with a valid JSON array of changes according to your instructions. You must always call 'listChangesWithLineNums' with one or more valid changes. Don't call any other function."
@@ -71,9 +67,7 @@ const replacementIntro = `
You are an AI that analyzes a code file and an AI-generated plan to update the code file and produces a list of changes.
`
-const lineNumsFunctionCallPrompt = `
-Call the 'listChangesWithLineNums' function with a valid JSON object that includes the 'changes' keys.
-
+const changesKeyPrompt = `
'changes': An array of NON-OVERLAPPING changes. Each change is an object with properties: 'summary', 'hasChange', 'old', 'startLineIncludedReasoning', 'startLineIncluded', 'endLineIncludedReasoning', 'endLineIncluded', and 'new'.
Note: all line numbers that are used below are prefixed with 'pdx-', like this 'pdx-5: for i := 0; i < 10; i++ {'. This is to help you identify the line numbers in the file. You *must* include the 'pdx-' prefix in the line numbers in the 'old' property.
@@ -138,7 +132,7 @@ Changes must be ordered in the array according to the order they appear in the f
const changeRulesPrompt = `
Apply changes intelligently in order to avoid syntax errors, breaking code, or removing code from the original file that should not be removed. Consider the reason behind the update and make sure the result is consistent with the intention of the plan.
-You ABSOLUTELY MUST NOT overwrite or delete code from the original file unless the plan *clearly intends* for the code to be overwritten or removed. Do NOT replace a full section of code with only new code unless that is the clear intention of the plan. Instead, merge the original code and the proposed changes together intelligently according to the intention of the plan.
+You ABSOLUTELY MUST NOT overwrite or delete code from the original file unless the plan *clearly intends* for the code to be overwritten or removed. Do NOT replace a full section of code with only new code unless that is the clear intention of the plan. Instead, merge the original code and the proposed updates together intelligently according to the intention of the plan.
Pay *EXTREMELY close attention* to opening and closing brackets, parentheses, and braces. Never leave them unbalanced when the changes are applied. Also pay *EXTREMELY close attention* to newlines and indentation. Make sure that the indentation of the new code is consistent with the indentation of the original code, and syntactically correct.
`
@@ -152,7 +146,10 @@ func getListChangesLineNumsPrompt() string {
return replacementIntro + `
[YOUR INSTRUCTIONS]
- ` + lineNumsFunctionCallPrompt + `
+
+ Call the 'listChangesWithLineNums' function with a valid JSON object that includes the 'changes' keys.
+
+ ` + changesKeyPrompt + `
` + summaryChangePrompt + `
@@ -185,10 +182,12 @@ func getListChangesLineNumsPrompt() string {
func getFixChangesLineNumsPrompt() string {
return `
- You are an AI that analyzes an incorrect updated file, the changes that should have been applied to the file, a description of the problems with the file, and a plan to fix them, and then produces a list of changes to apply to the *incorrect updated file* that will fix *ALL* the problems.
+ You are an AI that analyzes an original file (if present), an incorrectly updated file, the changes that were proposed, and a description of the problems with the file, and then produces a list of changes to apply to the *incorrectly updated file* that will fix *ALL* the problems.
Problems you MUST fix include:
- - Syntax errors
+ - Syntax errors, including unbalanced brackets, parentheses, braces, quotes, indentation, and other code structure errors
+ - Missing or incorrectly scoped declarations
+ - Any other errors that make the code invalid and would prevent it from being run as-is for the programming language being used
- Incorrectly applied changes
- Incorrectly removed code
- Incorrectly overwritten code
@@ -198,7 +197,13 @@ func getFixChangesLineNumsPrompt() string {
If the updated includes references to the original code in comments like "// rest of the function..." or "# existing init code...", or "// rest of the main function..." or "// rest of your function..." or "// Existing methods..." **any other reference to the original code, the file is incorrect. References like these must be handled by including the exact code from the original file that the comment is referencing.
[YOUR INSTRUCTIONS]
- ` + lineNumsFunctionCallPrompt + `
+ Call the 'listChangesWithLineNums' function with a valid JSON object that includes the 'problems' and 'changes' keys.
+
+ 'problems': A string that describes all problems present within the updated file. Explain the cause of each problem and how it should be fixed. Do not just restate that there is a syntax error on a specific line. Explain what the syntax error is and how to fix it. Be exhaustive and include *every* problem that is present in the file.
+
+ Since you are fixing an incorrectly updated file, you *MUST* include the 'problems' key and you *MUST* describe *all* problems present in the file. If you cannot identify any problems immediately, output a few hypotheses about what might be wrong and then explain which of them are actually present in the file. The file definitely does have problems, so you *must* identify them.
+
+ ` + changesKeyPrompt + `
` + summaryChangePrompt + `
@@ -208,6 +213,8 @@ func getFixChangesLineNumsPrompt() string {
You MUST ensure the line numbers for the 'old' property correctly remove *ALL* code that has problems and that the 'new' property correctly fixes *ALL* the problems present in the updated file. You MUST NOT miss any problems, fail to fix any problems, or introduce any new problems.
+ Because you are implementing a fix, be more willing to make larger changes in order to fix all the problems. Smaller changes are more error-prone, and the fact that you are fixing a file means a line-number based change already failed. This likely means there was some tricky structural challenge in applying the changes with line numbers, so be prepared to make a larger change in order to avoid continuing to fail to fix the file.
+
Example function call with all keys:
---
listChangesWithLineNums([{
@@ -235,6 +242,9 @@ var ListReplacementsFn = openai.FunctionDefinition{
Parameters: &jsonschema.Definition{
Type: jsonschema.Object,
Properties: map[string]jsonschema.Definition{
+ "problems": {
+ Type: jsonschema.String,
+ },
"changes": {
Type: jsonschema.Array,
Items: &jsonschema.Definition{
@@ -291,19 +301,39 @@ var ListReplacementsFn = openai.FunctionDefinition{
},
}
-func GetVerifyPrompt(preBuildState, updated, desc, changes string) string {
+func GetVerifyPrompt(preBuildState, updated, changes string) string {
s := `
-Based on an original file (if one exists), an AI-generated plan, and an updated file, determine whether the proposed changes were applied correctly to the updated file. Is the syntax in the updated file correct? Were the changes applied correctly or was some code from the original file removed or overwritten that should not have been? Does the updated file as a whole make sense and was it updated consistently with the intention of the plan? Were *all* comments in the proposed changes that referenced the original code correctly handled in the updated file by including the exact code from the original file that the comment was referencing? Did any code get duplicated that should not have been?
+Based on an original file (if one exists), an AI-generated plan, and an updated file, determine whether the updated file's syntax is correct and whether the proposed updates were applied correctly to the updated file.
-If the updated includes references to the original code in comments like "// rest of the function..." or "# existing init code...", or "// rest of the main function..." or "// rest of your function..." or "// Existing methods...", "// Existing code..." **any other reference to the original code**, the file is incorrect. References like these must be handled by including the exact code from the original file that the comment is referencing.
+You must consider whether any of the following problems are present in the updated file:
+- Syntax errors, including unbalanced brackets, parentheses, braces, quotes, indentation, and other code structure errors
+- Missing or incorrectly scoped declarations
+- Any other errors that make the code invalid and would prevent it from being run as-is for the programming language being used
+- Code from the original file was incorrectly removed or overwritten.
+- Code was incorrectly duplicated. For example, if a file should have a single main function, but instead of updating the existing main function, the updated file includes multiple main functions, then the file is incorrect. The same applies to any other functions or elements that should not be duplicated.
+- Incorrectly included comments that reference the original code.. If the updated file includes comments like "// rest of the function..." or "# existing init code...", or "// rest of the main function..." or "// rest of your function..." or "// Existing methods...", "// Existing code..." **any other reference to the original code**, the file is incorrect. References like these must be handled by including the exact code from the original file that the comment is referencing.
If there is no original file, it means that a new file was created from scratch based on the AI-generated plan. In this case, the syntax in the new file must be valid and consistent with the intention of the plan. You must ensure there are no syntax errors or other clear mistakes in the new file.
-Call the 'verifyOutput' function with a valid JSON object that include the 'reasoning' and 'isCorrect' keys.
+Call the 'verifyOutput' function with a valid JSON object that include the following keys:
+
+'syntaxErrorsReasoning': A string that succinctly explains whether there are any syntax or scoping errors in the updated file. Explain all syntax errors, scoping errors, or other code structure errors that are present in the updated file.
+
+'hasSyntaxErrors': A boolean that indicates whether there are any syntax errors in the updated file, based on the reasoning provided in 'syntaxErrorsReasoning'.
-'reasoning': Succinctly explain whether the proposed changes were or were not applied correctly and whether the syntax is valid. If the changes were not applied correctly or the syntax isn't valid, list *EVERY* problem and what needs to be done to fix *ALL* the errors. If the syntax isn't valid only because the syntax wasn't valid in the original file, explain that the syntax, though incorrect, is consistent with the original file and that the changes were applied correctly.
+'removedCodeErrorsReasoning': A string that succinctly explains whether any code was incorrectly removed or overwritten in the updated file. First explain whether any code was removed or overwritten, then explain whether the removal or overwriting was deliberate and consistent with the plan.
-'isCorrect': A boolean that indicates whether the proposed changes were applied correctly. If the proposed changes were applied correctly, set 'isCorrect' to true. If the proposed changes were not applied correctly, set 'isCorrect' to false.
+'hasRemovedCodeErrors': A boolean that indicates whether any code was *incorrectly* removed or overwritten in the updated file, based on the reasoning provided in 'removedCodeErrorsReasoning'. If code was *incorrectly* removed or overwritten, set 'hasRemovedCodeErrors' to true. If code was *correctly* removed or overwritten, consistent with the intention of the plan, set 'hasRemovedCodeErrors' to false.
+
+'duplicationErrorsReasoning': A string that succinctly explains whether any code was *incorrectly* duplicated in the updated file. First explain whether any code, functions, or other elements are duplicated in the updated file, then explain whether the duplication is deliberate and consistent with the plan, and whether the duplication is correct and valid in the programming language being used.
+
+'hasDuplicationErrors': A boolean that indicates whether any code was *incorrectly* duplicated in the updated file, based on the reasoning provided in 'duplicationErrorsReasoning'. If code was *incorrectly* duplicated, set 'hasDuplicationErrors' to true. If code was *correctly* duplicated, consistent with the intention of the plan, set 'hasDuplicationErrors' to false.
+
+'referenceErrorsReasoning': A string that succinctly explains whether any comments in the updated file are placeholders/references that should have been replaced with code from the original file. These are comments like "// rest of the function..." or "# existing init code...", or "// rest of the main function..." or "// rest of your function..." or "// Existing methods...", "// Existing code..." or other comments which reference code from the original file. Only include comments that *are not* present in the original file and *are* present in the proposed updates. If there are no such comments, explain that there are no reference errors.
+
+'hasReferenceErrors': A boolean that indicates whether any comments in the updated file are placeholders/references that should be replaced with code from the original file, based on the reasoning provided in 'referenceErrorsReasoning'.
+
+In each of the reasoning keys above, be exhaustive and include *every* problem that is present in the file. But if there are no problems in a reasoning key, do NOT invent problems--explain according to your instructions for each key that there are no problems in that category.
`
if preBuildState != "" {
@@ -319,12 +349,6 @@ Call the 'verifyOutput' function with a valid JSON object that include the 'reas
}
s += `
-## **Description of the proposed updates from AI-generated plan:**
-
-` + desc + `
-
---
-
## **Proposed updates:**
` + changes + `
@@ -357,90 +381,32 @@ var VerifyOutputFn = openai.FunctionDefinition{
Parameters: &jsonschema.Definition{
Type: jsonschema.Object,
Properties: map[string]jsonschema.Definition{
- "reasoning": {
+ "syntaxErrorsReasoning": {
+ Type: jsonschema.String,
+ },
+ "hasSyntaxErrors": {
+ Type: jsonschema.Boolean,
+ },
+ "removedCodeErrorsReasoning": {
Type: jsonschema.String,
},
- "isCorrect": {
+ "hasRemovedCodeErrors": {
+ Type: jsonschema.Boolean,
+ },
+ "duplicationErrorsReasoning": {
+ Type: jsonschema.String,
+ },
+ "hasDuplicationErrors": {
+ Type: jsonschema.Boolean,
+ },
+ "referenceErrorsReasoning": {
+ Type: jsonschema.String,
+ },
+ "hasReferenceErrors": {
Type: jsonschema.Boolean,
},
},
+ Required: []string{"syntaxErrorsReasoning", "hasSyntaxErrors",
+ "removedCodeErrorsReasoning", "hasRemovedCodeErrors", "duplicationErrorsReasoning", "hasDuplicationErrors", "referenceErrorsReasoning", "hasReferenceErrors"},
},
}
-
-// Saving the prompts below to maybe take a stab at full replacements in the future -- not robust enough for now
-
-// func GetBuildFullChangesSysPrompt(filePath, currentState, desc, changes string) string {
-
-// return fullChangesPrompt + "\n\n" + getBuildCurrentStatePrompt(filePath, currentState) + "\n\n" + getBuildPromptWithFullChanges(desc, changes)
-// }
-
-// func getBuildPromptWithFullChanges(desc, changes string) string {
-// s := ""
-
-// if desc != "" {
-// s += "Description of the proposed updates from AI-generated plan:\n```\n" + desc + "\n```\n\n"
-// }
-
-// s += "Proposed updates:\n```\n" + changes + "\n```"
-
-// s += "\n\n" + "Now call the 'listChangesFull' function with a valid JSON array of changes according to your instructions. You must always call 'listChangesFull' with one or more valid changes. Don't call any other function."
-
-// return s
-// }
-
-// var ListReplacementsFullFn = openai.FunctionDefinition{
-// Name: "listChangesFull",
-// Parameters: &jsonschema.Definition{
-// Type: jsonschema.Object,
-// Properties: map[string]jsonschema.Definition{
-// "changes": {
-// Type: jsonschema.Array,
-// Items: &jsonschema.Definition{
-// Type: jsonschema.Object,
-// Properties: map[string]jsonschema.Definition{
-// "summary": {
-// Type: jsonschema.String,
-// },
-// "old": {
-// Type: jsonschema.String,
-// },
-// "new": {
-// Type: jsonschema.String,
-// },
-// },
-// Required: []string{"summary", "old", "new"},
-// },
-// },
-// },
-// Required: []string{"changes"},
-// },
-// }
-
-// const fullChangesPrompt = replacementIntro + `
-
-// [YOUR INSTRUCTIONS]
-// Call the 'listChangesFull' function with a valid JSON object that includes the 'changes' keys.
-
-// 'changes': An array of NON-OVERLAPPING changes. Each change is an object with properties: 'summary', 'old', and 'new'.
-
-// ` + summaryPrompt + `
-
-// The 'old' property is the *exact* old text to replace. 'old' must be an EXACT SUBSTRING of the original file. 'old' *must only include entire lines and *no partial lines*. Pay *extremely* close attention to quotes, indentation, newlines, spaces and special characters. All double quotes inside 'old' MUST ALWAYS be escaped with a backslash. Apart from escaped double quotes, the 'old' property must be an exact match of the original code that will be replaced. 'old' must be large enough to be *unique and unambiguous* within the file. If the 'old' property occurs in multiple places in the file, you must include enough context to ensure that the 'old' property is unambiguous. Expand 'old' as necessary. 'old' must be an *exact* match of the original code that will be replaced.
-
-// ` + changeNewPrompt + `
-
-// Example function call with all keys:
-// ---
-// listChangesFull([{
-// summary: "Insert function ExecQuery after GetResults function in loop body.",
-// old: " GetResults()\n }\n }\n }",
-// new: " GetResults()\n execQuery()\n }\n }\n}",
-// }])
-// ---
-
-// ` + changeRulesPrompt + `
-
-// The 'listChangesFull' function MUST be called *valid JSON*. Double quotes within json properties of the 'listChangesFull' function call parameters JSON object *must be properly escaped* with a backslash.
-
-// [END YOUR INSTRUCTIONS]
-// `
diff --git a/app/server/syntax/parsers.go b/app/server/syntax/parsers.go
new file mode 100644
index 00000000..f9387a12
--- /dev/null
+++ b/app/server/syntax/parsers.go
@@ -0,0 +1,165 @@
+package syntax
+
+import (
+ tree_sitter "github.com/smacker/go-tree-sitter"
+ "github.com/smacker/go-tree-sitter/bash"
+ "github.com/smacker/go-tree-sitter/c"
+ "github.com/smacker/go-tree-sitter/cpp"
+ "github.com/smacker/go-tree-sitter/csharp"
+ "github.com/smacker/go-tree-sitter/css"
+ "github.com/smacker/go-tree-sitter/cue"
+ "github.com/smacker/go-tree-sitter/dockerfile"
+ "github.com/smacker/go-tree-sitter/elixir"
+ "github.com/smacker/go-tree-sitter/elm"
+ "github.com/smacker/go-tree-sitter/golang"
+ "github.com/smacker/go-tree-sitter/groovy"
+ "github.com/smacker/go-tree-sitter/hcl"
+ "github.com/smacker/go-tree-sitter/html"
+ "github.com/smacker/go-tree-sitter/java"
+ "github.com/smacker/go-tree-sitter/javascript"
+ "github.com/smacker/go-tree-sitter/kotlin"
+ "github.com/smacker/go-tree-sitter/lua"
+ "github.com/smacker/go-tree-sitter/ocaml"
+ "github.com/smacker/go-tree-sitter/php"
+ "github.com/smacker/go-tree-sitter/protobuf"
+ "github.com/smacker/go-tree-sitter/python"
+ "github.com/smacker/go-tree-sitter/ruby"
+ "github.com/smacker/go-tree-sitter/rust"
+ "github.com/smacker/go-tree-sitter/scala"
+ "github.com/smacker/go-tree-sitter/svelte"
+ "github.com/smacker/go-tree-sitter/swift"
+ "github.com/smacker/go-tree-sitter/toml"
+ "github.com/smacker/go-tree-sitter/typescript/tsx"
+ "github.com/smacker/go-tree-sitter/typescript/typescript"
+ "github.com/smacker/go-tree-sitter/yaml"
+)
+
+func getParserForExt(ext string) (*tree_sitter.Parser, string, *tree_sitter.Parser, string) {
+ lang, ok := languageByExtension[ext]
+ if !ok {
+ return nil, "", nil, ""
+ }
+
+ parser := getParserForLanguage(lang)
+
+ fallback := fallbackByExtension[ext]
+ var fallbackParser *tree_sitter.Parser
+ if fallback != "" {
+ fallbackParser = getParserForLanguage(fallback)
+ }
+
+ return parser, lang, fallbackParser, fallback
+}
+
+func getParserForLanguage(lang string) *tree_sitter.Parser {
+ parser := tree_sitter.NewParser()
+ switch lang {
+ case "bash":
+ parser.SetLanguage(bash.GetLanguage())
+ case "c":
+ parser.SetLanguage(c.GetLanguage())
+ case "cpp":
+ parser.SetLanguage(cpp.GetLanguage())
+ case "csharp":
+ parser.SetLanguage(csharp.GetLanguage())
+ case "css":
+ parser.SetLanguage(css.GetLanguage())
+ case "cue":
+ parser.SetLanguage(cue.GetLanguage())
+ case "dockerfile":
+ parser.SetLanguage(dockerfile.GetLanguage())
+ case "elixir":
+ parser.SetLanguage(elixir.GetLanguage())
+ case "elm":
+ parser.SetLanguage(elm.GetLanguage())
+ case "go":
+ parser.SetLanguage(golang.GetLanguage())
+ case "groovy":
+ parser.SetLanguage(groovy.GetLanguage())
+ case "hcl":
+ parser.SetLanguage(hcl.GetLanguage())
+ case "html":
+ parser.SetLanguage(html.GetLanguage())
+ case "java":
+ parser.SetLanguage(java.GetLanguage())
+ case "javascript":
+ parser.SetLanguage(javascript.GetLanguage())
+ case "kotlin":
+ parser.SetLanguage(kotlin.GetLanguage())
+ case "lua":
+ parser.SetLanguage(lua.GetLanguage())
+ case "ocaml":
+ parser.SetLanguage(ocaml.GetLanguage())
+ case "php":
+ parser.SetLanguage(php.GetLanguage())
+ case "protobuf":
+ parser.SetLanguage(protobuf.GetLanguage())
+ case "python":
+ parser.SetLanguage(python.GetLanguage())
+ case "ruby":
+ parser.SetLanguage(ruby.GetLanguage())
+ case "rust":
+ parser.SetLanguage(rust.GetLanguage())
+ case "scala":
+ parser.SetLanguage(scala.GetLanguage())
+ case "svelte":
+ parser.SetLanguage(svelte.GetLanguage())
+ case "swift":
+ parser.SetLanguage(swift.GetLanguage())
+ case "toml":
+ parser.SetLanguage(toml.GetLanguage())
+ case "typescript":
+ parser.SetLanguage(typescript.GetLanguage())
+ case "tsx":
+ parser.SetLanguage(tsx.GetLanguage())
+ case "yaml":
+ parser.SetLanguage(yaml.GetLanguage())
+ default:
+ return nil
+ }
+ return parser
+}
+
+var languageByExtension = map[string]string{
+ ".sh": "bash",
+ ".bash": "bash",
+ ".c": "c",
+ ".h": "c",
+ ".cpp": "cpp",
+ ".cc": "cpp",
+ ".cs": "csharp",
+ ".css": "css",
+ ".cue": "cue",
+ ".dockerfile": "dockerfile",
+ ".ex": "elixir",
+ ".exs": "elixir",
+ ".elm": "elm",
+ ".go": "go",
+ ".groovy": "groovy",
+ ".hcl": "hcl",
+ ".html": "html",
+ ".java": "java",
+ ".js": "javascript",
+ ".jsx": "tsx",
+ ".kt": "kotlin",
+ ".lua": "lua",
+ ".ml": "ocaml",
+ ".php": "php",
+ ".proto": "protobuf",
+ ".py": "python",
+ ".rb": "ruby",
+ ".rs": "rust",
+ ".scala": "scala",
+ ".svelte": "svelte",
+ ".swift": "swift",
+ ".toml": "toml",
+ ".ts": "typescript",
+ ".tsx": "tsx",
+ ".yaml": "yaml",
+ ".yml": "yaml",
+}
+
+var fallbackByExtension = map[string]string{
+ ".ts": "tsx",
+ ".js": "tsx",
+}
diff --git a/app/server/syntax/validate.go b/app/server/syntax/validate.go
new file mode 100644
index 00000000..88b50403
--- /dev/null
+++ b/app/server/syntax/validate.go
@@ -0,0 +1,119 @@
+package syntax
+
+import (
+ "path/filepath"
+ "strings"
+
+ tree_sitter "github.com/smacker/go-tree-sitter"
+
+ "context"
+ "fmt"
+)
+
+type ValidationRes = struct {
+ Ext string
+ Lang string
+ HasParser bool
+ Valid bool
+ Errors []string
+}
+
+func Validate(ctx context.Context, path, file string) (*ValidationRes, error) {
+ ext := filepath.Ext(path)
+
+ parser, lang, fallbackParser, fallbackLang := getParserForExt(ext)
+
+ if parser == nil {
+ return &ValidationRes{Ext: ext, Lang: lang, HasParser: false}, nil
+ }
+
+ // Parse the content
+ tree, err := parser.ParseCtx(ctx, nil, []byte(file))
+
+ if err != nil || tree == nil {
+ return nil, fmt.Errorf("failed to parse the content: %v", err)
+ }
+ defer tree.Close()
+
+ // Get the root node of the syntax tree and check for errors
+ root := tree.RootNode()
+
+ if root.HasError() {
+ if fallbackParser != nil {
+ fallbackTree, err := fallbackParser.ParseCtx(ctx, nil, []byte(file))
+ if err != nil || fallbackTree == nil {
+ return nil, fmt.Errorf("failed to parse the content with fallback parser: %v", err)
+ }
+ defer fallbackTree.Close()
+
+ root = fallbackTree.RootNode()
+
+ if !root.HasError() {
+ return &ValidationRes{Ext: ext, Lang: fallbackLang, HasParser: true, Valid: true}, nil
+ }
+ }
+
+ errorMarkers := insertErrorMarkers(file, root)
+
+ return &ValidationRes{
+ Ext: ext,
+ Lang: lang,
+ HasParser: true,
+ Valid: false,
+ Errors: errorMarkers,
+ }, nil
+
+ }
+
+ return &ValidationRes{Ext: ext, Lang: lang, HasParser: true, Valid: true}, nil
+}
+
+func insertErrorMarkers(source string, node *tree_sitter.Node) []string {
+ var markers []string
+ var uniqueMarkers = map[string]bool{}
+
+ // Function to calculate line numbers
+ calculateLineNumber := func(position int) int {
+ return strings.Count(source[:position], "\n") + 1
+ }
+
+ hasChildError := func(n *tree_sitter.Node) bool {
+ for i := 0; i < int(n.ChildCount()); i++ {
+ if n.Child(i).HasError() {
+ return true
+ }
+ }
+ return false
+ }
+
+ visitNodes(node, func(n *tree_sitter.Node) {
+ if n.HasError() && !hasChildError(n) {
+ startPosition := int(n.StartByte())
+ endPosition := int(n.EndByte())
+ startLineNumber := calculateLineNumber(startPosition)
+ endLineNumber := calculateLineNumber(endPosition)
+
+ if startLineNumber == endLineNumber {
+ uniqueMarkers[fmt.Sprintf("Invalid syntax on line %d", startLineNumber)] = true
+ } else {
+ uniqueMarkers[fmt.Sprintf("Invalid syntax on lines %d to %d", startLineNumber, endLineNumber)] = true
+ }
+
+ }
+ })
+
+ for marker := range uniqueMarkers {
+ markers = append(markers, marker)
+ }
+
+ return markers
+}
+
+// visitNodes recursively visits nodes in the syntax tree
+func visitNodes(n *tree_sitter.Node, f func(node *tree_sitter.Node)) {
+ f(n)
+ for i := 0; i < int(n.ChildCount()); i++ {
+ child := n.Child(i)
+ visitNodes(child, f)
+ }
+}
diff --git a/app/server/types/model.go b/app/server/types/model.go
index 5716db57..3515b3ce 100644
--- a/app/server/types/model.go
+++ b/app/server/types/model.go
@@ -1,6 +1,8 @@
package types
import (
+ "strings"
+
"github.com/plandex/plandex/shared"
)
@@ -9,7 +11,8 @@ type StreamedFile struct {
}
type StreamedChangesWithLineNums struct {
- Changes []*shared.StreamedChangeWithLineNums `json:"changes"`
+ Problems string `json:"problems"`
+ Changes []*shared.StreamedChangeWithLineNums `json:"changes"`
}
// type StreamedChangesFull struct {
@@ -17,6 +20,38 @@ type StreamedChangesWithLineNums struct {
// }
type StreamedVerifyResult struct {
- Reasoning string `json:"reasoning"`
- IsCorrect bool `json:"isCorrect"`
+ SyntaxErrorsReasoning string `json:"syntaxErrorsReasoning"`
+ HasSyntaxErrors bool `json:"hasSyntaxErrors"`
+ RemovedCodeErrorsReasoning string `json:"removedCodeErrorsReasoning"`
+ HasRemovedCodeErrors bool `json:"hasRemovedCodeErrors"`
+ DuplicationErrorsReasoning string `json:"duplicationErrorsReasoning"`
+ HasDuplicationErrors bool `json:"hasDuplicationErrors"`
+ ReferenceErrorsReasoning string `json:"referenceErrorsReasoning"`
+ HasReferenceErrors bool `json:"hasReferenceErrors"`
+}
+
+func (s *StreamedVerifyResult) IsCorrect() bool {
+ return !s.HasRemovedCodeErrors && !s.HasDuplicationErrors && !s.HasReferenceErrors && !s.HasSyntaxErrors
+}
+
+func (s *StreamedVerifyResult) GetReasoning() string {
+ res := []string{}
+
+ if s.HasSyntaxErrors {
+ res = append(res, s.SyntaxErrorsReasoning)
+ }
+
+ if s.HasRemovedCodeErrors {
+ res = append(res, s.RemovedCodeErrorsReasoning)
+ }
+
+ if s.HasDuplicationErrors {
+ res = append(res, s.DuplicationErrorsReasoning)
+ }
+
+ if s.HasReferenceErrors {
+ res = append(res, s.ReferenceErrorsReasoning)
+ }
+
+ return strings.Join(res, "\n")
}
diff --git a/app/server/types/reply.go b/app/server/types/reply.go
index 9c7aee90..db3a1707 100644
--- a/app/server/types/reply.go
+++ b/app/server/types/reply.go
@@ -208,14 +208,18 @@ func (r *ReplyParser) FinishAndRead() parserRes {
}
func (r *ReplyParser) GetReplyBeforeCurrentPath() string {
- if r.currentFilePath == "" {
+ return r.GetReplyBeforePath(r.currentFilePath)
+}
+
+func (r *ReplyParser) GetReplyBeforePath(path string) string {
+ if path == "" {
return strings.Join(r.lines, "\n")
}
var idx int
for i := len(r.lines) - 1; i >= 0; i-- {
line := r.lines[i]
- if lineMaybeHasFilePath(line) && r.currentFilePath == extractFilePath(line) {
+ if lineMaybeHasFilePath(line) && path == extractFilePath(line) {
idx = i
break
}
diff --git a/app/shared/ai_models.go b/app/shared/ai_models.go
index 3ffa1493..7e7a8c18 100644
--- a/app/shared/ai_models.go
+++ b/app/shared/ai_models.go
@@ -16,6 +16,32 @@ var fullCompatibility = ModelCompatibility{
}
var AvailableModels = []*AvailableModel{
+ {
+ Description: "OpenAI's latest gpt-4o model, first released on 2024-05-13",
+ DefaultMaxConvoTokens: 10000,
+ DefaultReservedOutputTokens: 4096,
+ BaseModelConfig: BaseModelConfig{
+ Provider: ModelProviderOpenAI,
+ ModelName: "gpt-4o",
+ MaxTokens: 128000,
+ ApiKeyEnvVar: OpenAIEnvVar,
+ ModelCompatibility: fullCompatibility,
+ BaseUrl: OpenAIV1BaseUrl,
+ },
+ },
+ {
+ Description: "OpenAI's gpt-4o model, pinned to version released on 2024-05-13",
+ DefaultMaxConvoTokens: 10000,
+ DefaultReservedOutputTokens: 4096,
+ BaseModelConfig: BaseModelConfig{
+ Provider: ModelProviderOpenAI,
+ ModelName: "gpt-4o-2024-05-13",
+ MaxTokens: 128000,
+ ApiKeyEnvVar: OpenAIEnvVar,
+ ModelCompatibility: fullCompatibility,
+ BaseUrl: OpenAIV1BaseUrl,
+ },
+ },
{
Description: "OpenAI's latest gpt-4-turbo model, first released on 2024-04-09",
DefaultMaxConvoTokens: 10000,
@@ -276,8 +302,10 @@ var Gpt4TurboPreviewLatestModelPack ModelPack
var Gpt4TurboLatestModelPack ModelPack
var OpenRouterClaudeOpusGPT4TurboModelPack ModelPack
var TogetherMixtral8x22BModelPack ModelPack
+var Gpt4oLatestModelPack ModelPack
var BuiltInModelPacks = []*ModelPack{
+ &Gpt4oLatestModelPack,
&Gpt4TurboLatestModelPack,
&Gpt4TurboPreviewLatestModelPack,
&OpenRouterClaudeOpusGPT4TurboModelPack,
@@ -353,6 +381,50 @@ func init() {
AvailableModelsByName[model.ModelName] = model
}
+ Gpt4oLatestModelPack = ModelPack{
+ Name: "gpt-4o-latest",
+ Description: "Uses OpenAI's latest gpt-4o model, first released on 2024-05-13, for heavy lifting, latest version of gpt-3.5-turbo for lighter tasks.",
+ Planner: PlannerRoleConfig{
+ ModelRoleConfig: ModelRoleConfig{
+ Role: ModelRolePlanner,
+ BaseModelConfig: AvailableModelsByName["gpt-4o"].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,
+ TopP: DefaultConfigByRole[ModelRolePlanner].TopP,
+ },
+ PlannerModelConfig: getPlannerModelConfig("gpt-4o"),
+ },
+ PlanSummary: ModelRoleConfig{
+ Role: ModelRolePlanSummary,
+ BaseModelConfig: AvailableModelsByName["gpt-4o"].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRolePlanSummary].Temperature,
+ TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,
+ },
+ Builder: ModelRoleConfig{
+ Role: ModelRoleBuilder,
+ BaseModelConfig: AvailableModelsByName["gpt-4o"].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,
+ TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,
+ },
+ Namer: ModelRoleConfig{
+ Role: ModelRoleName,
+ BaseModelConfig: AvailableModelsByName[openai.GPT3Dot5Turbo].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRoleName].Temperature,
+ TopP: DefaultConfigByRole[ModelRoleName].TopP,
+ },
+ CommitMsg: ModelRoleConfig{
+ Role: ModelRoleCommitMsg,
+ BaseModelConfig: AvailableModelsByName[openai.GPT3Dot5Turbo].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRoleCommitMsg].Temperature,
+ TopP: DefaultConfigByRole[ModelRoleCommitMsg].TopP,
+ },
+ ExecStatus: ModelRoleConfig{
+ Role: ModelRoleExecStatus,
+ BaseModelConfig: AvailableModelsByName["gpt-4o"].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRoleExecStatus].Temperature,
+ TopP: DefaultConfigByRole[ModelRoleExecStatus].TopP,
+ },
+ }
+
Gpt4TurboLatestModelPack = ModelPack{
Name: "gpt-4-turbo-latest",
Description: "Uses latest version of OpenAI gpt-4-turbo model (first released on 2024-04-09) for heavy lifting, latest version of gpt-3.5-turbo for lighter tasks.",