diff --git a/pkg/cli/cmd.go b/pkg/cli/cmd.go index 65b2275..c05af6b 100644 --- a/pkg/cli/cmd.go +++ b/pkg/cli/cmd.go @@ -31,6 +31,7 @@ func init() { rootCmd.AddCommand( continueCmd, + editCmd, lsCmd, newCmd, promptCmd, @@ -39,7 +40,6 @@ func init() { retryCmd, rmCmd, viewCmd, - editCmd, ) } @@ -47,11 +47,11 @@ func Execute() error { return rootCmd.Execute() } -func SystemPrompt() string { +func getSystemPrompt() string { if systemPromptFile != "" { content, err := FileContents(systemPromptFile) if err != nil { - Fatal("Could not read file contents at %s: %v", systemPromptFile, err) + Fatal("Could not read file contents at %s: %v\n", systemPromptFile, err) } return content } @@ -82,9 +82,9 @@ func fetchAndShowCompletion(messages []Message) ([]Message, error) { return replies, err } -// lookupConversationByShortname either returns the conversation found by the +// lookupConversation either returns the conversation found by the // short name or exits the program -func lookupConversationByShortname(shortName string) *Conversation { +func lookupConversation(shortName string) *Conversation { c, err := store.ConversationByShortName(shortName) if err != nil { Fatal("Could not lookup conversation: %v\n", err) @@ -137,11 +137,11 @@ func handleConversationReply(c *Conversation, persist bool, toSend ...Message) { } } -// InputFromArgsOrEditor returns either the provided input from the args slice +// inputFromArgsOrEditor returns either the provided input from the args slice // (joined with spaces), or if len(args) is 0, opens an editor and returns // whatever input was provided there. placeholder is a string which populates // the editor and gets stripped from the final output. -func InputFromArgsOrEditor(args []string, placeholder string, existingMessage string) (message string) { +func inputFromArgsOrEditor(args []string, placeholder string, existingMessage string) (message string) { var err error if len(args) == 0 { message, err = InputFromEditor(placeholder, "message.*.md", existingMessage) @@ -280,7 +280,7 @@ var rmCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { var toRemove []*Conversation for _, shortName := range args { - conversation := lookupConversationByShortname(shortName) + conversation := lookupConversation(shortName) toRemove = append(toRemove, conversation) } var errors []error @@ -327,7 +327,7 @@ var viewCmd = &cobra.Command{ }, Run: func(cmd *cobra.Command, args []string) { shortName := args[0] - conversation := lookupConversationByShortname(shortName) + conversation := lookupConversation(shortName) messages, err := store.Messages(conversation) if err != nil { @@ -358,7 +358,7 @@ var renameCmd = &cobra.Command{ }, Run: func(cmd *cobra.Command, args []string) { shortName := args[0] - conversation := lookupConversationByShortname(shortName) + conversation := lookupConversation(shortName) var err error generate, _ := cmd.Flags().GetBool("generate") @@ -370,7 +370,7 @@ var renameCmd = &cobra.Command{ } } else { if len(args) < 2 { - Fatal("Conversation title not provided.") + Fatal("Conversation title not provided.\n") } title = strings.Join(args[1:], " ") } @@ -403,9 +403,9 @@ var replyCmd = &cobra.Command{ }, Run: func(cmd *cobra.Command, args []string) { shortName := args[0] - conversation := lookupConversationByShortname(shortName) + conversation := lookupConversation(shortName) - reply := InputFromArgsOrEditor(args[1:], "# How would you like to reply?\n", "") + reply := inputFromArgsOrEditor(args[1:], "# How would you like to reply?\n", "") if reply == "" { Fatal("No reply was provided.\n") } @@ -430,7 +430,7 @@ var newCmd = &cobra.Command{ Short: "Start a new conversation", Long: `Start a new conversation with the Large Language Model.`, Run: func(cmd *cobra.Command, args []string) { - messageContents := InputFromArgsOrEditor(args, "# What would you like to say?\n", "") + messageContents := inputFromArgsOrEditor(args, "# What would you like to say?\n", "") if messageContents == "" { Fatal("No message was provided.\n") } @@ -445,7 +445,7 @@ var newCmd = &cobra.Command{ { ConversationID: conversation.ID, Role: MessageRoleSystem, - OriginalContent: SystemPrompt(), + OriginalContent: getSystemPrompt(), }, { ConversationID: conversation.ID, @@ -475,7 +475,7 @@ var promptCmd = &cobra.Command{ Short: "Do a one-shot prompt", Long: `Prompt the Large Language Model and get a response.`, Run: func(cmd *cobra.Command, args []string) { - message := InputFromArgsOrEditor(args, "# What would you like to say?\n", "") + message := inputFromArgsOrEditor(args, "# What would you like to say?\n", "") if message == "" { Fatal("No message was provided.\n") } @@ -483,7 +483,7 @@ var promptCmd = &cobra.Command{ messages := []Message{ { Role: MessageRoleSystem, - OriginalContent: SystemPrompt(), + OriginalContent: getSystemPrompt(), }, { Role: MessageRoleUser, @@ -511,7 +511,7 @@ var retryCmd = &cobra.Command{ }, Run: func(cmd *cobra.Command, args []string) { shortName := args[0] - conversation := lookupConversationByShortname(shortName) + conversation := lookupConversation(shortName) messages, err := store.Messages(conversation) if err != nil { @@ -555,7 +555,7 @@ var continueCmd = &cobra.Command{ }, Run: func(cmd *cobra.Command, args []string) { shortName := args[0] - conversation := lookupConversationByShortname(shortName) + conversation := lookupConversation(shortName) handleConversationReply(conversation, true) }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { @@ -579,7 +579,7 @@ var editCmd = &cobra.Command{ }, Run: func(cmd *cobra.Command, args []string) { shortName := args[0] - conversation := lookupConversationByShortname(shortName) + conversation := lookupConversation(shortName) messages, err := store.Messages(conversation) if err != nil { @@ -608,7 +608,7 @@ var editCmd = &cobra.Command{ existingContents := lastUserMessage.OriginalContent - newContents := InputFromArgsOrEditor(args[1:], "# Save when finished editing\n", existingContents) + newContents := inputFromArgsOrEditor(args[1:], "# Save when finished editing\n", existingContents) if newContents == existingContents { Fatal("No edits were made.\n") } @@ -617,7 +617,7 @@ var editCmd = &cobra.Command{ Fatal("No message was provided.\n") } - for _, message := range(toRemove) { + for _, message := range toRemove { err = store.DeleteMessage(&message) if err != nil { Warn("Could not delete message: %v\n", err)