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