Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
whole file builds - either for small files triggering validation or after a couple failed validation rewrites, assuming original file + changes fits within output limit. also some refactoring and a new model role.
Dane Schneider511445f59c45
diff --git a/app/cli/cmd/model_packs.go b/app/cli/cmd/model_packs.goindex 4189f4e5..28f05734 100644--- a/app/cli/cmd/model_packs.go+++ b/app/cli/cmd/model_packs.go@@ -254,11 +254,24 @@ func getModelWithRoleConfig(customModels []*shared.AvailableModel, modelRole shaterm.OutputErrorAndExit("Invalid number for top P: %v", err)}+ var reservedOutputTokens int+ if modelRole == shared.ModelRoleBuilder || modelRole == shared.ModelRolePlanner || modelRole == shared.ModelRoleWholeFileBuilder {+ reservedOutputTokensStr, err := term.GetUserStringInputWithDefault("Reserved output tokens for "+role+":", fmt.Sprintf("%d", shared.DefaultConfigByRole[modelRole].ReservedOutputTokens))+ if err != nil {+ term.OutputErrorAndExit("Error reading reserved output tokens: %v", err)+ }+ reservedOutputTokens, err = strconv.Atoi(reservedOutputTokensStr)+ if err != nil {+ term.OutputErrorAndExit("Invalid number for reserved output tokens: %v", err)+ }+ }+return model, shared.ModelRoleConfig{- Role: modelRole,- BaseModelConfig: model.BaseModelConfig,- Temperature: float32(temperature),- TopP: float32(topP),+ Role: modelRole,+ BaseModelConfig: model.BaseModelConfig,+ Temperature: float32(temperature),+ TopP: float32(topP),+ ReservedOutputTokens: reservedOutputTokens,}}@@ -268,8 +281,7 @@ func getPlannerRoleConfig(customModels []*shared.AvailableModel) shared.PlannerRreturn shared.PlannerRoleConfig{ModelRoleConfig: modelConfig,PlannerModelConfig: shared.PlannerModelConfig{- MaxConvoTokens: model.DefaultMaxConvoTokens,- ReservedOutputTokens: model.DefaultReservedOutputTokens,+ MaxConvoTokens: model.DefaultMaxConvoTokens,},}}diff --git a/app/cli/cmd/models.go b/app/cli/cmd/models.goindex 873543c3..3764901e 100644--- a/app/cli/cmd/models.go+++ b/app/cli/cmd/models.go@@ -162,7 +162,7 @@ func createCustomModel(cmd *cobra.Command, args []string) {}model.DefaultMaxConvoTokens = maxConvoTokens- fmt.Println("'Default Reserved Output Tokens' is the default number of tokens reserved for model output in the 'planner' role. This ensures the model has enough tokens to generate a response. For models with 8k context, ~1000 is recommended. For 128k context, ~4000 is recommended.")+ fmt.Println("'Default Reserved Output Tokens' is the default number of tokens reserved for model output in the 'planner', 'builder', and 'whole file builder' roles. This ensures the model has enough tokens to generate a response. For models with 8k context, ~1000 is recommended. For 128k context, ~4000 is recommended.")reservedOutputTokensStr, err := term.GetRequiredUserStringInput("Default Reserved Output Tokens:")if err != nil {term.OutputErrorAndExit("Error reading reserved output tokens: %v", err)@@ -437,7 +437,7 @@ func renderSettings(settings *shared.PlanSettings) {color.New(color.Bold, term.ColorHiCyan).Println("🤖 Models")table = tablewriter.NewWriter(os.Stdout)table.SetAutoWrapText(false)- table.SetHeader([]string{"Role", "Provider", "Model", "Temperature", "Top P"})+ table.SetHeader([]string{"Role", "Provider", "Model", "Temperature", "Top P", "Max Output"})addModelRow := func(role string, config shared.ModelRoleConfig) {table.Append([]string{@@ -446,6 +446,7 @@ func renderSettings(settings *shared.PlanSettings) {config.BaseModelConfig.ModelName,fmt.Sprintf("%.1f", config.Temperature),fmt.Sprintf("%.1f", config.TopP),+ fmt.Sprintf("%d 🪙", config.ReservedOutputTokens),})}@@ -463,11 +464,10 @@ func renderSettings(settings *shared.PlanSettings) {color.New(color.Bold, term.ColorHiCyan).Println("🧠 Planner Defaults")table = tablewriter.NewWriter(os.Stdout)table.SetAutoWrapText(false)- table.SetHeader([]string{"Max Tokens", "Max Convo Tokens", "Reserved Output Tokens"})+ table.SetHeader([]string{"Max Tokens", "Max Convo Tokens"})table.Append([]string{fmt.Sprintf("%d", modelPack.Planner.BaseModelConfig.MaxTokens),fmt.Sprintf("%d", modelPack.Planner.MaxConvoTokens),- fmt.Sprintf("%d", modelPack.Planner.ReservedOutputTokens),})table.Render()fmt.Println()@@ -486,11 +486,6 @@ func renderSettings(settings *shared.PlanSettings) {} else {table.Append([]string{"Max Convo Tokens", fmt.Sprintf("%d", *settings.ModelOverrides.MaxConvoTokens)})}- if settings.ModelOverrides.ReservedOutputTokens == nil {- table.Append([]string{"Reserved Output Tokens", "no override"})- } else {- table.Append([]string{"Reserved Output Tokens", fmt.Sprintf("%d", *settings.ModelOverrides.ReservedOutputTokens)})- }table.Render()fmt.Println()}diff --git a/app/cli/cmd/set_model.go b/app/cli/cmd/set_model.goindex 114c7fae..5162418c 100644--- a/app/cli/cmd/set_model.go+++ b/app/cli/cmd/set_model.go@@ -134,6 +134,7 @@ func updateModelSettings(args []string, originalSettings *shared.PlanSettings) *var selectedModel *shared.AvailableModelvar temperature *float64var topP *float64+ var reservedOutputTokens *intif len(args) > 0 {modelSetOrRoleOrSetting = args[0]@@ -303,17 +304,6 @@ func updateModelSettings(args []string, originalSettings *shared.PlanSettings) *}settings.ModelOverrides.MaxTokens = &n}- case "reservedoutputtokens":- if value == "" {- settings.ModelOverrides.ReservedOutputTokens = nil- } else {- n, err := strconv.Atoi(value)- if err != nil {- fmt.Println("Invalid value for reserved-output-tokens:", value)- return nil- }- settings.ModelOverrides.ReservedOutputTokens = &n- }}}@@ -355,6 +345,7 @@ func updateModelSettings(args []string, originalSettings *shared.PlanSettings) *"Select a model","Set temperature","Set top-p",+ "Set reserved output tokens",}opts = append(opts, lib.GoBack)@@ -393,6 +384,9 @@ func updateModelSettings(args []string, originalSettings *shared.PlanSettings) *} else if selection == "Set top-p" {propertyCompact = "topp"break Outer+ } else if selection == "Set reserved output tokens" {+ propertyCompact = "reservedoutputtokens"+ break Outer}}}@@ -405,6 +399,8 @@ func updateModelSettings(args []string, originalSettings *shared.PlanSettings) *msg += "temperature (-2.0 to 2.0)"} else if propertyCompact == "topp" {msg += "top-p (0.0 to 1.0)"+ } else if propertyCompact == "reservedoutputtokens" {+ msg += "reserved output tokens"}var err errorvalue, err = term.GetRequiredUserStringInput(msg)@@ -433,6 +429,13 @@ func updateModelSettings(args []string, originalSettings *shared.PlanSettings) *return nil}topP = &f+ case "reservedoutputtokens":+ n, err := strconv.Atoi(value)+ if err != nil {+ fmt.Println("Invalid value for reserved-output-tokens:", value)+ return nil+ }+ settings.ModelOverrides.ReservedOutputTokens = &n}}}@@ -446,13 +449,14 @@ func updateModelSettings(args []string, originalSettings *shared.PlanSettings) *if selectedModel != nil {settings.ModelPack.Planner.BaseModelConfig = selectedModel.BaseModelConfigsettings.ModelPack.Planner.PlannerModelConfig = shared.PlannerModelConfig{- MaxConvoTokens: selectedModel.DefaultMaxConvoTokens,- ReservedOutputTokens: selectedModel.DefaultReservedOutputTokens,+ MaxConvoTokens: selectedModel.DefaultMaxConvoTokens,}} else if temperature != nil {settings.ModelPack.Planner.Temperature = float32(*temperature)} else if topP != nil {settings.ModelPack.Planner.TopP = float32(*topP)+ } else if reservedOutputTokens != nil {+ settings.ModelPack.Planner.ReservedOutputTokens = *reservedOutputTokens}case shared.ModelRolePlanSummary:diff --git a/app/server/handlers/stream_helper.go b/app/server/handlers/stream_helper.goindex 689dc719..4fecee44 100644--- a/app/server/handlers/stream_helper.go+++ b/app/server/handlers/stream_helper.go@@ -172,10 +172,10 @@ func initConnectActive(auth *types.ServerAuth, planId, branch string, w http.ResbuildInfo.NumTokens = 0buildInfo.Finished = true} else {- tokens := build.WithLineNumsBufferTokens-+ // no longer showing token counts in build info - leaving commented out for now for reference+ // tokens := build.WithLineNumsBufferTokensbuildInfo.Finished = false- buildInfo.NumTokens += tokens+ // buildInfo.NumTokens += tokens}}diff --git a/app/server/model/plan/build_full_file.go b/app/server/model/plan/build_full_file.godeleted file mode 100644index 8203775d..00000000--- a/app/server/model/plan/build_full_file.go+++ /dev/null@@ -1,29 +0,0 @@-package plan--import (- "fmt"- "log"-)--func (fileState *activeBuildStreamFileState) buildFullFile() {- auth := fileState.auth- filePath := fileState.filePath- activeBuild := fileState.activeBuild- clients := fileState.clients- planId := fileState.plan.Id- branch := fileState.branch- config := fileState.settings.ModelPack.Builder- originalFile := fileState.preBuildState-- activePlan := GetActivePlan(planId, branch)-- if activePlan == nil {- log.Printf("Active plan not found for plan ID %s and branch %s\n", planId, branch)- fileState.onBuildFileError(fmt.Errorf("active plan not found for plan ID %s and branch %s", planId, branch))- return- }-- proposedContent := activeBuild.FileContent- desc := activeBuild.FileDescription--}diff --git a/app/server/model/plan/build_state.go b/app/server/model/plan/build_state.goindex 92832929..634d80f6 100644--- a/app/server/model/plan/build_state.go+++ b/app/server/model/plan/build_state.go@@ -38,26 +38,8 @@ type activeBuildStreamFileState struct {parser *sitter.Parserlanguage shared.TreeSitterLanguagepreBuildStateSyntaxInvalid bool-- structuredEditNumRetry int- expandRefsNumRetry int- lineNumsNumRetry int- verifyFileNumRetry int- fixFileNumRetry int-- syntaxNumRetry int- syntaxNumEpoch int-- isFixingSyntax bool- isFixingOther bool-- streamedChangesWithLineNums []*shared.StreamedChangeWithLineNums- updated string-- verificationErrors string- syntaxErrors []string-- isNewFile bool-- inputTokens int+ structuredEditNumRetry int+ wholeFileNumRetry int+ syntaxErrors []string+ isNewFile bool}diff --git a/app/server/model/plan/build_structured_edits.go b/app/server/model/plan/build_structured_edits.goindex 77a116d6..44a361c9 100644--- a/app/server/model/plan/build_structured_edits.go+++ b/app/server/model/plan/build_structured_edits.go@@ -11,7 +11,6 @@ import ("plandex-server/model""plandex-server/model/prompts""plandex-server/syntax"- "plandex-server/types""strings""time"@@ -20,8 +19,21 @@ import ("github.com/sashabaranov/go-openai")-const BuildStructuredEditsMaxTries = 4-const BuildStructuredEditsTriesBeforeFullFile = 2+type FixedProposedUpdatesTag struct {+ XMLName xml.Name `xml:"PlandexProposedUpdates"`+ Content string `xml:",chardata"`+}++type ProposedUpdatesExplanationTag struct {+ XMLName xml.Name `xml:"PlandexProposedUpdatesExplanation"`+ Content string `xml:",chardata"`+}++const BuildStructuredEditsMaxTries = 5+const BuildTriesBeforeWholeFile = 3++// if original file plus updates token count is below this threshold, build whole file immediately+const BuildWholeFileImmediateThreshold = 600func (fileState *activeBuildStreamFileState) buildStructuredEdits() {auth := fileState.auth@@ -62,15 +74,24 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {// log.Println(applyRes.NewFile)proposedContent = applyRes.Proposed+ totalPossibleTokens := activeBuild.FileContentTokens + activeBuild.CurrentFileTokensfor len(applyRes.NeedsVerifyReasons) > 0 && numTries < BuildStructuredEditsMaxTries {log.Printf("buildStructuredEdits verify call - numTries: %d\n", numTries)-- numTries++-log.Println("buildStructuredEdits - needs verify reasons:")spew.Dump(applyRes.NeedsVerifyReasons)+ wholeFileConfig := fileState.settings.ModelPack.GetWholeFileBuilder()+ reservedOutputTokens := wholeFileConfig.ReservedOutputTokens+ buildImmediate := totalPossibleTokens < BuildWholeFileImmediateThreshold++ if (buildImmediate || numTries == BuildTriesBeforeWholeFile) && totalPossibleTokens < int(float32(reservedOutputTokens)*0.9) {+ log.Printf("buildStructuredEdits - %s - num tries %d - total possible tokens %d is less than reserved output tokens %d - building whole file\n", filePath, numTries, totalPossibleTokens, reservedOutputTokens)++ fileState.buildWholeFileFallback(proposedContent, desc)+ return+ }+log.Println("buildStructuredEdits - getting verify edits prompt")var diff string@@ -107,15 +128,13 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {inputTokens := prompts.ExtraTokensPerRequest + prompts.ExtraTokensPerMessage + promptTokens- fileState.inputTokens = inputTokens-_, apiErr := hooks.ExecHook(hooks.WillSendModelRequest, hooks.HookParams{Auth: auth,Plan: fileState.plan,WillSendModelRequestParams: &hooks.WillSendModelRequestParams{InputTokens: inputTokens,- OutputTokens: shared.AvailableModelsByName[fileState.settings.ModelPack.Builder.BaseModelConfig.ModelName].DefaultReservedOutputTokens,- ModelName: fileState.settings.ModelPack.Builder.BaseModelConfig.ModelName,+ OutputTokens: config.ReservedOutputTokens,+ ModelName: config.BaseModelConfig.ModelName,},})if apiErr != nil {@@ -152,11 +171,11 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {DidSendModelRequestParams: &hooks.DidSendModelRequestParams{InputTokens: resp.Usage.PromptTokens,OutputTokens: resp.Usage.CompletionTokens,- ModelName: fileState.settings.ModelPack.Builder.BaseModelConfig.ModelName,- ModelProvider: fileState.settings.ModelPack.Builder.BaseModelConfig.Provider,+ ModelName: config.BaseModelConfig.ModelName,+ ModelProvider: config.BaseModelConfig.Provider,ModelPackName: fileState.settings.ModelPack.Name,ModelRole: shared.ModelRoleBuilder,- Purpose: "File edit",+ Purpose: "File edit (structured edits)",},})@@ -185,7 +204,7 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {// edits are validbreak} else {- var fixedProposedUpdates syntax.FixedProposedUpdatesTag+ var fixedProposedUpdates FixedProposedUpdatesTagerr = xml.Unmarshal([]byte(fixedProposedUpdatesXmlString), &fixedProposedUpdates)if err != nil {log.Printf("buildStructuredEdits - error unmarshalling PlandexProposedUpdates xml: %v\n", err)@@ -194,21 +213,7 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {proposedContent = fixedProposedUpdates.Content// remove code block formatting if it was mistakenly included in the proposed content- trimmedProposedContent := strings.TrimSpace(proposedContent)- splitProposedContent := strings.Split(trimmedProposedContent, "\n")-- if len(splitProposedContent) > 2 {- firstLine := strings.TrimSpace(splitProposedContent[0])- secondLine := strings.TrimSpace(splitProposedContent[1])- lastLine := strings.TrimSpace(splitProposedContent[len(splitProposedContent)-1])- if types.LineMaybeHasFilePath(firstLine) && strings.HasPrefix(secondLine, "```") {- if lastLine == "```" {- proposedContent = strings.Join(splitProposedContent[1:len(splitProposedContent)-1], "\n")- }- } else if strings.HasPrefix(firstLine, "```") && lastLine == "```" {- proposedContent = strings.Join(splitProposedContent[1:len(splitProposedContent)-1], "\n")- }- }+ proposedContent = StripBackticksWrapper(proposedContent)// log.Println("buildStructuredEdits - fixed proposed content:")// log.Println(proposedContent)@@ -219,7 +224,7 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {// log.Println(fixedDescString)if fixedDescString != "" {- var descElement syntax.ProposedUpdatesExplanationTag+ var descElement ProposedUpdatesExplanationTagerr = xml.Unmarshal([]byte(fixedDescString), &descElement)if err != nil {log.Printf("buildStructuredEdits - error unmarshalling PlandexProposedUpdatesExplanation xml: %v\n", err)@@ -241,6 +246,8 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {log.Printf("buildStructuredEdits - %s - applyRes.NeedsVerifyReasons: %v\n", filePath, applyRes.NeedsVerifyReasons)proposedContent = applyRes.Proposed++ numTries++}}@@ -257,8 +264,6 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {})time.Sleep(50 * time.Millisecond)- fileState.updated = updatedFile-replacements, err := diff_pkg.GetDiffReplacements(originalFile, updatedFile)if err != nil {log.Printf("buildStructuredEdits - error getting diff replacements: %v\n", err)diff --git a/app/server/model/plan/build_whole_file.go b/app/server/model/plan/build_whole_file.gonew file mode 100644index 00000000..67a93b13--- /dev/null+++ b/app/server/model/plan/build_whole_file.go@@ -0,0 +1,202 @@+package plan++import (+ "encoding/xml"+ "fmt"+ "log"+ "math/rand"+ "plandex-server/db"+ diff_pkg "plandex-server/diff"+ "plandex-server/hooks"+ "plandex-server/model"+ "plandex-server/model/prompts"+ "strings"+ "time"++ "github.com/davecgh/go-spew/spew"+ "github.com/plandex/plandex/shared"+ "github.com/sashabaranov/go-openai"+)++type WholeFileTag struct {+ XMLName xml.Name `xml:"PlandexWholeFile"`+ Content string `xml:",chardata"`+}++func (fileState *activeBuildStreamFileState) buildWholeFileFallback(proposedContent string, desc string) {+ auth := fileState.auth+ filePath := fileState.filePath+ clients := fileState.clients+ planId := fileState.plan.Id+ branch := fileState.branch+ originalFile := fileState.preBuildState+ config := fileState.settings.ModelPack.GetWholeFileBuilder()++ activePlan := GetActivePlan(planId, branch)++ if activePlan == nil {+ log.Printf("Active plan not found for plan ID %s and branch %s\n", planId, branch)+ fileState.onBuildFileError(fmt.Errorf("active plan not found for plan ID %s and branch %s", planId, branch))+ return+ }++ sysPrompt := prompts.GetWholeFilePrompt(filePath, originalFile, desc, proposedContent)++ messages := []openai.ChatCompletionMessage{+ {+ Role: openai.ChatMessageRoleSystem,+ Content: sysPrompt,+ },+ }++ promptTokens, err := shared.GetNumTokens(sysPrompt)++ if err != nil {+ log.Printf("buildWholeFile - error getting num tokens for prompt: %v\n", err)+ fileState.onBuildFileError(fmt.Errorf("error getting num tokens for prompt: %v", err))+ return+ }++ inputTokens := prompts.ExtraTokensPerRequest + prompts.ExtraTokensPerMessage + promptTokens++ _, apiErr := hooks.ExecHook(hooks.WillSendModelRequest, hooks.HookParams{+ Auth: auth,+ Plan: fileState.plan,+ WillSendModelRequestParams: &hooks.WillSendModelRequestParams{+ InputTokens: inputTokens,+ OutputTokens: config.ReservedOutputTokens,+ ModelName: config.BaseModelConfig.ModelName,+ },+ })+ if apiErr != nil {+ activePlan.StreamDoneCh <- apiErr+ return+ }++ log.Println("buildWholeFile - calling model for applied changes validation")++ modelReq := openai.ChatCompletionRequest{+ Model: config.BaseModelConfig.ModelName,+ Messages: messages,+ Temperature: config.Temperature,+ TopP: config.TopP,+ }++ envVar := config.BaseModelConfig.ApiKeyEnvVar+ client := clients[envVar]++ resp, err := model.CreateChatCompletionWithRetries(client, activePlan.Ctx, modelReq)++ if err != nil {+ log.Printf("buildWholeFile - error calling model: %v\n", err)+ fileState.wholeFileRetryOrError(proposedContent, desc, fmt.Errorf("error calling model: %v", err))+ return+ }++ log.Println("buildWholeFile - usage:")+ spew.Dump(resp.Usage)++ _, apiErr = hooks.ExecHook(hooks.DidSendModelRequest, hooks.HookParams{+ Auth: auth,+ Plan: fileState.plan,+ DidSendModelRequestParams: &hooks.DidSendModelRequestParams{+ InputTokens: resp.Usage.PromptTokens,+ OutputTokens: resp.Usage.CompletionTokens,+ ModelName: config.BaseModelConfig.ModelName,+ ModelProvider: config.BaseModelConfig.Provider,+ ModelPackName: fileState.settings.ModelPack.Name,+ ModelRole: shared.ModelRoleBuilder,+ Purpose: "File edit (whole file)",+ },+ })++ if apiErr != nil {+ activePlan.StreamDoneCh <- apiErr+ return+ }++ if len(resp.Choices) == 0 {+ log.Printf("buildStructuredEdits - no choices in response\n")+ fileState.structuredEditRetryOrError(fmt.Errorf("no choices in response"))+ return+ }++ refsChoice := resp.Choices[0]+ content := refsChoice.Message.Content++ log.Printf("buildWholeFile - %s - content:\n%s\n", filePath, content)++ wholeFileXmlString := GetXMLTag(content, "PlandexWholeFile", true)++ var wholeFileTag WholeFileTag+ err = xml.Unmarshal([]byte(wholeFileXmlString), &wholeFileTag)+ if err != nil {+ log.Printf("buildWholeFile - error unmarshalling PlandexWholeFile xml: %v\n", err)+ }++ updatedFile := wholeFileTag.Content++ buildInfo := &shared.BuildInfo{+ Path: filePath,+ NumTokens: 0,+ Finished: true,+ }+ activePlan.Stream(shared.StreamMessage{+ Type: shared.StreamMessageBuildInfo,+ BuildInfo: buildInfo,+ })+ time.Sleep(50 * time.Millisecond)++ replacements, err := diff_pkg.GetDiffReplacements(originalFile, updatedFile)+ if err != nil {+ log.Printf("buildWholeFile - error getting diff replacements: %v\n", err)+ fileState.wholeFileRetryOrError(proposedContent, desc, fmt.Errorf("error getting diff replacements: %v", err))+ return+ }++ for _, replacement := range replacements {+ replacement.Summary = strings.TrimSpace(desc)+ }++ res := db.PlanFileResult{+ TypeVersion: 1,+ OrgId: fileState.plan.OrgId,+ PlanId: fileState.plan.Id,+ PlanBuildId: fileState.build.Id,+ ConvoMessageId: fileState.convoMessageId,+ Content: "",+ Path: filePath,+ Replacements: replacements,+ }++ fileState.onFinishBuildFile(&res, updatedFile)+}++func (fileState *activeBuildStreamFileState) wholeFileRetryOrError(proposedContent string, desc string, err error) {+ if fileState.wholeFileNumRetry < MaxBuildErrorRetries {+ fileState.wholeFileNumRetry++++ log.Printf("buildWholeFile - retrying whole file file '%s' due to error: %v\n", fileState.filePath, err)++ activePlan := GetActivePlan(fileState.plan.Id, fileState.branch)++ if activePlan == nil {+ log.Printf("buildWholeFile - active plan not found for plan ID %s and branch %s\n", fileState.plan.Id, fileState.branch)+ fileState.onBuildFileError(fmt.Errorf("active plan not found for plan ID %s and branch %s", fileState.plan.Id, fileState.branch))+ return+ }++ select {+ case <-activePlan.Ctx.Done():+ log.Printf("buildWholeFile - context canceled\n")+ return+ case <-time.After(time.Duration(fileState.wholeFileNumRetry*fileState.wholeFileNumRetry)*200*time.Millisecond + time.Duration(rand.Intn(500))*time.Millisecond):+ break+ }++ fileState.buildWholeFileFallback(proposedContent, desc)+ } else {+ fileState.onBuildFileError(err)+ }++}diff --git a/app/server/model/plan/utils.go b/app/server/model/plan/utils.gonew file mode 100644index 00000000..5d08cb3a--- /dev/null+++ b/app/server/model/plan/utils.go@@ -0,0 +1,26 @@+package plan++import (+ "plandex-server/types"+ "strings"+)++func StripBackticksWrapper(s string) string {+ check := strings.TrimSpace(s)+ split := strings.Split(check, "\n")++ if len(split) > 2 {+ firstLine := strings.TrimSpace(split[0])+ secondLine := strings.TrimSpace(split[1])+ lastLine := strings.TrimSpace(split[len(split)-1])+ if types.LineMaybeHasFilePath(firstLine) && strings.HasPrefix(secondLine, "```") {+ if lastLine == "```" {+ return strings.Join(split[1:len(split)-1], "\n")+ }+ } else if strings.HasPrefix(firstLine, "```") && lastLine == "```" {+ return strings.Join(split[1:len(split)-1], "\n")+ }+ }++ return s+}diff --git a/app/server/model/prompts/build.go b/app/server/model/prompts/build.goindex 5265b1f5..e330165e 100644--- a/app/server/model/prompts/build.go+++ b/app/server/model/prompts/build.go@@ -7,120 +7,6 @@ import ("github.com/plandex/plandex/shared")-func GetWholeFilePrompt(filePath, preBuildState, changesFile, changesDesc string) string {- preBuildStateWithLineNums := shared.AddLineNums(preBuildState)- changesWithLineNums := shared.AddLineNumsWithPrefix(changesFile, "pdx-new-")-- s := WholeFileBeginning + ReferencesPrompt + WholeFileEnding + "\n\n" + getPreBuildStatePrompt(filePath, preBuildStateWithLineNums) + "\n\n"-- s += fmt.Sprintf("Proposed updates:\n%s\n```\n%s\n```", changesDesc, changesWithLineNums)-- return s-}--var ExampleReferences = `-A reference comment is a comment that references code in the *original file* for the purpose of making it clear where a change should be applied. Examples of reference comments include:-- - // ... existing code...- - # Existing code...- - /* ... */- - // Rest of the function...- - <!-- rest of div tag -->- - // ... rest of function ...- - // rest of component...- - # other methods...- - // ... rest of init code...- - // rest of the class...- - // other properties- - // other methods- // ... existing properties ...- // ... existing values ...- // ... existing text ...--Reference comments often won't exactly match one of the above examples, but they will always be referencing a block of code from the *original file* that is left out of the *proposed updates* for the sake of focusing on the specific change that is being made.--Reference comments do NOT need to be valid comments for the given file type. For file types like JSON or plain text that do not use comments, reference comments in the form of '// ... existing properties ...' or '// ... existing values ...' or '// ... existing text ...' can still be present. These MUST be treated as valid reference comments regardless of the file type or the validity of the syntax.-`--const RefsBeginning = `-You are an AI that analyzes an *original file* and *proposed updates* to that file and then identifies *all* *reference comments* present in the *proposed updates*.--`--const WholeFileBeginning = `-After identifying all references, you will output the *entire file* with the *proposed updates* correctly applied. ALL references will be replaced by the appropriate code from the *original file*. You will correctly merge the code from the *original file* with the *proposed updates* and output the entire file.--`--var ReferencesPrompt = ExampleReferences + `-- *NOT EVERY COMMENT IS A REFERENCE.* If a comment refers to code that is present in the *proposed updates* then it is *not* a reference. Similarly, if a comment explains something about the change being made in the *proposed updates*, it is also *not* a reference.-- A reference comment MUST EXIST in the *proposed updates*. Do not include a reference comment unless it exists VERBATIM in the *proposed updates*.-- Before outputting the references, first output a section that lists *EVERY* comment in the *proposed updates*, including the line number of each comment prefixed by 'pdx-new-'. Below each comment, evaluate whether it is a reference comment. Focus on whether the comment is clearly referencing a block of code in the *original file*, whether it is explaining a change being made, or whether it is a comment that was carried over from the *original file* but does *not* reference any code that was left out of the *proposed updates*. After this evaluation, state whether each comment is a reference comment or not. Only list valid *comments* for the given programming language in the comments section. Do not include non-comment lines of code in the comments section.-- Example:-- ---- Comments:-- pdx-new-2: // ... existing code to start transaction ...- Evaluation: refers the code at the beginning of the 'update' function that starts the database transaction.- Reference: true-- pdx-new-6: // ... existing update code ...- Evaluation: refers the code inside the 'update' function that updates the user.- Reference: true-- pdx-new-9: // ... existing code to commit db transaction...- Evaluation: refers the code inside the 'update' function that commits the database transaction.- Reference: true-- pdx-new-4: // verify user permission before performing update- Evaluation: describes the change being made. Does not refer to any code in the *original file*.- Reference: false-- pdx-new-85: // Rest of the main function...- Evaluation: refers to the rest of the main function that is left unchanged.- Reference: true-- pdx-new-25: # Delete the object- Evaluation: describes the change being made. Does not refer to any code in the *original file*.- Reference: false-`--const RefsOnlyEnding = `- *-- Do NOT include any additional text after the <references> element. The output must end after </references>. DO NOT use the string <references> anywhere else in the output. ONLY use it to start the <references> element.-`--const WholeFileEnding = `- *-- Now output the entire file with the *proposed updates* correctly applied. ALL identified references MUST be replaced by the appropriate code from the *original file*. You MUST correctly merge the code from the *original file* with the *proposed updates* and output the entire file. The resulting file MUST NOT include any reference comments.-- The resulting file MUST be syntactically and semantically correct. All code structures must be properly balanced.-- The full resulting file should be output within a <file> element, like this:-- <file>- package main-- import "logger"-- function main() {- logger.info("Hello, world!");- exec()- }- </file>-- Do NOT include line numbers in the <file> element. Do NOT include reference comments in the <file> element. Output the ENTIRE file, no matter how long it is, with NO EXCEPTIONS. Include the resulting file *only* with no other text. Do NOT wrap the file output in triple backticks or any other formatting, except for the <file> element tags.-- Do NOT include any additional text after the <file> element. The output must end after </file>. DO NOT use the string <file> anywhere else in the output. ONLY use it to start the <file> element.-`-func GetValidateEditsPrompt(path,original,@@ -155,12 +41,15 @@ func GetValidateEditsPrompt(if reason == syntax.NeedsVerifyReasonAmbiguousLocation {editsIncorrect = trues += `The proposed changes were applied to an ambiguous location. This may mean that anchors were written incorrectly (with incorrect spacing or indentation, for example), or else that the ordering of anchors was incorrect. It may also mean that necessary surrounding context and anchors were not included.`- } else if reason == syntax.NeedsVerifyReasonNoChanges {- s += `The proposed changes did not cause any change to the resulting file when applied. Was this intentional?`++ // not going to verify for no changes for now, too many false positives+ // } else if reason == syntax.NeedsVerifyReasonNoChanges {+ // s += `The proposed changes did not cause any change to the resulting file when applied. Was this intentional?`+} else if reason == syntax.NeedsVerifyReasonCodeRemoved {- s += `The proposed changes removed or replaced code. Was this intentional?`+ s += `The proposed changes removed or replaced code. Was this intentional? If this was the clear intention of the plan, then removing or replacing code can be correct. But it could also be a sign that the proposed changes were not correctly applied.`} else if reason == syntax.NeedsVerifyReasonCodeDuplicated {- s += `The proposed may have duplicated code. Was this intentional?`+ s += `The proposed may have duplicated code. Was this intentional? If this was the clear intention of the plan, or the duplication exists in the original file for a valid reason, then duplicating code can be correct. But it could also be a sign that the proposed changes were not correctly applied.`}}@@ -174,7 +63,7 @@ func GetValidateEditsPrompt(s += `-- You MUST NOT make *functional* changes when rewriting the explanation or proposed updates. Your job is not to change functionality or write additional code, but to ensure that the explanation and proposed updates follow all the rules correctly. Stick as close to the original proposed updates as possible when rewriting. Fix the problems, but keep everything else the same as much as possible, including comments, line breaks, spacing, etc.+- You MUST NOT make *functional* changes when rewriting the explanation or proposed updates. Your job is *NOT* to change functionality or add additional code in *any way*. It is *only* to ensure that the explanation and proposed updates follow all the rules correctly. Stick as close to the original proposed updates as possible when rewriting. Fix the problems, but keep everything else *exactly the same*, including comments, line breaks, spacing, etc.- You MUST NOT add 'Plandex: removed' comments unless the intention of the plan and the explanation is to remove code. NEVER add 'Plandex: removed' comments to the *proposed updates* unless the *explanation* includes the word 'remove'. The *only* time you can add a 'Plandex: removed' comment is if 1 - you are correcting a mistaken comment that was intended as a removal comment, but used the wrong format—for example, if the 'Plandex: ' prefix was incorrectly omitted. In that case you must fix the comment in the fixed proposed updates. 2 - the explanation explicitly stats that code should be removed, but a necessary 'Plandex: removed' comment is missing from the proposed updates, causing the code that should have been removed to incorrectly remain in the file. In that case you must add the missing 'Plandex: removed' comment to the proposed updates in the correct location, with correct surrounding context and anchors.`@@ -315,3 +204,111 @@ func getPreBuildStatePrompt(filePath, preBuildState string) string {return fmt.Sprintf("**The current file is %s. Original state of the file:**\n```\n%s\n```", filePath, preBuildState) + "\n\n"}++func GetWholeFilePrompt(filePath, preBuildState, changesFile, changesDesc string) string {+ preBuildStateWithLineNums := shared.AddLineNums(preBuildState)+ changesWithLineNums := shared.AddLineNumsWithPrefix(changesFile, "pdx-new-")++ s := WholeFileBeginning + ReferencesPrompt + WholeFileEnding + "\n\n" + getPreBuildStatePrompt(filePath, preBuildStateWithLineNums) + "\n\n"++ s += fmt.Sprintf("Proposed updates:\n%s\n```\n%s\n```", changesDesc, changesWithLineNums)++ return s+}++var ExampleReferences = `+A reference comment is a comment that references code in the *original file* for the purpose of making it clear where a change should be applied. Examples of reference comments include:++ - // ... existing code...+ - # Existing code...+ - /* ... */+ - // Rest of the function...+ - <!-- rest of div tag -->+ - // ... rest of function ...+ - // rest of component...+ - # other methods...+ - // ... rest of init code...+ - // rest of the class...+ - // other properties+ - // other methods+ // ... existing properties ...+ // ... existing values ...+ // ... existing text ...++Reference comments often won't exactly match one of the above examples, but they will always be referencing a block of code from the *original file* that is left out of the *proposed updates* for the sake of focusing on the specific change that is being made.++Reference comments do NOT need to be valid comments for the given file type. For file types like JSON or plain text that do not use comments, reference comments in the form of '// ... existing properties ...' or '// ... existing values ...' or '// ... existing text ...' can still be present. These MUST be treated as valid reference comments regardless of the file type or the validity of the syntax.+`++const RefsBeginning = `+You are an AI that analyzes an *original file* and *proposed updates* to that file and then identifies *all* *reference comments* present in the *proposed updates*.++`++const WholeFileBeginning = `+After identifying all references, you will output the *entire file* with the *proposed updates* correctly applied. ALL references will be replaced by the appropriate code from the *original file*. You will correctly merge the code from the *original file* with the *proposed updates* and output the entire file.++`++var ReferencesPrompt = ExampleReferences + `++ *NOT EVERY COMMENT IS A REFERENCE.* If a comment refers to code that is present in the *proposed updates* then it is *not* a reference. Similarly, if a comment explains something about the change being made in the *proposed updates*, it is also *not* a reference.++ A reference comment MUST EXIST in the *proposed updates*. Do not include a reference comment unless it exists VERBATIM in the *proposed updates*.++ Before outputting the references, first output a section that lists *EVERY* comment in the *proposed updates*, including the line number of each comment prefixed by 'pdx-new-'. Below each comment, evaluate whether it is a reference comment. Focus on whether the comment is clearly referencing a block of code in the *original file*, whether it is explaining a change being made, or whether it is a comment that was carried over from the *original file* but does *not* reference any code that was left out of the *proposed updates*. After this evaluation, state whether each comment is a reference comment or not. Only list valid *comments* for the given programming language in the comments section. Do not include non-comment lines of code in the comments section.++ Example:++ ---+ Comments:++ pdx-new-2: // ... existing code to start transaction ...+ Evaluation: refers the code at the beginning of the 'update' function that starts the database transaction.+ Reference: true++ pdx-new-6: // ... existing update code ...+ Evaluation: refers the code inside the 'update' function that updates the user.+ Reference: true++ pdx-new-9: // ... existing code to commit db transaction...+ Evaluation: refers the code inside the 'update' function that commits the database transaction.+ Reference: true++ pdx-new-4: // verify user permission before performing update+ Evaluation: describes the change being made. Does not refer to any code in the *original file*.+ Reference: false++ pdx-new-85: // Rest of the main function...+ Evaluation: refers to the rest of the main function that is left unchanged.+ Reference: true++ pdx-new-25: # Delete the object+ Evaluation: describes the change being made. Does not refer to any code in the *original file*.+ Reference: false+`++const WholeFileEnding = `+ *++ Now output the entire file with the *proposed updates* correctly applied. ALL identified references MUST be replaced by the appropriate code from the *original file*. You MUST correctly merge the code from the *original file* with the *proposed updates* and output the *entire* resulting file. The resulting file MUST NOT include any reference comments.++ The resulting file MUST be syntactically and semantically correct. All code structures must be properly balanced.++ The full resulting file should be output within a <PlandexWholeFile> element, like this:++ <PlandexWholeFile>+ package main++ import "logger"++ function main() {+ logger.info("Hello, world!");+ exec()+ }+ </PlandexWholeFile>++ Do NOT include line numbers in the <PlandexWholeFile> element. Do NOT include reference comments in the <PlandexWholeFile> element. Output the ENTIRE file, no matter how long it is, with NO EXCEPTIONS. Include the resulting file *only* with no other text. Do NOT wrap the file output in triple backticks or any other formatting, except for the <PlandexWholeFile> element tags.++ Do NOT include any additional text after the <PlandexWholeFile> element. The output must end after </PlandexWholeFile>. DO NOT use the string <PlandexWholeFile> anywhere else in the output. ONLY use it to start the <PlandexWholeFile> element.+`diff --git a/app/server/syntax/structural_edits.go b/app/server/syntax/structural_edits.goindex de82d1fe..9622f732 100644--- a/app/server/syntax/structural_edits.go+++ b/app/server/syntax/structural_edits.go@@ -1,7 +1,6 @@package syntaximport (- "encoding/xml""fmt""log""regexp"@@ -27,7 +26,9 @@ const (NeedsVerifyReasonCodeRemoved NeedsVerifyReason = "code_removed"NeedsVerifyReasonCodeDuplicated NeedsVerifyReason = "code_duplicated"NeedsVerifyReasonAmbiguousLocation NeedsVerifyReason = "ambiguous_location"- NeedsVerifyReasonNoChanges NeedsVerifyReason = "no_changes"++ // not going to verify for no changes for now, too many false positives+ // NeedsVerifyReasonNoChanges NeedsVerifyReason = "no_changes")type ApplyChangesResult struct {@@ -36,16 +37,6 @@ type ApplyChangesResult struct {NeedsVerifyReasons []NeedsVerifyReason}-type FixedProposedUpdatesTag struct {- XMLName xml.Name `xml:"PlandexProposedUpdates"`- Content string `xml:",chardata"`-}--type ProposedUpdatesExplanationTag struct {- XMLName xml.Name `xml:"PlandexProposedUpdatesExplanation"`- Content string `xml:",chardata"`-}-type AnchorMap = map[int]inttype ReferenceBlock struct {@@ -211,16 +202,17 @@ func ApplyChanges(return res}- if strings.TrimSpace(res.NewFile) == strings.TrimSpace(original) {- // log.Println("ApplyChanges - no changes")- // log.Println("res.NewFile:")- // log.Println(res.NewFile)- // log.Println()- // log.Println("original:")- // log.Println(original)- res.NeedsVerifyReasons = append(res.NeedsVerifyReasons, NeedsVerifyReasonNoChanges)- return res- }+ // not going to verify for no changes for now, too many false positives+ // if strings.TrimSpace(res.NewFile) == strings.TrimSpace(original) {+ // // log.Println("ApplyChanges - no changes")+ // // log.Println("res.NewFile:")+ // // log.Println(res.NewFile)+ // // log.Println()+ // // log.Println("original:")+ // // log.Println(original)+ // res.NeedsVerifyReasons = append(res.NeedsVerifyReasons, NeedsVerifyReasonNoChanges)+ // return res+ // }originalLineMap := make(map[string]bool)for _, line := range originalLines {@@ -246,19 +238,34 @@ func ApplyChanges(// Check for lines in proposed updates that are duplicated in new filenewLineFreq := make(map[string]int)+ originalLineFreq := make(map[string]int)++ // First count frequencies in original file+ for _, line := range originalLines {+ trimmed := strings.TrimSpace(line)+ if len(trimmed) > duplicationThreshold {+ originalLineFreq[line]+++ }+ }++ // Count frequencies in new filefor _, line := range newLines {trimmed := strings.TrimSpace(line)if len(trimmed) > duplicationThreshold {newLineFreq[line]++}}++ // Check proposed lines against new frequencies, accounting for original duplicatesfor _, line := range proposedLines {trimmed := strings.TrimSpace(line)if len(trimmed) > duplicationThreshold {- if newLineFreq[line] > 1 {+ originalCount := originalLineFreq[line]+ if newLineFreq[line] > originalCount+1 {log.Println("ApplyChanges - code duplicated")log.Println("line:")log.Println(line)+ log.Printf("original occurrences: %d, new occurrences: %d", originalCount, newLineFreq[line])res.NeedsVerifyReasons = append(res.NeedsVerifyReasons, NeedsVerifyReasonCodeDuplicated)break}diff --git a/app/shared/ai_models.go b/app/shared/ai_models.goindex 3c3f07e5..848eb5bd 100644--- a/app/shared/ai_models.go+++ b/app/shared/ai_models.go@@ -172,8 +172,7 @@ var DefaultModelPack *ModelPack = &OpenRouterClaude3Dot5SonnetGPT4oModelPackfunc getPlannerModelConfig(name string) PlannerModelConfig {return PlannerModelConfig{- MaxConvoTokens: AvailableModelsByName[name].DefaultMaxConvoTokens,- ReservedOutputTokens: AvailableModelsByName[name].DefaultReservedOutputTokens,+ MaxConvoTokens: AvailableModelsByName[name].DefaultMaxConvoTokens,}}@@ -243,10 +242,11 @@ func init() {Description: "Uses OpenAI's latest gpt-4o model for heavy lifting, and latest version of gpt-4o-mini for lighter tasks.",Planner: PlannerRoleConfig{ModelRoleConfig: ModelRoleConfig{- Role: ModelRolePlanner,- BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,- Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,- TopP: DefaultConfigByRole[ModelRolePlanner].TopP,+ Role: ModelRolePlanner,+ BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,+ Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,+ TopP: DefaultConfigByRole[ModelRolePlanner].TopP,+ ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,},PlannerModelConfig: getPlannerModelConfig(openai.GPT4o),},@@ -257,10 +257,11 @@ func init() {TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,},Builder: ModelRoleConfig{- Role: ModelRoleBuilder,- BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,- Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,- TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,+ Role: ModelRoleBuilder,+ BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,+ Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,+ TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,+ ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,},Namer: ModelRoleConfig{Role: ModelRoleName,@@ -287,10 +288,11 @@ func init() {Description: "Uses Anthropic's Claude 3.5 Sonnet model (via OpenRouter) for planning, summarization, diff-based edits, and auto-continue, OpenAI gpt-4o for whole-file edits, and gpt-4o-mini for lighter tasks.",Planner: PlannerRoleConfig{ModelRoleConfig: ModelRoleConfig{- Role: ModelRolePlanner,- BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,- Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,- TopP: DefaultConfigByRole[ModelRolePlanner].TopP,+ Role: ModelRolePlanner,+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,+ Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,+ TopP: DefaultConfigByRole[ModelRolePlanner].TopP,+ ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,},PlannerModelConfig: getPlannerModelConfig("anthropic/claude-3.5-sonnet"),},@@ -301,16 +303,18 @@ func init() {TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,},Builder: ModelRoleConfig{- Role: ModelRoleBuilder,- BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,- Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,- TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,+ Role: ModelRoleBuilder,+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,+ Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,+ TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,+ ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,},WholeFileBuilder: &ModelRoleConfig{- Role: ModelRoleWholeFileBuilder,- BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,- Temperature: DefaultConfigByRole[ModelRoleWholeFileBuilder].Temperature,- TopP: DefaultConfigByRole[ModelRoleWholeFileBuilder].TopP,+ Role: ModelRoleWholeFileBuilder,+ BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,+ Temperature: DefaultConfigByRole[ModelRoleWholeFileBuilder].Temperature,+ TopP: DefaultConfigByRole[ModelRoleWholeFileBuilder].TopP,+ ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,},Namer: ModelRoleConfig{Role: ModelRoleName,@@ -337,10 +341,11 @@ func init() {Description: "Uses Anthropic's Claude 3.5 Sonnet model (via OpenRouter) for planning, builds, and auto-continue, and summarization, and Claude 3 Haiku for lighter tasks.",Planner: PlannerRoleConfig{ModelRoleConfig: ModelRoleConfig{- Role: ModelRolePlanner,- BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,- Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,- TopP: DefaultConfigByRole[ModelRolePlanner].TopP,+ Role: ModelRolePlanner,+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,+ Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,+ TopP: DefaultConfigByRole[ModelRolePlanner].TopP,+ ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,},PlannerModelConfig: getPlannerModelConfig("anthropic/claude-3.5-sonnet"),},@@ -351,10 +356,11 @@ func init() {TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,},Builder: ModelRoleConfig{- Role: ModelRoleBuilder,- BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,- Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,- TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,+ Role: ModelRoleBuilder,+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,+ Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,+ TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,+ ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,},Namer: ModelRoleConfig{Role: ModelRoleName,@@ -381,10 +387,11 @@ func init() {Description: "Uses Google's Gemini Pro 1.5 model for heavy lifting and Gemini Flash 1.5 for lighter tasks.",Planner: PlannerRoleConfig{ModelRoleConfig: ModelRoleConfig{- Role: ModelRolePlanner,- BaseModelConfig: AvailableModelsByName["google/gemini-pro-1.5"].BaseModelConfig,- Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,- TopP: DefaultConfigByRole[ModelRolePlanner].TopP,+ Role: ModelRolePlanner,+ BaseModelConfig: AvailableModelsByName["google/gemini-pro-1.5"].BaseModelConfig,+ Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,+ TopP: DefaultConfigByRole[ModelRolePlanner].TopP,+ ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,},PlannerModelConfig: getPlannerModelConfig("google/gemini-pro-1.5"),},@@ -395,10 +402,11 @@ func init() {TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,},Builder: ModelRoleConfig{- Role: ModelRoleBuilder,- BaseModelConfig: AvailableModelsByName["google/gemini-pro-1.5"].BaseModelConfig,- Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,- TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,+ Role: ModelRoleBuilder,+ BaseModelConfig: AvailableModelsByName["google/gemini-pro-1.5"].BaseModelConfig,+ Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,+ TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,+ ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,},Namer: ModelRoleConfig{Role: ModelRoleName,diff --git a/app/shared/data_models.go b/app/shared/data_models.goindex ff0e06ea..776f7318 100644--- a/app/shared/data_models.go+++ b/app/shared/data_models.go@@ -262,15 +262,15 @@ type AvailableModel struct {}type PlannerModelConfig struct {- MaxConvoTokens int `json:"maxConvoTokens"`- ReservedOutputTokens int `json:"maxOutputTokens"`+ MaxConvoTokens int `json:"maxConvoTokens"`}type ModelRoleConfig struct {- Role ModelRole `json:"role"`- BaseModelConfig BaseModelConfig `json:"baseModelConfig"`- Temperature float32 `json:"temperature"`- TopP float32 `json:"topP"`+ Role ModelRole `json:"role"`+ BaseModelConfig BaseModelConfig `json:"baseModelConfig"`+ Temperature float32 `json:"temperature"`+ TopP float32 `json:"topP"`+ ReservedOutputTokens int `json:"reservedOutputTokens"`}func (m *ModelRoleConfig) Scan(src interface{}) error {diff --git a/app/shared/plan_model_settings.go b/app/shared/plan_model_settings.goindex 182b410f..40f75649 100644--- a/app/shared/plan_model_settings.go+++ b/app/shared/plan_model_settings.go@@ -86,9 +86,9 @@ func (ps PlanSettings) GetPlannerMaxConvoTokens() int {func (ps PlanSettings) GetPlannerReservedOutputTokens() int {if ps.ModelOverrides.ReservedOutputTokens == nil {if ps.ModelPack == nil {- return DefaultModelPack.Planner.PlannerModelConfig.ReservedOutputTokens+ return DefaultModelPack.Planner.ReservedOutputTokens} else {- return ps.ModelPack.Planner.PlannerModelConfig.ReservedOutputTokens+ return ps.ModelPack.Planner.ReservedOutputTokens}} else {return *ps.ModelOverrides.ReservedOutputTokens