Skip to content

Commit c1a74ce

Browse files
committed
fix: set common UI env vars regardless of whether a file is passed
Signed-off-by: Donnie Adams <donnie@acorn.io>
1 parent d3cac6e commit c1a74ce

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

pkg/cli/gptscript.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,18 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
334334
if r.UI {
335335
args = append([]string{uiTool()}, args...)
336336

337+
if os.Getenv(system.BinEnvVar) == "" {
338+
gptOpt.Env = append(gptOpt.Env, system.BinEnvVar+"="+system.Bin())
339+
}
340+
341+
// Pass the corrected environment variables for SDK server options
342+
if r.DefaultModel != "" {
343+
gptOpt.Env = append(gptOpt.Env, "GPTSCRIPT_SDKSERVER_DEFAULT_MODEL="+r.DefaultModel)
344+
}
345+
if len(r.CredentialOverride) > 0 {
346+
gptOpt.Env = append(gptOpt.Env, "GPTSCRIPT_SDKSERVER_CREDENTIAL_OVERRIDE="+strings.Join(r.CredentialOverride, ","))
347+
}
348+
337349
// If args has more than one element, then the user has provided a file.
338350
if len(args) > 1 {
339351
if args[1] == "-" {
@@ -359,23 +371,7 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
359371
gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+cwd)
360372
}
361373

362-
if os.Getenv(system.BinEnvVar) == "" {
363-
gptOpt.Env = append(gptOpt.Env, system.BinEnvVar+"="+system.Bin())
364-
}
365-
366-
// Pass the corrected environment variables for SDK server options
367-
if r.DefaultModel != "" {
368-
gptOpt.Env = append(gptOpt.Env, "GPTSCRIPT_SDKSERVER_DEFAULT_MODEL="+r.DefaultModel)
369-
}
370-
if len(r.CredentialOverride) > 0 {
371-
gptOpt.Env = append(gptOpt.Env, "GPTSCRIPT_SDKSERVER_CREDENTIAL_OVERRIDE="+strings.Join(r.CredentialOverride, ","))
372-
}
373-
374374
gptOpt.Env = append(gptOpt.Env, "UI_RUN_FILE="+file)
375-
376-
if len(args) > 2 {
377-
args = append(args, args[2:]...)
378-
}
379375
} else {
380376
cwd, err := os.Getwd()
381377
if err != nil {

0 commit comments

Comments
 (0)