File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 11package facade
22
33import (
4+ "os"
45 "path/filepath"
56 "sort"
67
78 "github.com/goark/errs"
89 "github.com/goark/gocli/cache"
10+ "github.com/goark/gpt-cli/gpt"
911 "github.com/goark/gpt-cli/logger"
1012 "github.com/rs/zerolog"
1113 "github.com/spf13/viper"
@@ -18,6 +20,10 @@ type options struct {
1820}
1921
2022func getOptions () (* options , error ) {
23+ apiKey := os .Getenv (gpt .ENV_API_KEY )
24+ if s := viper .GetString ("api-key" ); len (s ) > 0 {
25+ apiKey = s
26+ }
2127 logger , err := logger .New (
2228 logger .LevelFrom (viper .GetString ("log-level" )),
2329 viper .GetString ("log-dir" ),
@@ -26,7 +32,7 @@ func getOptions() (*options, error) {
2632 return nil , errs .Wrap (err )
2733 }
2834 return & options {
29- APIKey : viper . GetString ( "api-key" ) ,
35+ APIKey : apiKey ,
3036 CacheDir : cache .Dir (Name ),
3137 Logger : logger ,
3238 }, nil
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ import (
77 "github.com/sashabaranov/go-openai"
88)
99
10+ const (
11+ ENV_API_KEY = "OPENAI_API_KEY"
12+ )
13+
1014type GPTContext struct {
1115 apiKey string
1216 cacheDir string
You can’t perform that action at this time.
0 commit comments