Skip to content

Commit fa70e26

Browse files
authored
Merge pull request #493 from tylerslaton/sdk-remote-file
fix: support passing along URLs to the UI
2 parents 1c6faca + d15c4e9 commit fa70e26

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pkg/cli/gptscript.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,31 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
337337
return fmt.Errorf("chat UI only supports files, cannot read from stdin")
338338
}
339339

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)
343357
}
344358

345-
gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+filepath.Dir(absPathToScript))
346359
if os.Getenv(system.BinEnvVar) == "" {
347360
gptOpt.Env = append(gptOpt.Env, system.BinEnvVar+"="+system.Bin())
348361
}
349362

350-
args = append([]string{args[0]}, "--file="+filepath.Base(args[1]))
363+
args = append([]string{args[0]}, "--file="+file)
364+
351365
if len(args) > 2 {
352366
args = append(args, args[2:]...)
353367
}

0 commit comments

Comments
 (0)