Skip to content

Commit

Permalink
Add support for reading the default model from a config file
Browse files Browse the repository at this point in the history
This commit adds support for reading the default model from a config file
located at `~/.aichat/config.yml`. If the `model` flag is not specified when
running the program, it will try to read the default model from the config file.
If the config file does not exist or does not contain a `model` field, it will
use the default model `gogpt.GPT3Dot5Turbo`.
  • Loading branch information
tkawachi committed May 18, 2023
1 parent a0e20ec commit 9907945
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
17 changes: 16 additions & 1 deletion aichat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 9907945

Please sign in to comment.