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
Data that is piped into `plandex load` is now automatically given a name
Dane Schneiderf9617f9cb66f
diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.goindex fd50f93a..3b260916 100644--- a/app/cli/lib/context_load.go+++ b/app/cli/lib/context_load.go@@ -45,9 +45,18 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {}if len(pipedData) > 0 {+ apiKeys := MustVerifyApiKeysSilent()+ openAIBase := os.Getenv("OPENAI_API_BASE")+ if openAIBase == "" {+ openAIBase = os.Getenv("OPENAI_ENDPOINT")+ }+loadContextReq = append(loadContextReq, &shared.LoadContextParams{ContextType: shared.ContextPipedDataType,Body: string(pipedData),+ ApiKeys: apiKeys,+ OpenAIBase: openAIBase,+ OpenAIOrgId: os.Getenv("OPENAI_ORG_ID"),})}}diff --git a/app/server/handlers/context_helper.go b/app/server/handlers/context_helper.goindex a301cd61..20495fad 100644--- a/app/server/handlers/context_helper.go+++ b/app/server/handlers/context_helper.go@@ -6,6 +6,7 @@ import ("log""net/http""plandex-server/db"+ "plandex-server/model""plandex-server/types""github.com/plandex/plandex/shared"@@ -14,6 +15,44 @@ import (func loadContexts(w http.ResponseWriter, r *http.Request, auth *types.ServerAuth, loadReq *shared.LoadContextRequest, plan *db.Plan, branchName string) (*shared.LoadContextResponse, []*db.Context) {var err error+ // get name for piped data if present (there will only be one)+ for _, context := range *loadReq {+ if context.ContextType == shared.ContextPipedDataType {+ settings, err := db.GetPlanSettings(plan, true)++ if err != nil {+ log.Printf("Error generating name for piped data: %v\n", err)+ http.Error(w, "Error generating name for piped data: "+err.Error(), http.StatusInternalServerError)+ return nil, nil+ }++ clients := initClients(+ initClientsParams{+ w: w,+ apiKeys: context.ApiKeys,+ openAIBase: context.OpenAIBase,+ openAIOrgId: context.OpenAIOrgId,+ plan: plan,+ },+ )++ envVar := settings.ModelPack.Namer.BaseModelConfig.ApiKeyEnvVar+ client := clients[envVar]++ name, err := model.GenPipedDataName(client, settings.ModelPack.Namer, context.Body)++ if err != nil {+ log.Printf("Error generating name for piped data: %v\n", err)+ http.Error(w, "Error generating name for piped data: "+err.Error(), http.StatusInternalServerError)+ return nil, nil+ }++ context.Name = name++ break+ }+ }+ctx, cancel := context.WithCancel(context.Background())unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {diff --git a/app/server/model/name.go b/app/server/model/name.goindex 3ea97666..dece2e88 100644--- a/app/server/model/name.go+++ b/app/server/model/name.go@@ -4,6 +4,7 @@ import ("context""encoding/json""fmt"+ "log""plandex-server/model/prompts""github.com/plandex/plandex/shared"@@ -14,15 +15,10 @@ func GenPlanName(client *openai.Client, config shared.ModelRoleConfig, planContemessages := []openai.ChatCompletionMessage{{Role: openai.ChatMessageRoleSystem,- Content: prompts.SysPlanName,+ Content: prompts.GetPlanNamePrompt(planContent),},}- messages = append(messages, openai.ChatCompletionMessage{- Role: openai.ChatMessageRoleUser,- Content: prompts.GetPlanNamePrompt(planContent),- })-var responseFormat *openai.ChatCompletionResponseFormatif config.BaseModelConfig.HasJsonResponseMode {responseFormat = &openai.ChatCompletionResponseFormat{Type: "json_object"}@@ -85,3 +81,82 @@ func GenPlanName(client *openai.Client, config shared.ModelRoleConfig, planContereturn nameRes.PlanName, nil}++func GenPipedDataName(client *openai.Client, config shared.ModelRoleConfig, pipedContent string) (string, error) {+ messages := []openai.ChatCompletionMessage{+ {+ Role: openai.ChatMessageRoleSystem,+ Content: prompts.GetPipedDataNamePrompt(pipedContent),+ },+ }++ var responseFormat *openai.ChatCompletionResponseFormat+ if config.BaseModelConfig.HasJsonResponseMode {+ responseFormat = &openai.ChatCompletionResponseFormat{Type: "json_object"}+ }++ log.Println("calling piped data name model")+ // log.Printf("model: %s\n", config.BaseModelConfig.ModelName)+ // log.Printf("temperature: %f\n", config.Temperature)+ // log.Printf("topP: %f\n", config.TopP)++ // log.Printf("messages: %v\n", messages)+ // log.Println(spew.Sdump(messages))++ resp, err := CreateChatCompletionWithRetries(+ client,+ context.Background(),+ openai.ChatCompletionRequest{+ Model: config.BaseModelConfig.ModelName,+ Tools: []openai.Tool{+ {+ Type: "function",+ Function: &prompts.PipedDataNameFn,+ },+ },+ ToolChoice: openai.ToolChoice{+ Type: "function",+ Function: openai.ToolFunction{+ Name: prompts.PipedDataNameFn.Name,+ },+ },+ Temperature: config.Temperature,+ TopP: config.TopP,+ Messages: messages,+ ResponseFormat: responseFormat,+ },+ )++ var res string+ var nameRes prompts.PipedDataNameRes++ if err != nil {+ fmt.Printf("Error during piped data name model call: %v\n", err)+ return "", err+ }++ for _, choice := range resp.Choices {+ if len(choice.Message.ToolCalls) == 1 &&+ choice.Message.ToolCalls[0].Function.Name == prompts.PipedDataNameFn.Name {+ fnCall := choice.Message.ToolCalls[0].Function+ res = fnCall.Arguments+ break+ }+ }++ if res == "" {+ fmt.Println("no namePipedData function call found in response")+ return "", err+ }++ bytes := []byte(res)++ err = json.Unmarshal(bytes, &nameRes)+ if err != nil {+ fmt.Printf("Error unmarshalling piped data name response: %v\n", err)+ return "", err+ }++ return nameRes.Name, nil++}diff --git a/app/server/model/prompts/name.go b/app/server/model/prompts/name.goindex 337874a2..4f880c7a 100644--- a/app/server/model/prompts/name.go+++ b/app/server/model/prompts/name.go@@ -27,3 +27,26 @@ var PlanNameFn = openai.FunctionDefinition{func GetPlanNamePrompt(text string) string {return SysPlanName + "\n\nContent:\n" + text}++type PipedDataNameRes struct {+ Name string `json:"name"`+}++const SysPipedDataName = "You are an AI namer that creates a name for output that has been piped into context. Take the output into account and also try to guess what command produced it if you can. Call the 'namePipedData' function with a valid JSON object that includes the 'name' key. 'name' is a *short* lowercase name for the data. Use dashes as word separators. No spaces, numbers, or special characters. Shorten and abbreviate where possible. You must ALWAYS call the 'namePipedData' function. Don't call any other function."++var PipedDataNameFn = openai.FunctionDefinition{+ Name: "namePipedData",+ Parameters: &jsonschema.Definition{+ Type: jsonschema.Object,+ Properties: map[string]jsonschema.Definition{+ "name": {+ Type: jsonschema.String,+ },+ },+ Required: []string{"name"},+ },+}++func GetPipedDataNamePrompt(text string) string {+ return SysPipedDataName + "\n\nContent:\n" + text+}diff --git a/app/shared/req_res.go b/app/shared/req_res.goindex 3f3a6a75..9db5f042 100644--- a/app/shared/req_res.go+++ b/app/shared/req_res.go@@ -153,6 +153,11 @@ type LoadContextParams struct {FilePath string `json:"file_path"`Body string `json:"body"`ForceSkipIgnore bool `json:"forceSkipIgnore"`++ // For naming piped data+ ApiKeys map[string]string `json:"apiKeys"`+ OpenAIBase string `json:"openAIBase"`+ OpenAIOrgId string `json:"openAIOrgId"`}type LoadContextRequest []*LoadContextParamsdiff --git a/releases/cli/versions/0.9.1.md b/releases/cli/versions/0.9.1.mdindex d133849c..37f3572f 100644--- a/releases/cli/versions/0.9.1.md+++ b/releases/cli/versions/0.9.1.md@@ -1,3 +1,5 @@- Fix for occasional stream TUI panic during builds with long file paths (https://github.com/plandex-ai/plandex/issues/105)- If auto-upgrade fails due to a permissions issue, suggest re-running command with `sudo` (https://github.com/plandex-ai/plandex/issues/97 - thanks @kalil0321!)-- Include 'openrouter'in list of model providers when adding a custom model (https://github.com/plandex-ai/plandex/issues/107)\ No newline at end of file+- Include 'openrouter' in list of model providers when adding a custom model (https://github.com/plandex-ai/plandex/issues/107)+- Make prompts that shouldn't be optional required across the board (https://github.com/plandex-ai/plandex/issues/108)+- Data that is piped into `plandex load` is now automatically given a name.\ No newline at end of filediff --git a/releases/server/versions/0.9.1.md b/releases/server/versions/0.9.1.mdindex 8269b62a..94a3aef1 100644--- a/releases/server/versions/0.9.1.md+++ b/releases/server/versions/0.9.1.md@@ -1,3 +1,4 @@- Added an auto-verify and auto-fix step to plan builds to improve reliability and reduce syntax errors, mistaken duplication or removal of code, and other similar issues.- Improvements to auto-continue check. It should now do a better job determining whether a plan is finished or should automatically continue.-- Fix for 'exit status 128' errors in a couple of edge case scenarios.\ No newline at end of file+- Fix for 'exit status 128' errors in a couple of edge case scenarios.+- Data that is piped into `plandex load` is now automatically given a name.\ No newline at end of file