Private
Public Access
1
0

Add validation to command line flags + update system prompt handling

Renamed `applyPromptFlags` to `applyGenerationFlags` and added
`validateGenerationFlags`
This commit is contained in:
2024-06-23 04:47:47 +00:00
parent 677cfcfebf
commit f89cc7b410
11 changed files with 90 additions and 44 deletions

View File

@@ -15,6 +15,11 @@ func PromptCmd(ctx *lmcli.Context) *cobra.Command {
Short: "Do a one-shot prompt",
Long: `Prompt the Large Language Model and get a response.`,
RunE: func(cmd *cobra.Command, args []string) error {
err := validateGenerationFlags(ctx, cmd)
if err != nil {
return err
}
input := inputFromArgsOrEditor(args, "# Write your prompt below\n", "")
if input == "" {
return fmt.Errorf("No message was provided.")
@@ -22,8 +27,7 @@ func PromptCmd(ctx *lmcli.Context) *cobra.Command {
var messages []api.Message
// TODO: stop supplying system prompt as a message
system := ctx.GetSystemPrompt()
system := ctx.Config.GetSystemPrompt()
if system != "" {
messages = append(messages, api.Message{
Role: api.MessageRoleSystem,
@@ -36,7 +40,7 @@ func PromptCmd(ctx *lmcli.Context) *cobra.Command {
Content: input,
})
_, err := cmdutil.Prompt(ctx, messages, nil)
_, err = cmdutil.Prompt(ctx, messages, nil)
if err != nil {
return fmt.Errorf("Error fetching LLM response: %v", err)
}
@@ -44,6 +48,6 @@ func PromptCmd(ctx *lmcli.Context) *cobra.Command {
},
}
applyPromptFlags(ctx, cmd)
applyGenerationFlags(ctx, cmd)
return cmd
}