Add lmcli rename
to rename conversations
This commit is contained in:
parent
af2fccd4ee
commit
1e8ff60c54
@ -26,11 +26,14 @@ func init() {
|
||||
cmd.MarkFlagsMutuallyExclusive("system-prompt", "system-prompt-file")
|
||||
}
|
||||
|
||||
renameCmd.Flags().Bool("generate", false, "Use the LLM to generate the conversation title.")
|
||||
|
||||
rootCmd.AddCommand(
|
||||
continueCmd,
|
||||
lsCmd,
|
||||
newCmd,
|
||||
promptCmd,
|
||||
renameCmd,
|
||||
replyCmd,
|
||||
retryCmd,
|
||||
rmCmd,
|
||||
@ -357,8 +360,8 @@ var newCmd = &cobra.Command{
|
||||
Fatal("No message was provided.\n")
|
||||
}
|
||||
|
||||
conversation := Conversation{}
|
||||
err := store.SaveConversation(&conversation)
|
||||
conversation := &Conversation{}
|
||||
err := store.SaveConversation(conversation)
|
||||
if err != nil {
|
||||
Fatal("Could not save new conversation: %v\n", err)
|
||||
}
|
||||
@ -387,18 +390,67 @@ var newCmd = &cobra.Command{
|
||||
|
||||
conversation.GenerateAndSaveReplies(messages)
|
||||
|
||||
err = conversation.GenerateTitle()
|
||||
title, err := conversation.GenerateTitle()
|
||||
if err != nil {
|
||||
Warn("Could not generate title for conversation: %v\n", err)
|
||||
}
|
||||
|
||||
err = store.SaveConversation(&conversation)
|
||||
conversation.Title = title
|
||||
|
||||
err = store.SaveConversation(conversation)
|
||||
if err != nil {
|
||||
Warn("Could not save conversation after generating title: %v\n", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
var renameCmd = &cobra.Command{
|
||||
Use: "rename <conversation> [title]",
|
||||
Short: "Rename a conversation",
|
||||
Long: `Renames a conversation, either with the provided title or by generating a new name.`,
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
argCount := 1
|
||||
if err := cobra.MinimumNArgs(argCount)(cmd, args); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
shortName := args[0]
|
||||
conversation, err := store.ConversationByShortName(shortName)
|
||||
if conversation.ID == 0 {
|
||||
Fatal("Conversation not found with short name: %s\n", shortName)
|
||||
}
|
||||
|
||||
generate, _ := cmd.Flags().GetBool("generate")
|
||||
var title string
|
||||
if generate {
|
||||
title, err = conversation.GenerateTitle()
|
||||
if err != nil {
|
||||
Fatal("Could not generate title for conversation: %v\n", err)
|
||||
}
|
||||
} else {
|
||||
if len(args) < 2 {
|
||||
Fatal("Conversation title not provided.")
|
||||
}
|
||||
title = strings.Join(args[1:], " ")
|
||||
}
|
||||
|
||||
conversation.Title = title
|
||||
err = store.SaveConversation(conversation)
|
||||
if err != nil {
|
||||
Warn("Could not save conversation with new title: %v\n", err)
|
||||
}
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
compMode := cobra.ShellCompDirectiveNoFileComp
|
||||
if len(args) != 0 {
|
||||
return nil, compMode
|
||||
}
|
||||
return store.ConversationShortNameCompletions(toComplete), compMode
|
||||
},
|
||||
}
|
||||
|
||||
var promptCmd = &cobra.Command{
|
||||
Use: "prompt [message]",
|
||||
Short: "Do a one-shot prompt",
|
||||
|
@ -29,7 +29,7 @@ func (m *Message) FriendlyRole() string {
|
||||
return friendlyRole
|
||||
}
|
||||
|
||||
func (c *Conversation) GenerateTitle() error {
|
||||
func (c *Conversation) GenerateTitle() (string, error) {
|
||||
const header = "Generate a consise 4-5 word title for the conversation below."
|
||||
prompt := fmt.Sprintf("%s\n\n---\n\n%s", header, c.FormatForExternalPrompting(false))
|
||||
|
||||
@ -43,11 +43,10 @@ func (c *Conversation) GenerateTitle() error {
|
||||
model := "gpt-3.5-turbo" // use cheap model to generate title
|
||||
response, err := CreateChatCompletion(model, messages, 25, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
c.Title = response
|
||||
return nil
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *Conversation) FormatForExternalPrompting(system bool) string {
|
||||
|
Loading…
Reference in New Issue
Block a user