Skip to content

Commit 901e28b

Browse files
1 parent a376c73 commit 901e28b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

facade/options.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package facade
22

33
import (
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

2022
func 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

gpt/gpt.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
1014
type GPTContext struct {
1115
apiKey string
1216
cacheDir string

0 commit comments

Comments
 (0)