25
25
const relativeToBinaryPath = "<me>"
26
26
27
27
type GPTScript struct {
28
- url string
28
+ url string
29
+ globalEnv []string
29
30
}
30
31
31
32
func NewGPTScript (opts GlobalOptions ) (* GPTScript , error ) {
@@ -39,16 +40,18 @@ func NewGPTScript(opts GlobalOptions) (*GPTScript, error) {
39
40
serverURL = os .Getenv ("GPTSCRIPT_URL" )
40
41
}
41
42
43
+ if opts .Env == nil {
44
+ opts .Env = os .Environ ()
45
+ }
46
+
47
+ opts .Env = append (opts .Env , opts .toEnv ()... )
48
+
42
49
if serverProcessCancel == nil && ! disableServer {
43
50
ctx , cancel := context .WithCancel (context .Background ())
44
51
in , _ := io .Pipe ()
45
52
46
53
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 [:]
52
55
53
56
serverProcess .Stdin = in
54
57
stdErr , err := serverProcess .StderrPipe ()
@@ -88,7 +91,15 @@ func NewGPTScript(opts GlobalOptions) (*GPTScript, error) {
88
91
89
92
serverURL = strings .TrimSpace (serverURL )
90
93
}
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
92
103
}
93
104
94
105
func readAddress (stdErr io.Reader ) (string , error ) {
@@ -117,6 +128,7 @@ func (g *GPTScript) Close() {
117
128
}
118
129
119
130
func (g * GPTScript ) Evaluate (ctx context.Context , opts Options , tools ... ToolDef ) (* Run , error ) {
131
+ opts .Env = append (g .globalEnv , opts .Env ... )
120
132
return (& Run {
121
133
url : g .url ,
122
134
requestPath : "evaluate" ,
@@ -127,6 +139,7 @@ func (g *GPTScript) Evaluate(ctx context.Context, opts Options, tools ...ToolDef
127
139
}
128
140
129
141
func (g * GPTScript ) Run (ctx context.Context , toolPath string , opts Options ) (* Run , error ) {
142
+ opts .Env = append (g .globalEnv , opts .Env ... )
130
143
return (& Run {
131
144
url : g .url ,
132
145
requestPath : "run" ,
0 commit comments