Skip to content

Commit

Permalink
fix: support passing along URLs to the UI
Browse files Browse the repository at this point in the history
Signed-off-by: tylerslaton <[email protected]>
  • Loading branch information
tylerslaton committed Jun 13, 2024
1 parent affa1b7 commit d15c4e9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions pkg/cli/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,31 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
return fmt.Errorf("chat UI only supports files, cannot read from stdin")
}

absPathToScript, err := filepath.Abs(args[1])
if err != nil {
return fmt.Errorf("cannot determine absolute path to script %s: %v", args[1], err)
file := args[1]

// If the file is external, then set the SCRIPTS_PATH to the current working directory. Otherwise,
// set it to the directory of the script and set the file to the base.
if !(strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") || strings.HasPrefix(file, "github.com")) {
absPathToScript, err := filepath.Abs(file)
if err != nil {
return fmt.Errorf("cannot determine absolute path to script %s: %v", file, err)
}
gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+filepath.Dir(absPathToScript))
file = filepath.Base(file)
} else {
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("could not determine current working directory: %w", err)
}
gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+cwd)
}

gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+filepath.Dir(absPathToScript))
if os.Getenv(system.BinEnvVar) == "" {
gptOpt.Env = append(gptOpt.Env, system.BinEnvVar+"="+system.Bin())
}

args = append([]string{args[0]}, "--file="+filepath.Base(args[1]))
args = append([]string{args[0]}, "--file="+file)

if len(args) > 2 {
args = append(args, args[2:]...)
}
Expand Down

0 comments on commit d15c4e9

Please sign in to comment.