Update command flag handling
`lmcli chat` now supports common prompt flags (model, length, system prompt, etc)
This commit is contained in:
@@ -8,10 +8,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
systemPromptFile string
|
||||
)
|
||||
|
||||
func RootCmd(ctx *lmcli.Context) *cobra.Command {
|
||||
var root = &cobra.Command{
|
||||
Use: "lmcli <command> [flags]",
|
||||
@@ -23,58 +19,43 @@ func RootCmd(ctx *lmcli.Context) *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
chatCmd := ChatCmd(ctx)
|
||||
continueCmd := ContinueCmd(ctx)
|
||||
cloneCmd := CloneCmd(ctx)
|
||||
editCmd := EditCmd(ctx)
|
||||
listCmd := ListCmd(ctx)
|
||||
newCmd := NewCmd(ctx)
|
||||
promptCmd := PromptCmd(ctx)
|
||||
renameCmd := RenameCmd(ctx)
|
||||
replyCmd := ReplyCmd(ctx)
|
||||
retryCmd := RetryCmd(ctx)
|
||||
rmCmd := RemoveCmd(ctx)
|
||||
viewCmd := ViewCmd(ctx)
|
||||
|
||||
inputCmds := []*cobra.Command{newCmd, promptCmd, replyCmd, retryCmd, continueCmd, editCmd}
|
||||
for _, cmd := range inputCmds {
|
||||
cmd.Flags().StringVar(ctx.Config.Defaults.Model, "model", *ctx.Config.Defaults.Model, "Which model to use")
|
||||
cmd.RegisterFlagCompletionFunc("model", func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
|
||||
return ctx.GetModels(), cobra.ShellCompDirectiveDefault
|
||||
})
|
||||
cmd.Flags().IntVar(ctx.Config.Defaults.MaxTokens, "length", *ctx.Config.Defaults.MaxTokens, "Maximum response tokens")
|
||||
cmd.Flags().StringVar(ctx.Config.Defaults.SystemPrompt, "system-prompt", *ctx.Config.Defaults.SystemPrompt, "System prompt")
|
||||
cmd.Flags().StringVar(&systemPromptFile, "system-prompt-file", "", "A path to a file containing the system prompt")
|
||||
cmd.MarkFlagsMutuallyExclusive("system-prompt", "system-prompt-file")
|
||||
}
|
||||
|
||||
root.AddCommand(
|
||||
chatCmd,
|
||||
cloneCmd,
|
||||
continueCmd,
|
||||
editCmd,
|
||||
listCmd,
|
||||
newCmd,
|
||||
promptCmd,
|
||||
renameCmd,
|
||||
replyCmd,
|
||||
retryCmd,
|
||||
rmCmd,
|
||||
viewCmd,
|
||||
ChatCmd(ctx),
|
||||
ContinueCmd(ctx),
|
||||
CloneCmd(ctx),
|
||||
EditCmd(ctx),
|
||||
ListCmd(ctx),
|
||||
NewCmd(ctx),
|
||||
PromptCmd(ctx),
|
||||
RenameCmd(ctx),
|
||||
ReplyCmd(ctx),
|
||||
RetryCmd(ctx),
|
||||
RemoveCmd(ctx),
|
||||
ViewCmd(ctx),
|
||||
)
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
func getSystemPrompt(ctx *lmcli.Context) string {
|
||||
if systemPromptFile != "" {
|
||||
content, err := util.ReadFileContents(systemPromptFile)
|
||||
if err != nil {
|
||||
lmcli.Fatal("Could not read file contents at %s: %v\n", systemPromptFile, err)
|
||||
}
|
||||
return content
|
||||
}
|
||||
return *ctx.Config.Defaults.SystemPrompt
|
||||
func applyPromptFlags(ctx *lmcli.Context, cmd *cobra.Command) {
|
||||
f := cmd.Flags()
|
||||
|
||||
f.StringVarP(
|
||||
ctx.Config.Defaults.Model,
|
||||
"model", "m",
|
||||
*ctx.Config.Defaults.Model,
|
||||
"The model to generate a response with",
|
||||
)
|
||||
cmd.RegisterFlagCompletionFunc("model", func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
|
||||
return ctx.GetModels(), cobra.ShellCompDirectiveDefault
|
||||
})
|
||||
|
||||
f.IntVar(ctx.Config.Defaults.MaxTokens, "max-length", *ctx.Config.Defaults.MaxTokens, "Maximum response tokens")
|
||||
f.Float32VarP(ctx.Config.Defaults.Temperature, "temperature", "t", *ctx.Config.Defaults.Temperature, "Sampling temperature")
|
||||
|
||||
f.StringVar(ctx.Config.Defaults.SystemPrompt, "system-prompt", *ctx.Config.Defaults.SystemPrompt, "System prompt")
|
||||
f.StringVar(&ctx.SystemPromptFile, "system-prompt-file", "", "A path to a file containing the system prompt")
|
||||
cmd.MarkFlagsMutuallyExclusive("system-prompt", "system-prompt-file")
|
||||
}
|
||||
|
||||
// inputFromArgsOrEditor returns either the provided input from the args slice
|
||||
|
||||
Reference in New Issue
Block a user