|
| 1 | +/* |
| 2 | +Copyright © 2023 NAME HERE <EMAIL ADDRESS> |
| 3 | +*/ |
| 4 | +package cmd |
| 5 | + |
| 6 | +import ( |
| 7 | + "github.com/spf13/cobra" |
| 8 | + |
| 9 | + "github.com/chand1012/ottodocs/config" |
| 10 | + "github.com/chand1012/ottodocs/utils" |
| 11 | +) |
| 12 | + |
| 13 | +var VALID_MODELS = []string{"gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314", "gpt-3.5-turbo", "gpt-3.5-turbo-0301"} |
| 14 | + |
| 15 | +// setModelCmd represents the setModel command |
| 16 | +var setModelCmd = &cobra.Command{ |
| 17 | + Use: "setModel", |
| 18 | + Short: "Set the model to use for documentation", |
| 19 | + Long: `Sets the model to use for documentation. Takes a valid ChatGPT API model name as a single positional argument. |
| 20 | +Valid models are: gpt-4, gpt-4-0314, gpt-4-32k, gpt-4-32k-0314, gpt-3.5-turbo, gpt-3.5-turbo-0301 |
| 21 | +See here for more information: https://platform.openai.com/docs/models/model-endpoint-compatibility |
| 22 | +`, |
| 23 | + Run: func(cmd *cobra.Command, args []string) { |
| 24 | + model := args[0] |
| 25 | + c, err := config.Load() |
| 26 | + if err != nil { |
| 27 | + log.Errorf("Error loading config: %s", err) |
| 28 | + } |
| 29 | + if !utils.Contains(VALID_MODELS, model) { |
| 30 | + log.Errorf("Invalid model: %s", model) |
| 31 | + log.Errorf("Valid models are: %s", VALID_MODELS) |
| 32 | + return |
| 33 | + } |
| 34 | + |
| 35 | + c.Model = model |
| 36 | + |
| 37 | + err = config.Save(c) |
| 38 | + if err != nil { |
| 39 | + log.Errorf("Error saving config: %s", err) |
| 40 | + } |
| 41 | + log.Infof("Set model to %s", model) |
| 42 | + }, |
| 43 | + Args: cobra.ExactArgs(1), |
| 44 | +} |
| 45 | + |
| 46 | +func init() { |
| 47 | + RootCmd.AddCommand(setModelCmd) |
| 48 | +} |
0 commit comments