@@ -338,17 +338,31 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
338338 return fmt .Errorf ("chat UI only supports files, cannot read from stdin" )
339339 }
340340
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 )
344358 }
345359
346- gptOpt .Env = append (gptOpt .Env , "SCRIPTS_PATH=" + filepath .Dir (absPathToScript ))
347360 if os .Getenv (system .BinEnvVar ) == "" {
348361 gptOpt .Env = append (gptOpt .Env , system .BinEnvVar + "=" + system .Bin ())
349362 }
350363
351- args = append ([]string {args [0 ]}, "--file=" + filepath .Base (args [1 ]))
364+ args = append ([]string {args [0 ]}, "--file=" + file )
365+
352366 if len (args ) > 2 {
353367 args = append (args , args [2 :]... )
354368 }
0 commit comments