2525const relativeToBinaryPath = "<me>"
2626
2727type GPTScript struct {
28- url string
28+ url string
29+ globalEnv []string
2930}
3031
3132func NewGPTScript (opts GlobalOptions ) (* GPTScript , error ) {
@@ -39,16 +40,18 @@ func NewGPTScript(opts GlobalOptions) (*GPTScript, error) {
3940 serverURL = os .Getenv ("GPTSCRIPT_URL" )
4041 }
4142
43+ if opts .Env == nil {
44+ opts .Env = os .Environ ()
45+ }
46+
47+ opts .Env = append (opts .Env , opts .toEnv ()... )
48+
4249 if serverProcessCancel == nil && ! disableServer {
4350 ctx , cancel := context .WithCancel (context .Background ())
4451 in , _ := io .Pipe ()
4552
4653 serverProcess = exec .CommandContext (ctx , getCommand (), "sys.sdkserver" , "--listen-address" , serverURL )
47- if opts .Env == nil {
48- opts .Env = os .Environ ()
49- }
50-
51- serverProcess .Env = append (opts .Env [:], opts .toEnv ()... )
54+ serverProcess .Env = opts .Env [:]
5255
5356 serverProcess .Stdin = in
5457 stdErr , err := serverProcess .StderrPipe ()
@@ -88,7 +91,15 @@ func NewGPTScript(opts GlobalOptions) (*GPTScript, error) {
8891
8992 serverURL = strings .TrimSpace (serverURL )
9093 }
91- return & GPTScript {url : "http://" + serverURL }, nil
94+ g := & GPTScript {
95+ url : "http://" + serverURL ,
96+ }
97+
98+ if disableServer {
99+ g .globalEnv = opts .Env [:]
100+ }
101+
102+ return g , nil
92103}
93104
94105func readAddress (stdErr io.Reader ) (string , error ) {
@@ -117,6 +128,7 @@ func (g *GPTScript) Close() {
117128}
118129
119130func (g * GPTScript ) Evaluate (ctx context.Context , opts Options , tools ... ToolDef ) (* Run , error ) {
131+ opts .Env = append (g .globalEnv , opts .Env ... )
120132 return (& Run {
121133 url : g .url ,
122134 requestPath : "evaluate" ,
@@ -127,6 +139,7 @@ func (g *GPTScript) Evaluate(ctx context.Context, opts Options, tools ...ToolDef
127139}
128140
129141func (g * GPTScript ) Run (ctx context.Context , toolPath string , opts Options ) (* Run , error ) {
142+ opts .Env = append (g .globalEnv , opts .Env ... )
130143 return (& Run {
131144 url : g .url ,
132145 requestPath : "run" ,
0 commit comments