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
new openai models, bunch of git and plumbing work, working on fix for abort command
Dane Schneider37707e3d0162
diff --git a/cli/cmd/convo.go b/cli/cmd/convo.goindex 194e67be..590d4f26 100644--- a/cli/cmd/convo.go+++ b/cli/cmd/convo.go@@ -5,8 +5,10 @@ import ("os""plandex/lib""strings"+ "time""github.com/fatih/color"+ "github.com/plandex/plandex/shared""github.com/spf13/cobra")@@ -35,18 +37,37 @@ func convo(cmd *cobra.Command, args []string) {var convMarkdown []stringvar totalTokens int- for _, msg := range conversation {+ for i, msg := range conversation {var author stringif msg.Message.Role == "assistant" {- author = "Plandex"+ author = "π€ Plandex"} else if msg.Message.Role == "user" {- author = "You"+ author = "π¬ You"} else {author = msg.Message.Role}- header := fmt.Sprintf("#### %s | %s | %d πͺ",- author, msg.Timestamp, msg.Tokens)+ dt, err := time.Parse(shared.TsFormat, msg.Timestamp)+ if err != nil {+ fmt.Fprintln(os.Stderr, "Error parsing time:", err)+ continue+ }++ // format as above but start with day of week+ formattedTs := dt.Local().Format("Mon Jan 2, 2006 | 3:04:05pm MST")++ // if it's today then use 'Today' instead of the date+ if dt.Day() == time.Now().Day() {+ formattedTs = dt.Local().Format("Today | 3:04:05pm MST")+ }++ // if it's yesterday then use 'Yesterday' instead of the date+ if dt.Day() == time.Now().AddDate(0, 0, -1).Day() {+ formattedTs = dt.Local().Format("Yesterday | 3:04:05pm MST")+ }++ header := fmt.Sprintf("#### %d | %s | %s | %d πͺ", i+1,+ author, formattedTs, msg.Tokens)convMarkdown = append(convMarkdown, header, msg.Message.Content, "")totalTokens += msg.Tokens}diff --git a/cli/cmd/delete_plan.go b/cli/cmd/delete_plan.goindex 91d30c29..6e083d15 100644--- a/cli/cmd/delete_plan.go+++ b/cli/cmd/delete_plan.go@@ -50,7 +50,7 @@ func del(cmd *cobra.Command, args []string) {if err != nil {fmt.Fprintln(os.Stderr, "Error getting plans:", err)}- plan := plans[idx]+ plan := plans[idx-1]name = plan.Name} else {name = nameOrIdxdiff --git a/cli/cmd/ls.go b/cli/cmd/ls.goindex a321c562..cdfa6591 100644--- a/cli/cmd/ls.go+++ b/cli/cmd/ls.go@@ -80,7 +80,7 @@ func context(cmd *cobra.Command, args []string) {}row := []string{- strconv.Itoa(i),+ strconv.Itoa(i + 1)," " + icon + " " + id,t,strconv.Itoa(part.NumTokens), //+ " πͺ",diff --git a/cli/cmd/plans.go b/cli/cmd/plans.goindex 7887ce47..1685ff62 100644--- a/cli/cmd/plans.go+++ b/cli/cmd/plans.go@@ -66,7 +66,7 @@ func plans(cmd *cobra.Command, args []string) {}row := []string{- strconv.Itoa(i),+ strconv.Itoa(i + 1),name,format.Time(updatedAt),format.Time(createdAt),diff --git a/cli/cmd/rm.go b/cli/cmd/rm.goindex c5eee19e..ddd73430 100644--- a/cli/cmd/rm.go+++ b/cli/cmd/rm.go@@ -33,7 +33,7 @@ func contextRm(cmd *cobra.Command, args []string) {for i, part := range context {path := lib.CreateContextFileName(part.Name, part.Sha)for _, id := range args {- if fmt.Sprintf("%d", i) == id || part.Name == id || part.FilePath == id || part.Url == id {+ if fmt.Sprintf("%d", i+1) == id || part.Name == id || part.FilePath == id || part.Url == id {toRemovePaths = append(toRemovePaths, path)toRemoveParts = append(toRemoveParts, part)breakdiff --git a/cli/lib/api_abort.go b/cli/lib/api_abort.goindex fd6b1d42..8b0dc30c 100644--- a/cli/lib/api_abort.go+++ b/cli/lib/api_abort.go@@ -7,11 +7,13 @@ import ()func (api *API) Abort(proposalId string) error {+ fmt.Println("api aborting proposal", proposalId)+serverUrl := apiHost + "/abort"- req, err := http.NewRequest("GET", serverUrl, nil)+ req, err := http.NewRequest("DELETE", serverUrl, nil)if err != nil {- return fmt.Errorf("failed to create request: %s\n", err)+ return fmt.Errorf("failed to create request: %s", err)}q := req.URL.Query()@@ -20,7 +22,7 @@ func (api *API) Abort(proposalId string) error {resp, err := http.DefaultClient.Do(req)if err != nil {- return fmt.Errorf("failed to send request to server: %s\n", err)+ return fmt.Errorf("failed to send request to server: %s", err)}defer resp.Body.Close()diff --git a/cli/lib/context_fs.go b/cli/lib/context_fs.goindex 67c0df31..a6048ddf 100644--- a/cli/lib/context_fs.go+++ b/cli/lib/context_fs.go@@ -5,6 +5,7 @@ import ("fmt""os""path/filepath"+ "strings""github.com/plandex/plandex/shared")@@ -13,7 +14,8 @@ import (func CreateContextFileName(name, sha string) string {// Extract the first 8 characters of the shashaSubstring := sha[:8]- return fmt.Sprintf("%s.%s", name, shaSubstring)+ s := strings.ReplaceAll(name, string(os.PathSeparator), "_")+ return fmt.Sprintf("%s.%s", s, shaSubstring)}func ContextRemoveFiles(paths []string) error {diff --git a/cli/lib/context_load.go b/cli/lib/context_load.goindex f40d3001..9275db66 100644--- a/cli/lib/context_load.go+++ b/cli/lib/context_load.go@@ -233,7 +233,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) (int,contextPart := &shared.ModelContextPart{Type: shared.ContextDirectoryTreeType,- Name: name,+ Name: inputFilePath,FilePath: inputFilePath,Body: body,Sha: sha,@@ -289,13 +289,11 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) (int,}()- _, fileName := filepath.Split(path)-ts := shared.StringTs()contextPart := &shared.ModelContextPart{Type: shared.ContextFileType,- Name: fileName,+ Name: path,Body: body,FilePath: path,Sha: sha,diff --git a/cli/lib/conversation.go b/cli/lib/conversation.goindex db57ab6d..35ddda9b 100644--- a/cli/lib/conversation.go+++ b/cli/lib/conversation.go@@ -177,10 +177,26 @@ func LoadSummaries() ([]shared.ConversationSummary, error) {func appendConversation(params types.AppendConversationParams) error {// Create or append to conversation fileconversationFilePath := filepath.Join(ConversationSubdir, fmt.Sprintf("%s.md", params.Timestamp))- userHeader := fmt.Sprintf("@@@!>user|%s|%d\n\n", params.Timestamp, params.PromptTokens)- responseHeader := fmt.Sprintf("@@@!>response|%s|%d\n\n", params.ResponseTimestamp, params.ReplyTokens)- conversationFileContents := fmt.Sprintf("%s%s\n\n%s%s", userHeader, params.Prompt, responseHeader, params.Reply)+ var header string+ var body string+ var tokens int+ var t string+ if params.PromptParams != nil {+ t = "prompt"+ header = fmt.Sprintf("@@@!>user|%s|%d\n\n", params.Timestamp, params.PromptParams.PromptTokens)+ body = params.PromptParams.Prompt+ tokens = params.PromptParams.PromptTokens+ } else if params.ReplyParams != nil {+ t = "reply"+ header = fmt.Sprintf("@@@!>response|%s|%d\n\n", params.ReplyParams.ResponseTimestamp, params.ReplyParams.ReplyTokens)+ body = params.ReplyParams.Reply+ tokens = params.ReplyParams.ReplyTokens+ } else {+ return fmt.Errorf("invalid params: either prompt or reply params must be provided")+ }++ conversationFileContents := fmt.Sprintf("%s%s\n\n", header, body)conversationFile, err := os.OpenFile(conversationFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)if err != nil {return fmt.Errorf("failed to write conversation file: %s", err)@@ -192,8 +208,24 @@ func appendConversation(params types.AppendConversationParams) error {return fmt.Errorf("failed to write conversation file: %s", err)}- // Update plan state -- will be written to file by caller- params.PlanState.ConvoTokens += params.PromptTokens + params.ReplyTokens+ params.PlanState.NumMessages+++ params.PlanState.ConvoTokens += tokens+ err = SetPlanState(params.PlanState, shared.StringTs())+ if err != nil {+ return fmt.Errorf("failed to update plan state: %s", err)+ }++ var desc string+ if t == "prompt" {+ desc = "user prompt"+ } else {+ desc = "Plandex reply"+ }+ err = GitCommitConvoUpdate(fmt.Sprintf("Message #%d | %s | %d tokens", params.PlanState.NumMessages, desc, tokens))++ if err != nil {+ return fmt.Errorf("failed to commit conversation update: %s", err)+ }return nil}@@ -244,5 +276,15 @@ func saveLatestConvoSummary(rootId string) error {err = os.WriteFile(summaryFilePath, []byte(summaryFileContents), 0644)+ if err != nil {+ return fmt.Errorf("failed to write summary file: %s", err)+ }++ err = GitCommitConvoUpdate(fmt.Sprintf("Summarized up to message #%d | %d tokens", summary.NumMessages-1, summary.Tokens))++ if err != nil {+ return fmt.Errorf("failed to commit conversation update: %s", err)+ }+return err}diff --git a/cli/lib/fs.go b/cli/lib/fs.goindex eeb28897..607b2730 100644--- a/cli/lib/fs.go+++ b/cli/lib/fs.go@@ -20,6 +20,7 @@ var CurrentPlanName stringvar CurrentPlanRootDir stringvar PlanSubdir stringvar PlanFilesDir string+var PlanDescriptionsDir stringvar ConversationSubdir stringvar ContextSubdir string@@ -93,6 +94,7 @@ func LoadCurrentPlan() error {CurrentPlanRootDir = filepath.Join(PlandexDir, CurrentPlanName)PlanSubdir = filepath.Join(CurrentPlanRootDir, "plan")PlanFilesDir = filepath.Join(PlanSubdir, "files")+ PlanDescriptionsDir = filepath.Join(PlanSubdir, "descriptions")ConversationSubdir = filepath.Join(CurrentPlanRootDir, "conversation")ContextSubdir = filepath.Join(CurrentPlanRootDir, "context")diff --git a/cli/lib/git.go b/cli/lib/git.goindex faab996b..66b325b9 100644--- a/cli/lib/git.go+++ b/cli/lib/git.go@@ -99,16 +99,10 @@ func GitCommit(repoDir, commitMsg string, lockMutex bool) error {return nil}-func GitCommitContextUpdate(commitMsg string) error {- err := GitAddAndCommit(ContextSubdir, commitMsg)-- if err != nil {- return fmt.Errorf("failed to commit context: %v", err)- }-- err = GitAdd(CurrentPlanRootDir, ContextSubdir, true)+func gitCommitRootUpdate(commitMsg string) error {+ err := GitAdd(CurrentPlanRootDir, ".", true)if err != nil {- return fmt.Errorf("failed to stage submodule changes in context dir: %s", err)+ return fmt.Errorf("failed to root plan dir changes: %s", err)}// Commit these staged submodule changes in the root repo@@ -118,36 +112,44 @@ func GitCommitContextUpdate(commitMsg string) error {}return nil+}-func GitCommitPlanUpdate(commitMsg string) error {+func GitCommitContextUpdate(commitMsg string) error {+ err := GitAddAndCommit(ContextSubdir, commitMsg)- err := GitAddAndCommit(ConversationSubdir, commitMsg)if err != nil {- return fmt.Errorf("failed to commit files to conversation dir: %s", err)+ return fmt.Errorf("failed to commit context: %v", err)}- err = GitAddAndCommit(PlanSubdir, commitMsg)+ err = GitAdd(CurrentPlanRootDir, ContextSubdir, true)if err != nil {- return fmt.Errorf("failed to commit files to plan dir: %s", err)+ return fmt.Errorf("failed to stage submodule changes in context dir: %s", err)}- // Stage changes in the submodules in the root repo- err = GitAdd(CurrentPlanRootDir, ConversationSubdir, true)+ return gitCommitRootUpdate(commitMsg)+}++func GitCommitConvoUpdate(commitMsg string) error {+ err := GitAddAndCommit(ConversationSubdir, commitMsg)+if err != nil {- return fmt.Errorf("failed to stage submodule changes in conversation dir: %s", err)+ return fmt.Errorf("failed to commit convo update: %v", err)}- err = GitAdd(CurrentPlanRootDir, PlanSubdir, true)+ err = GitAdd(CurrentPlanRootDir, ConversationSubdir, true)if err != nil {- return fmt.Errorf("failed to stage submodule changes in plan dir: %s", err)+ return fmt.Errorf("failed to stage submodule changes in convo dir: %s", err)}- // Commit these staged submodule changes in the root repo- err = GitCommit(CurrentPlanRootDir, commitMsg, true)+ return gitCommitRootUpdate(commitMsg)+}++func GitCommitPlanUpdate(commitMsg string) error {+ err := GitAddAndCommit(PlanSubdir, commitMsg)if err != nil {- return fmt.Errorf("failed to commit submodule updates in root dir: %s", err)+ return fmt.Errorf("failed to commit files to plan dir: %s", err)}- return nil+ return gitCommitRootUpdate(commitMsg)}diff --git a/cli/lib/proposal.go b/cli/lib/proposal.goindex 0fbfcd30..dca06faa 100644--- a/cli/lib/proposal.go+++ b/cli/lib/proposal.go@@ -5,6 +5,7 @@ import ("encoding/json""fmt""os"+ "path/filepath""plandex/format""plandex/types""strconv"@@ -50,10 +51,14 @@ func Propose(prompt string) error {if CurrentPlanIsDraft() {fileNameResp, err := Api.FileName(prompt)if err != nil {- fmt.Fprintln(os.Stderr, "\nError summarizing prompt:", err)+ fmt.Fprintln(os.Stderr, "\nError getting file name for prompt:", err)+ return err+ }+ err = RenameCurrentDraftPlan(format.GetFileNameWithoutExt(fileNameResp.FileName))+ if err != nil {+ fmt.Fprintln(os.Stderr, "\nError renaming draft plan:", err)return err}- RenameCurrentDraftPlan(format.GetFileNameWithoutExt(fileNameResp.FileName))}timestamp := shared.StringTs()@@ -92,10 +97,20 @@ func Propose(prompt string) error {}}- var promptNumTokens int- go func() {- promptNumTokens = shared.GetNumTokens(prompt)- }()+ promptNumTokens := shared.GetNumTokens(prompt)++ err = appendConversation(types.AppendConversationParams{+ Timestamp: timestamp,+ PlanState: planState,+ PromptParams: &types.AppendConversationPromptParams{+ Prompt: prompt,+ PromptTokens: promptNumTokens,+ },+ })++ if err != nil {+ return fmt.Errorf("failed to append prompt to conversation: %s", err)+ }printReply := func() {ClearScreen()@@ -130,22 +145,19 @@ func Propose(prompt string) error {s.Start()}- appendConvo := func() {+ appendConvoReply := func() error {var totalTokens int_, _, _, totalTokens = replyTokenCounter.FinishAndRead()- err := appendConversation(types.AppendConversationParams{- Timestamp: timestamp,- ResponseTimestamp: desc.ResponseTimestamp,- Prompt: prompt,- PromptTokens: promptNumTokens,- Reply: reply,- ReplyTokens: totalTokens,- PlanState: planState,+ return appendConversation(types.AppendConversationParams{+ Timestamp: timestamp,+ PlanState: planState,+ ReplyParams: &types.AppendConversationReplyParams{+ ResponseTimestamp: desc.ResponseTimestamp,+ Reply: reply,+ ReplyTokens: totalTokens,+ },})- if err != nil {- fmt.Printf("failed to append conversation: %s", err)- }}contextByFilePath := make(map[string]*shared.ModelContextPart)@@ -240,18 +252,29 @@ func Propose(prompt string) error {endReply()} else {- err := json.Unmarshal([]byte(content), &desc)+ bytes := []byte(content)++ err := json.Unmarshal(bytes, &desc)if err != nil {onError(fmt.Errorf("error parsing plan description: %v", err))return}- planState.Description = desc- appendConvo()+ err = os.MkdirAll(PlanDescriptionsDir, os.ModePerm)+ if err != nil {+ onError(fmt.Errorf("failed to create plan descriptions directory: %s", err))+ return+ }+ descriptionsPath := filepath.Join(PlanDescriptionsDir, desc.ResponseTimestamp+".json")+ err = os.WriteFile(descriptionsPath, bytes, 0644)+ if err != nil {+ onError(fmt.Errorf("failed to write plan description to file: %s", err))+ return+ }- err = SetPlanState(planState, shared.StringTs())+ err = appendConvoReply()if err != nil {- onError(fmt.Errorf("failed to update plan state: %s", err))+ onError(fmt.Errorf("failed to append reply to conversation: %s", err))return}@@ -317,6 +340,12 @@ func Propose(prompt string) error {if len(finishedByPath) == len(files) {filesFinished = true+ err = GitCommitPlanUpdate(desc.CommitMsg)+ if err != nil {+ onError(fmt.Errorf("failed to commit root update: %s", err))+ return+ }+if streamFinished {close(done)}@@ -338,6 +367,7 @@ func Propose(prompt string) error {BackToMain()return fmt.Errorf("failed to send prompt to server: %s", err)}+for _, part := range apiReq.ModelContext {contextByFilePath[part.FilePath] = part}@@ -470,7 +500,11 @@ func checkOutdatedContext(s *spinner.Spinner) (bool, error) {}}- color.New(color.FgHiCyan, color.Bold).Printf("%s in context have been modified π\n\n", msg)+ phrase := "have been"+ if len(outdatedRes.UpdatedParts) == 1 {+ phrase = "has been"+ }+ color.New(color.FgHiCyan, color.Bold).Printf("%s in context %s modified π\n\n", msg, phrase)table := TableForContextUpdateRes(outdatedRes)table.Render()diff --git a/cli/types/types.go b/cli/types/types.goindex 7893c5d9..3aaf3021 100644--- a/cli/types/types.go+++ b/cli/types/types.go@@ -23,26 +23,34 @@ type APIHandler interface {}type AppendConversationParams struct {- Timestamp string+ Timestamp string+ PlanState *PlanState+ PromptParams *AppendConversationPromptParams+ ReplyParams *AppendConversationReplyParams+}++type AppendConversationPromptParams struct {+ Prompt string+ PromptTokens int+}++type AppendConversationReplyParams struct {ResponseTimestamp string- Prompt stringReply string- PromptTokens intReplyTokens int- PlanState *PlanState}type PlanState struct {- Name string `json:"name"`- ProposalId string `json:"proposalId"`- RootId string `json:"rootId"`- CreatedAt string `json:"createdAt"`- UpdatedAt string `json:"updatedAt"`- Description *shared.PlanDescription `json:"description"`- ContextTokens int `json:"contextTokens"`- ContextUpdatableTokens int `json:"contextUpdatableTokens"`- ConvoTokens int `json:"convoTokens"`- ConvoSummarizedTokens int `json:"convoSummarizedTokens"`+ Name string `json:"name"`+ ProposalId string `json:"proposalId"`+ RootId string `json:"rootId"`+ CreatedAt string `json:"createdAt"`+ UpdatedAt string `json:"updatedAt"`+ ContextTokens int `json:"contextTokens"`+ ContextUpdatableTokens int `json:"contextUpdatableTokens"`+ ConvoTokens int `json:"convoTokens"`+ ConvoSummarizedTokens int `json:"convoSummarizedTokens"`+ NumMessages int `json:"numMessages"`}type PlanSettings struct {diff --git a/server/main.go b/server/main.goindex f6e61754..ece9f115 100644--- a/server/main.go+++ b/server/main.go@@ -23,7 +23,7 @@ func main() {r := mux.NewRouter()r.HandleFunc("/proposal", handlers.ProposalHandler).Methods("POST")- r.HandleFunc("/abort-proposal", handlers.AbortProposalHandler).Methods("DELETE")+ r.HandleFunc("/abort", handlers.AbortProposalHandler).Methods("DELETE")r.HandleFunc("/short-summary", handlers.ShortSummaryHandler).Methods("POST")r.HandleFunc("/filename", handlers.FileNameHandler).Methods("POST")r.HandleFunc("/convo-summary/{rootId}", handlers.ConvoSummaryHandler).Methods("GET")diff --git a/server/model/constants.go b/server/model/constants.gonew file mode 100644index 00000000..8e079983--- /dev/null+++ b/server/model/constants.go@@ -0,0 +1,6 @@+package model++import "github.com/sashabaranov/go-openai"++const StrongModel = "gpt-4-1106-preview" //openai.GPT4+const WeakModel = openai.GPT3Dot5Turbodiff --git a/server/model/fix_json.go b/server/model/fix_json.godeleted file mode 100644index 534a2c18..00000000--- a/server/model/fix_json.go+++ /dev/null@@ -1,90 +0,0 @@-// this file is unused as it hasn't yet been needed-// keeping it around for now in case it's useful at some point--package model--import (- "context"- "encoding/json"- "fmt"-- "github.com/davecgh/go-spew/spew"- "github.com/sashabaranov/go-openai"- "github.com/sashabaranov/go-openai/jsonschema"-)--type fixed struct {- FixedJson string `json:"fixedJson"`-}--func FixJson(invalidJson string) ([]byte, error) {- messages := []openai.ChatCompletionMessage{- {- Role: openai.ChatMessageRoleSystem,- Content: `You are an AI JSON fixer. You take invalid JSON and fix it so that it becomes valid. You should call the 'fixed' function with the 'fixedJson' parameter, a string containing valid JSON. You must *always* call the 'fixed' function and never call any other function.`,- },- {- Role: openai.ChatMessageRoleUser,- Content: fmt.Sprintf("Fix the following invalid JSON and call the 'fixed' function with the result:\n\n%s",- invalidJson),- },- }-- resp, err := Client.CreateChatCompletion(- context.Background(),- openai.ChatCompletionRequest{- Model: openai.GPT4,- Functions: []openai.FunctionDefinition{{- Name: "fixed",- Parameters: &jsonschema.Definition{- Type: jsonschema.Object,- Properties: map[string]jsonschema.Definition{- "fixedJson": {- Type: jsonschema.String,- Description: "Valid json.",- Items: &jsonschema.Definition{- Type: jsonschema.String,- },- },- },- Required: []string{"fixedJson"},- },- }},- Messages: messages,- })-- if err != nil {- return nil, err- }-- spew.Dump(resp)-- var byteRes []byte- for _, choice := range resp.Choices {- if choice.FinishReason == "function_call" && choice.Message.Role == "assistant" && choice.Message.FunctionCall != nil && choice.Message.FunctionCall.Name == "fixed" {- fnCall := choice.Message.FunctionCall- byteRes = []byte(fnCall.Arguments)- }- }-- if len(byteRes) == 0 {- return nil, fmt.Errorf("no 'fixed' function call found in response")- }-- // Clean the body of the response- // cleanBody, err := shared.CleanJson(byteRes)- // if err != nil {- // return nil, fmt.Errorf("error cleaning JSON: %w", err)- // }-- // validate the JSON response- var fixResp fixed- err = json.Unmarshal(byteRes, &fixResp)-- if err != nil {- fmt.Printf("Failed JSON: %s\n", byteRes) // Printing the JSON causing the failure- return nil, fmt.Errorf("error unmarshalling JSON: %w", err)- }-- return byteRes, nil-}diff --git a/server/model/name.go b/server/model/name.goindex 2ceb8ec9..b3e66545 100644--- a/server/model/name.go+++ b/server/model/name.go@@ -15,7 +15,7 @@ func FileName(text string) ([]byte, int, error) {resp, err := Client.CreateChatCompletion(context.Background(),openai.ChatCompletionRequest{- Model: openai.GPT3Dot5Turbo,+ Model: WeakModel,Functions: []openai.FunctionDefinition{{Name: "nameFile",Parameters: &jsonschema.Definition{diff --git a/server/model/proposal/abort.go b/server/model/proposal/abort.goindex 06d27929..e7154325 100644--- a/server/model/proposal/abort.go+++ b/server/model/proposal/abort.go@@ -3,6 +3,8 @@ package proposalimport "fmt"func AbortProposal(proposalId string) error {+ fmt.Println("aborting proposal", proposalId)+proposal := proposals.Get(proposalId)if proposal == nil {return fmt.Errorf("proposal not found")diff --git a/server/model/proposal/build.go b/server/model/proposal/build.goindex 94b3d503..c31e4b95 100644--- a/server/model/proposal/build.go+++ b/server/model/proposal/build.go@@ -218,7 +218,7 @@ func buildPlan(proposalId string, fileContents map[string]string, numTokensByFil}modelReq := openai.ChatCompletionRequest{- Model: openai.GPT4,+ Model: model.StrongModel,Functions: functions,Messages: fileMessages,}diff --git a/server/model/proposal/create.go b/server/model/proposal/create.goindex 2edd1b66..6dbb2400 100644--- a/server/model/proposal/create.go+++ b/server/model/proposal/create.go@@ -215,7 +215,7 @@ func CreateProposal(req shared.PromptRequest, onStream types.OnStreamFunc) errorreplyInfo := shared.NewReplyInfo()modelReq := openai.ChatCompletionRequest{- Model: openai.GPT4,+ Model: model.StrongModel,Messages: messages,Stream: true,}@@ -314,8 +314,10 @@ func CreateProposal(req shared.PromptRequest, onStream types.OnStreamFunc) errorvar summaryMessages []openai.ChatCompletionMessagevar latestSummary *shared.ConversationSummary+ var numMessagesSummarized int = 0if len(req.ConversationSummaries) > 0 {latestSummary = &req.ConversationSummaries[len(req.ConversationSummaries)-1]+ numMessagesSummarized = latestSummary.NumMessages}if latestSummary == nil {@@ -334,7 +336,7 @@ func CreateProposal(req shared.PromptRequest, onStream types.OnStreamFunc) errorContent: proposal.Content,})- summary, err := model.PlanSummary(summaryMessages, responseTs)+ summary, err := model.PlanSummary(summaryMessages, responseTs, numMessagesSummarized+1)if err != nil {fmt.Printf("Error generating plan summary for root %s: %v\n", proposal.RootId, err)@@ -396,7 +398,6 @@ func CreateProposal(req shared.PromptRequest, onStream types.OnStreamFunc) erroronStream(planDescriptionJson, nil)if len(files) == 0 {- onStream(planDescriptionJson, nil)onStream(shared.STREAM_FINISHED, nil)} else {onStream(shared.STREAM_BUILD_PHASE, nil)diff --git a/server/model/proposal/describe.go b/server/model/proposal/describe.goindex f957977d..e479adf6 100644--- a/server/model/proposal/describe.go+++ b/server/model/proposal/describe.go@@ -17,7 +17,7 @@ func genPlanDescriptionJson(proposalId string, ctx context.Context) (*shared.PlaplanDescResp, err := model.Client.CreateChatCompletion(ctx,openai.ChatCompletionRequest{- Model: openai.GPT3Dot5Turbo,+ Model: model.WeakModel,Functions: []openai.FunctionDefinition{{Name: "describePlan",Parameters: &jsonschema.Definition{diff --git a/server/model/summarize.go b/server/model/summarize.goindex f0dfc491..0b39b8ee 100644--- a/server/model/summarize.go+++ b/server/model/summarize.go@@ -15,7 +15,7 @@ func ShortSummary(text string) ([]byte, error) {resp, err := Client.CreateChatCompletion(context.Background(),openai.ChatCompletionRequest{- Model: openai.GPT3Dot5Turbo,+ Model: WeakModel,Functions: []openai.FunctionDefinition{{Name: "summarize",Parameters: &jsonschema.Definition{@@ -77,7 +77,7 @@ func ShortSummary(text string) ([]byte, error) {return byteRes, nil}-func PlanSummary(conversation []openai.ChatCompletionMessage, lastMessageTimestamp string) (*shared.ConversationSummary, error) {+func PlanSummary(conversation []openai.ChatCompletionMessage, lastMessageTimestamp string, numMessages int) (*shared.ConversationSummary, error) {messages := []openai.ChatCompletionMessage{{Role: openai.ChatMessageRoleSystem,@@ -98,8 +98,7 @@ func PlanSummary(conversation []openai.ChatCompletionMessage, lastMessageTimestaresp, err := Client.CreateChatCompletion(context.Background(),openai.ChatCompletionRequest{- Model: openai.GPT4,- // Model: openai.GPT3Dot5Turbo16K,+ Model: StrongModel,Messages: messages,},)diff --git a/shared/tokens.go b/shared/tokens.goindex acb2dd09..b15481e3 100644--- a/shared/tokens.go+++ b/shared/tokens.go@@ -7,8 +7,8 @@ import ("github.com/pkoukk/tiktoken-go")-const MaxTokens int = 7500 // leave room for the model ouput-const MaxContextTokens int = 6500 // leave room for the conversation history+const MaxTokens int = 16000 // leave room for the model ouput+const MaxContextTokens int = 15000 // leave room for the conversation historyfunc GetNumTokens(text string) (numTokens int) {tkm, err := tiktoken.EncodingForModel("gpt-4")diff --git a/shared/types.go b/shared/types.goindex a5d75f52..edf975e4 100644--- a/shared/types.go+++ b/shared/types.go@@ -82,4 +82,5 @@ type ConversationSummary struct {Summary stringTokens intLastMessageTimestamp string+ NumMessages int}