Skip to content

Commit 64b6fa2

Browse files
committed
fix: remove the disable server environment variable
Now, when the GPTSCRIPT_URL is passed, the SDK will use it and not start its own server. Additionally, the SDK will pass this server URL to child SDK calls. Signed-off-by: Donnie Adams <[email protected]>
1 parent a2753a6 commit 64b6fa2

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/gptscript.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,21 @@ export class GPTScript {
8383
this.ready = false
8484
GPTScript.instanceCount++
8585
if (!GPTScript.serverURL) {
86-
GPTScript.serverURL = "http://" + (process.env.GPTSCRIPT_URL || "127.0.0.1:0")
86+
GPTScript.serverURL = process.env.GPTSCRIPT_URL || "http://127.0.0.1:0"
87+
if (!GPTScript.serverURL.startsWith("http://") && !GPTScript.serverURL.startsWith("https://")) {
88+
GPTScript.serverURL = "http://" + GPTScript.serverURL
89+
}
90+
}
91+
92+
if (!this.opts.Env) {
93+
this.opts.Env = []
8794
}
88-
if (GPTScript.instanceCount === 1 && process.env.GPTSCRIPT_DISABLE_SERVER !== "true") {
95+
if (process.env.GPTSCRIPT_URL) {
96+
this.opts.Env.push("GPTSCRIPT_URL=" + GPTScript.serverURL)
97+
return
98+
}
99+
100+
if (GPTScript.instanceCount === 1) {
89101
let env = process.env
90102
if (this.opts.Env) {
91103
env = {
@@ -121,6 +133,10 @@ export class GPTScript {
121133
}
122134

123135
GPTScript.serverURL = `http://${url}`
136+
if (!this.opts.Env) {
137+
this.opts.Env = []
138+
}
139+
this.opts.Env.push(`GPTSCRIPT_URL=${GPTScript.serverURL}`)
124140

125141
GPTScript.serverProcess.stderr?.removeAllListeners()
126142
})
@@ -130,7 +146,7 @@ export class GPTScript {
130146
close(): void {
131147
GPTScript.instanceCount--
132148
if (GPTScript.instanceCount === 0 && GPTScript.serverProcess) {
133-
GPTScript.serverURL = "http://" + (process.env.GPTSCRIPT_URL || "127.0.0.1:0")
149+
GPTScript.serverURL = process.env.GPTSCRIPT_URL || "http://127.0.0.1:0"
134150
GPTScript.serverProcess.kill("SIGTERM")
135151
GPTScript.serverProcess.stdin?.end()
136152
}

0 commit comments

Comments
 (0)