-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for reading the default model from a config file
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
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |