@@ -332,16 +332,25 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
332
332
333
333
// If the user is trying to launch the chat-builder UI, then set up the tool and options here.
334
334
if r .UI {
335
- args = append ([]string {uiTool ()}, args ... )
335
+ if os .Getenv (system .BinEnvVar ) == "" {
336
+ gptOpt .Env = append (gptOpt .Env , system .BinEnvVar + "=" + system .Bin ())
337
+ }
338
+
339
+ // Pass the corrected environment variables for SDK server options
340
+ if r .DefaultModel != "" {
341
+ gptOpt .Env = append (gptOpt .Env , "GPTSCRIPT_SDKSERVER_DEFAULT_MODEL=" + r .DefaultModel )
342
+ }
343
+ if len (r .CredentialOverride ) > 0 {
344
+ gptOpt .Env = append (gptOpt .Env , "GPTSCRIPT_SDKSERVER_CREDENTIAL_OVERRIDE=" + strings .Join (r .CredentialOverride , "," ))
345
+ }
336
346
337
347
// If args has more than one element, then the user has provided a file.
338
- if len (args ) > 1 {
339
- if args [1 ] == "-" {
348
+ if len (args ) > 0 {
349
+ file := args [0 ]
350
+ if file == "-" {
340
351
return fmt .Errorf ("chat UI only supports files, cannot read from stdin" )
341
352
}
342
353
343
- file := args [1 ]
344
-
345
354
// If the file is external, then set the SCRIPTS_PATH to the current working directory. Otherwise,
346
355
// set it to the directory of the script and set the file to the base.
347
356
if ! (strings .HasPrefix (file , "http://" ) || strings .HasPrefix (file , "https://" ) || strings .HasPrefix (file , "github.com" )) {
@@ -359,23 +368,9 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
359
368
gptOpt .Env = append (gptOpt .Env , "SCRIPTS_PATH=" + cwd )
360
369
}
361
370
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
-
374
371
gptOpt .Env = append (gptOpt .Env , "UI_RUN_FILE=" + file )
375
-
376
- if len (args ) > 2 {
377
- args = append (args , args [2 :]... )
378
- }
372
+ // Remove the file from args because the above line will pass it to the UI tool.
373
+ args = args [1 :]
379
374
} else {
380
375
cwd , err := os .Getwd ()
381
376
if err != nil {
@@ -386,6 +381,8 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
386
381
387
382
// The UI must run in daemon mode.
388
383
r .Daemon = true
384
+ // Use the UI tool as the first argument.
385
+ args = append ([]string {uiTool ()}, args ... )
389
386
}
390
387
391
388
ctx := cmd .Context ()
0 commit comments