Skip to content

Commit

Permalink
fix: remove the disable server environment variable
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
thedadams committed Sep 26, 2024
1 parent a2753a6 commit 64b6fa2
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,21 @@ export class GPTScript {
this.ready = false
GPTScript.instanceCount++
if (!GPTScript.serverURL) {
GPTScript.serverURL = "http://" + (process.env.GPTSCRIPT_URL || "127.0.0.1:0")
GPTScript.serverURL = process.env.GPTSCRIPT_URL || "http://127.0.0.1:0"
if (!GPTScript.serverURL.startsWith("http://") && !GPTScript.serverURL.startsWith("https://")) {
GPTScript.serverURL = "http://" + GPTScript.serverURL
}
}

if (!this.opts.Env) {
this.opts.Env = []
}
if (GPTScript.instanceCount === 1 && process.env.GPTSCRIPT_DISABLE_SERVER !== "true") {
if (process.env.GPTSCRIPT_URL) {
this.opts.Env.push("GPTSCRIPT_URL=" + GPTScript.serverURL)
return
}

if (GPTScript.instanceCount === 1) {
let env = process.env
if (this.opts.Env) {
env = {
Expand Down Expand Up @@ -121,6 +133,10 @@ export class GPTScript {
}

GPTScript.serverURL = `http://${url}`
if (!this.opts.Env) {
this.opts.Env = []
}
this.opts.Env.push(`GPTSCRIPT_URL=${GPTScript.serverURL}`)

GPTScript.serverProcess.stderr?.removeAllListeners()
})
Expand All @@ -130,7 +146,7 @@ export class GPTScript {
close(): void {
GPTScript.instanceCount--
if (GPTScript.instanceCount === 0 && GPTScript.serverProcess) {
GPTScript.serverURL = "http://" + (process.env.GPTSCRIPT_URL || "127.0.0.1:0")
GPTScript.serverURL = process.env.GPTSCRIPT_URL || "http://127.0.0.1:0"
GPTScript.serverProcess.kill("SIGTERM")
GPTScript.serverProcess.stdin?.end()
}
Expand Down

0 comments on commit 64b6fa2

Please sign in to comment.