@@ -338,17 +338,31 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
338
338
return fmt .Errorf ("chat UI only supports files, cannot read from stdin" )
339
339
}
340
340
341
- absPathToScript , err := filepath .Abs (args [1 ])
342
- if err != nil {
343
- return fmt .Errorf ("cannot determine absolute path to script %s: %v" , args [1 ], err )
341
+ file := args [1 ]
342
+
343
+ // If the file is external, then set the SCRIPTS_PATH to the current working directory. Otherwise,
344
+ // set it to the directory of the script and set the file to the base.
345
+ if ! (strings .HasPrefix (file , "http://" ) || strings .HasPrefix (file , "https://" ) || strings .HasPrefix (file , "github.com" )) {
346
+ absPathToScript , err := filepath .Abs (file )
347
+ if err != nil {
348
+ return fmt .Errorf ("cannot determine absolute path to script %s: %v" , file , err )
349
+ }
350
+ gptOpt .Env = append (gptOpt .Env , "SCRIPTS_PATH=" + filepath .Dir (absPathToScript ))
351
+ file = filepath .Base (file )
352
+ } else {
353
+ cwd , err := os .Getwd ()
354
+ if err != nil {
355
+ return fmt .Errorf ("could not determine current working directory: %w" , err )
356
+ }
357
+ gptOpt .Env = append (gptOpt .Env , "SCRIPTS_PATH=" + cwd )
344
358
}
345
359
346
- gptOpt .Env = append (gptOpt .Env , "SCRIPTS_PATH=" + filepath .Dir (absPathToScript ))
347
360
if os .Getenv (system .BinEnvVar ) == "" {
348
361
gptOpt .Env = append (gptOpt .Env , system .BinEnvVar + "=" + system .Bin ())
349
362
}
350
363
351
- args = append ([]string {args [0 ]}, "--file=" + filepath .Base (args [1 ]))
364
+ args = append ([]string {args [0 ]}, "--file=" + file )
365
+
352
366
if len (args ) > 2 {
353
367
args = append (args , args [2 :]... )
354
368
}
0 commit comments