Skip to content

Commit 38c368f

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 25c1368 commit 38c368f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

gptscript/gptscript.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ def __init__(self, opts: GlobalOptions = None):
3232
GPTScript.__gptscript_count += 1
3333

3434
if GPTScript.__server_url == "":
35-
GPTScript.__server_url = os.environ.get("GPTSCRIPT_URL", "127.0.0.1:0")
35+
GPTScript.__server_url = os.environ.get("GPTSCRIPT_URL", "http://127.0.0.1:0")
36+
if not (GPTScript.__server_url.startswith("http://") or GPTScript.__server_url.startswith("https://")):
37+
GPTScript.__server_url = f"http://{GPTScript.__server_url}"
3638

37-
if GPTScript.__gptscript_count == 1 and os.environ.get("GPTSCRIPT_DISABLE_SERVER", "") != "true":
39+
if GPTScript.__gptscript_count == 1 and os.environ.get("GPTSCRIPT_URL", "") == "":
3840
self.opts.toEnv()
3941

4042
GPTScript.__process = Popen(
41-
[_get_command(), "--listen-address", GPTScript.__server_url, "sdkserver"],
43+
[_get_command(), "--listen-address", GPTScript.__server_url.removeprefix("http://"), "sdkserver"],
4244
stdin=PIPE,
4345
stdout=PIPE,
4446
stderr=PIPE,
@@ -51,7 +53,10 @@ def __init__(self, opts: GlobalOptions = None):
5153
if "=" in GPTScript.__server_url:
5254
GPTScript.__server_url = GPTScript.__server_url.split("=")[1]
5355

54-
self._server_url = f"http://{GPTScript.__server_url}"
56+
self.opts.Env.append("GPTSCRIPT_URL=" + GPTScript.__server_url)
57+
self._server_url = GPTScript.__server_url
58+
if not (self._server_url.startswith("http://") or self._server_url.startswith("https://")):
59+
self._server_url = f"http://{self._server_url}"
5560
self._wait_for_gptscript()
5661

5762
def _wait_for_gptscript(self):

tox.ini

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ passenv =
1212
ANTHROPIC_API_KEY
1313
GPTSCRIPT_BIN
1414
GPTSCRIPT_URL
15-
GPTSCRIPT_DISABLE_SERVER
1615
GPTSCRIPT_CONFIG_FILE
1716
commands =
1817
install_gptscript

0 commit comments

Comments
 (0)