Compare commits

..

No commits in common. "c8a1e3e10594437334acbc90c28c8e4f8a631454" and "e6dcefacf5096dcca9159d7ce05b3360089ef49b" have entirely different histories.

2 changed files with 15 additions and 29 deletions

View File

@ -35,23 +35,6 @@ func Execute() error {
return rootCmd.Execute() return rootCmd.Execute()
} }
// 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) (message string) {
var err error
if len(args) == 0 {
message, err = InputFromEditor(placeholder, "message.*.md")
if err != nil {
Fatal("Failed to get input: %v\n", err)
}
} else {
message = strings.Trim(strings.Join(args, " "), " \t\n")
}
return
}
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "lmcli", Use: "lmcli",
Short: "Interact with Large Language Models", Short: "Interact with Large Language Models",
@ -166,7 +149,7 @@ var lsCmd = &cobra.Command{
} }
var rmCmd = &cobra.Command{ var rmCmd = &cobra.Command{
Use: "rm <conversation>", Use: "rm [conversation]",
Short: "Remove a conversation", Short: "Remove a conversation",
Long: `Removes a conversation by its short name.`, Long: `Removes a conversation by its short name.`,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
@ -200,7 +183,7 @@ var rmCmd = &cobra.Command{
} }
var viewCmd = &cobra.Command{ var viewCmd = &cobra.Command{
Use: "view <conversation>", Use: "view [conversation]",
Short: "View messages in a conversation", Short: "View messages in a conversation",
Long: `Finds a conversation by its short name and displays its contents.`, Long: `Finds a conversation by its short name and displays its contents.`,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
@ -234,7 +217,7 @@ var viewCmd = &cobra.Command{
} }
var replyCmd = &cobra.Command{ var replyCmd = &cobra.Command{
Use: "reply <conversation> [message]", Use: "reply",
Short: "Send a reply to a conversation", Short: "Send a reply to a conversation",
Long: `Sends a reply to conversation and writes the response to stdout.`, Long: `Sends a reply to conversation and writes the response to stdout.`,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
@ -256,7 +239,7 @@ var replyCmd = &cobra.Command{
Fatal("Could not retrieve messages for conversation: %s\n", conversation.Title) Fatal("Could not retrieve messages for conversation: %s\n", conversation.Title)
} }
messageContents := InputFromArgsOrEditor(args[1:], "# How would you like to reply?\n") messageContents, err := InputFromEditor("# How would you like to reply?\n", "reply.*.md")
if messageContents == "" { if messageContents == "" {
Fatal("No reply was provided.\n") Fatal("No reply was provided.\n")
} }
@ -311,18 +294,22 @@ var replyCmd = &cobra.Command{
} }
var newCmd = &cobra.Command{ var newCmd = &cobra.Command{
Use: "new [message]", Use: "new",
Short: "Start a new conversation", Short: "Start a new conversation",
Long: `Start a new conversation with the Large Language Model.`, Long: `Start a new conversation with the Large Language Model.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
messageContents := InputFromArgsOrEditor(args, "# What would you like to say?\n") messageContents, err := InputFromEditor("# What would you like to say?\n", "message.*.md")
if err != nil {
Fatal("Failed to get input: %v\n", err)
}
if messageContents == "" { if messageContents == "" {
Fatal("No message was provided.\n") Fatal("No message was provided.\n")
} }
// TODO: set title if --title provided, otherwise defer for later(?) // TODO: set title if --title provided, otherwise defer for later(?)
conversation := Conversation{} conversation := Conversation{}
err := store.SaveConversation(&conversation) err = store.SaveConversation(&conversation)
if err != nil { if err != nil {
Fatal("Could not save new conversation: %v\n", err) Fatal("Could not save new conversation: %v\n", err)
} }
@ -378,7 +365,6 @@ var newCmd = &cobra.Command{
if err != nil { if err != nil {
Warn("Could not generate title for conversation: %v\n", err) Warn("Could not generate title for conversation: %v\n", err)
} }
err = store.SaveConversation(&conversation) err = store.SaveConversation(&conversation)
if err != nil { if err != nil {
Warn("Could not save conversation after generating title: %v\n", err) Warn("Could not save conversation after generating title: %v\n", err)
@ -387,12 +373,12 @@ var newCmd = &cobra.Command{
} }
var promptCmd = &cobra.Command{ var promptCmd = &cobra.Command{
Use: "prompt [message]", Use: "prompt",
Short: "Do a one-shot prompt", Short: "Do a one-shot prompt",
Long: `Prompt the Large Language Model and get a response.`, Long: `Prompt the Large Language Model and get a response.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
message := InputFromArgsOrEditor(args, "# What would you like to say?\n") message := strings.Join(args, " ")
if message == "" { if len(strings.Trim(message, " \t\n")) == 0 {
Fatal("No message was provided.\n") Fatal("No message was provided.\n")
} }

View File

@ -33,7 +33,7 @@ func (c *Conversation) GenerateTitle() error {
} }
model := "gpt-3.5-turbo" // use cheap model to generate title model := "gpt-3.5-turbo" // use cheap model to generate title
response, err := CreateChatCompletion(model, messages, 25) response, err := CreateChatCompletion(model, messages, 10)
if err != nil { if err != nil {
return err return err
} }