diff --git a/aichat.go b/aichat.go index 122dc5a..9666a38 100644 --- a/aichat.go +++ b/aichat.go @@ -228,7 +228,7 @@ func main() { var listPrompts = false var nonStreaming = false var split = false - var model = gogpt.GPT4 + var model = "" getopt.FlagLong(&temperature, "temperature", 't', "temperature") getopt.FlagLong(&maxTokens, "max-tokens", 0, "max tokens, 0 to use default") getopt.FlagLong(&verbose, "verbose", 'v', "verbose output") @@ -249,6 +249,21 @@ func main() { if err != nil { log.Fatal(err) } + + config, err := ReadConfig() + if err != nil { + log.Fatal(err) + } + + // if model is not specified, use the default model from the config file + if model == "" { + if config.Model == "" { + model = gogpt.GPT3Dot5Turbo + } else { + model = config.Model + } + } + options := chatOptions{ model: model, temperature: temperature, diff --git a/config.go b/config.go new file mode 100644 index 0000000..474d932 --- /dev/null +++ b/config.go @@ -0,0 +1,29 @@ +package main + +import ( + "os" + "path/filepath" +) + +type Config struct { + Model string `yaml:"model"` +} + +func ReadConfig() (*Config, error) { + config := &Config{} + // try to read from ~/.aichat/config.yml + homedir, err := os.UserHomeDir() + if err != nil { + return nil, err + } + path := filepath.Join(homedir, ".aichat", "config.yml") + + if err := ReadYamlFromFile(path, config); err != nil { + // if the file does not exist, return an empty config + if os.IsNotExist(err) { + return config, nil + } + return nil, err + } + return config, nil +}