Matt Low
0384c7cb66
This refactor splits out all conversation concerns into a new `conversation` package. There is now a split between `conversation` and `api`s representation of `Message`, the latter storing the minimum information required for interaction with LLM providers. There is necessary conversation between the two when making LLM calls.
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
cmdutil "git.mlow.ca/mlow/lmcli/pkg/cmd/util"
|
|
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
|
|
"git.mlow.ca/mlow/lmcli/pkg/tui"
|
|
"git.mlow.ca/mlow/lmcli/pkg/tui/shared"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func ChatCmd(ctx *lmcli.Context) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "chat [conversation]",
|
|
Short: "Open the chat interface",
|
|
Long: `Open the chat interface, optionally on a given conversation.`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
err := validateGenerationFlags(ctx, cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var opts []tui.LaunchOption
|
|
|
|
list, err := cmd.Flags().GetBool("list")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if !list && len(args) == 1 {
|
|
shortname := args[0]
|
|
if shortname != ""{
|
|
conv, err := cmdutil.LookupConversationE(ctx, shortname)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
opts = append(opts, tui.WithInitialConversation(conv))
|
|
}
|
|
}
|
|
|
|
if list {
|
|
opts = append(opts, tui.WithInitialView(shared.ViewConversations))
|
|
}
|
|
|
|
err = tui.Launch(ctx, opts...)
|
|
if err != nil {
|
|
return fmt.Errorf("Error fetching LLM response: %v", err)
|
|
}
|
|
return nil
|
|
},
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
compMode := cobra.ShellCompDirectiveNoFileComp
|
|
if len(args) != 0 {
|
|
return nil, compMode
|
|
}
|
|
return ctx.Conversations.ConversationShortNameCompletions(toComplete), compMode
|
|
},
|
|
}
|
|
|
|
// -l, --list
|
|
cmd.Flags().BoolP("list", "l", false, "View/manage conversations")
|
|
|
|
applyGenerationFlags(ctx, cmd)
|
|
return cmd
|
|
}
|