Skip to content

Commit caca17a

Browse files
committed
fix: set global options as environment variables for security
Signed-off-by: Donnie Adams <[email protected]>
1 parent 39e4e76 commit caca17a

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

gptscript.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ func NewGPTScript(opts GlobalOptions) (GPTScript, error) {
7171
ctx, cancel := context.WithCancel(context.Background())
7272

7373
in, _ := io.Pipe()
74-
serverProcess = exec.CommandContext(ctx, getCommand(), append(opts.toArgs(), "--listen-address", serverURL, "sdkserver")...)
74+
serverProcess = exec.CommandContext(ctx, getCommand(), "--listen-address", serverURL, "sdkserver")
75+
serverProcess.Env = append(os.Environ(), opts.toEnv()...)
7576
serverProcess.Stdin = in
7677

7778
serverProcessCancel = func() {

gptscript_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestMain(m *testing.M) {
2020
}
2121

2222
var err error
23-
g, err = NewGPTScript(GlobalOptions{})
23+
g, err = NewGPTScript(GlobalOptions{OpenAIAPIKey: os.Getenv("OPENAI_API_KEY")})
2424
if err != nil {
2525
panic(fmt.Sprintf("error creating gptscript: %s", err))
2626
}

opts.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ type GlobalOptions struct {
88
DefaultModel string `json:"DefaultModel"`
99
}
1010

11-
func (g GlobalOptions) toArgs() []string {
11+
func (g GlobalOptions) toEnv() []string {
1212
var args []string
1313
if g.OpenAIAPIKey != "" {
14-
args = append(args, "--openai-api-key", g.OpenAIAPIKey)
14+
args = append(args, "OPENAI_API_KEY="+g.OpenAIAPIKey)
1515
}
1616
if g.OpenAIBaseURL != "" {
17-
args = append(args, "--openai-base-url", g.OpenAIBaseURL)
17+
args = append(args, "OPENAI_BASE_URL="+g.OpenAIBaseURL)
1818
}
1919
if g.DefaultModel != "" {
20-
args = append(args, "--default-model", g.DefaultModel)
20+
args = append(args, "GPTSCRIPT_DEFAULT_MODEL="+g.DefaultModel)
2121
}
2222

2323
return args

0 commit comments

Comments
 (0)