Skip to content

Commit f2496a0

Browse files
authored
Merge pull request #40 from thedadams/improve-sdk-server-startup
feat: improve SDK server startup
2 parents e20cb80 + 55791e6 commit f2496a0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

gptscript/gptscript.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,9 @@ def __init__(self, opts: GlobalOptions = None):
3030
GPTScript.__gptscript_count += 1
3131

3232
if GPTScript.__server_url == "":
33-
GPTScript.__server_url = os.environ.get("GPTSCRIPT_URL", "")
33+
GPTScript.__server_url = os.environ.get("GPTSCRIPT_URL", "127.0.0.1:0")
3434

3535
if GPTScript.__gptscript_count == 1 and os.environ.get("GPTSCRIPT_DISABLE_SERVER", "") != "true":
36-
if GPTScript.__server_url == "":
37-
with socket() as s:
38-
s.bind(("", 0))
39-
GPTScript.__server_url = f"127.0.0.1:{s.getsockname()[1]}"
40-
4136
opts.toEnv()
4237

4338
GPTScript.__process = Popen(
@@ -50,6 +45,10 @@ def __init__(self, opts: GlobalOptions = None):
5045
encoding="utf-8",
5146
)
5247

48+
GPTScript.__server_url = GPTScript.__process.stderr.readline().strip("\n")
49+
if "=" in GPTScript.__server_url:
50+
GPTScript.__server_url = GPTScript.__server_url.split("=")[1]
51+
5352
self._server_url = f"http://{GPTScript.__server_url}"
5453
self._wait_for_gptscript()
5554

0 commit comments

Comments
 (0)