Skip to content

Commit

Permalink
Merge pull request #40 from thedadams/improve-sdk-server-startup
Browse files Browse the repository at this point in the history
feat: improve SDK server startup
  • Loading branch information
thedadams authored Jul 22, 2024
2 parents e20cb80 + 55791e6 commit f2496a0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions gptscript/gptscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@ def __init__(self, opts: GlobalOptions = None):
GPTScript.__gptscript_count += 1

if GPTScript.__server_url == "":
GPTScript.__server_url = os.environ.get("GPTSCRIPT_URL", "")
GPTScript.__server_url = os.environ.get("GPTSCRIPT_URL", "127.0.0.1:0")

if GPTScript.__gptscript_count == 1 and os.environ.get("GPTSCRIPT_DISABLE_SERVER", "") != "true":
if GPTScript.__server_url == "":
with socket() as s:
s.bind(("", 0))
GPTScript.__server_url = f"127.0.0.1:{s.getsockname()[1]}"

opts.toEnv()

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

GPTScript.__server_url = GPTScript.__process.stderr.readline().strip("\n")
if "=" in GPTScript.__server_url:
GPTScript.__server_url = GPTScript.__server_url.split("=")[1]

self._server_url = f"http://{GPTScript.__server_url}"
self._wait_for_gptscript()

Expand Down

0 comments on commit f2496a0

Please sign in to comment.