2024-02-21 21:55:38 -07:00
|
|
|
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/lmcli/model"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func PromptCmd(ctx *lmcli.Context) *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "prompt [message]",
|
|
|
|
Short: "Do a one-shot prompt",
|
|
|
|
Long: `Prompt the Large Language Model and get a response.`,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
message := inputFromArgsOrEditor(args, "# What would you like to say?\n", "")
|
|
|
|
if message == "" {
|
|
|
|
return fmt.Errorf("No message was provided.")
|
|
|
|
}
|
|
|
|
|
|
|
|
messages := []model.Message{
|
|
|
|
{
|
|
|
|
Role: model.MessageRoleSystem,
|
|
|
|
Content: getSystemPrompt(ctx),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Role: model.MessageRoleUser,
|
|
|
|
Content: message,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-03-12 14:36:24 -06:00
|
|
|
_, err := cmdutil.FetchAndShowCompletion(ctx, messages, nil)
|
2024-02-21 21:55:38 -07:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error fetching LLM response: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|