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.
45 lines
1015 B
Go
45 lines
1015 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.mlow.ca/mlow/lmcli/pkg/api"
|
|
cmdutil "git.mlow.ca/mlow/lmcli/pkg/cmd/util"
|
|
"git.mlow.ca/mlow/lmcli/pkg/conversation"
|
|
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
|
|
"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 {
|
|
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.")
|
|
}
|
|
|
|
messages := []conversation.Message{{
|
|
Role: api.MessageRoleUser,
|
|
Content: input,
|
|
}}
|
|
|
|
_, err = cmdutil.Prompt(ctx, messages, nil)
|
|
if err != nil {
|
|
return fmt.Errorf("Error fetching LLM response: %v", err)
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
applyGenerationFlags(ctx, cmd)
|
|
return cmd
|
|
}
|