Skip to content

Commit e6c1996

Browse files
authored
use CENTML_SERVER_URL instead of IP and PORT (#53)
* Use CENTML_SERVER_URL instead of IP and PORT
1 parent abdeb60 commit e6c1996

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ To run the server locally, you can use the following CLI command:
3535
centml server
3636
```
3737
By default, the server will run at the URL `http://0.0.0.0:8090`. \
38-
You can change this by setting the environment variables `CENTML_SERVER_IP` and `CENTML_SERVER_PORT`
38+
You can change this by setting the environment variable `CENTML_SERVER_URL`
3939

4040

4141
Then, within your python script include the following:
@@ -55,7 +55,7 @@ output = compiled_model(inputs)
5555
```
5656
Note that the centml backend compiler is non-blocking. This means it that until the server returns the compiled model, your python script will use the uncompiled model to generate the output.
5757

58-
Again, make sure your script's environment sets the environment variables `CENTML_SERVER_IP` and `CENTML_SERVER_PORT` to communicate with the desired server.
58+
Again, make sure your script's environment sets `CENTML_SERVER_URL` to communicate with the desired server.
5959

6060

6161
### Tests

centml/compiler/config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ class Config:
1414
COMPILING_SLEEP_TIME: int = 15
1515

1616
CACHE_PATH: str = os.getenv("CENTML_CACHE_DIR", default=os.path.expanduser("~/.cache/centml"))
17-
SERVER_IP: str = os.getenv("CENTML_SERVER_IP", default="0.0.0.0")
18-
SERVER_PORT: str = os.getenv("CENTML_SERVER_PORT", default="8090")
19-
SERVER_URL: str = f"http://{SERVER_IP}:{SERVER_PORT}"
17+
18+
SERVER_URL: str = os.getenv("CENTML_SERVER_URL", default="http://0.0.0.0:8090")
2019

2120
BACKEND_BASE_PATH: str = os.path.join(CACHE_PATH, "backend")
2221
SERVER_BASE_PATH: str = os.path.join(CACHE_PATH, "server")

centml/compiler/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import io
22
import os
33
from http import HTTPStatus
4+
from urllib.parse import urlparse
45
import logging
56
import uvicorn
67
import torch
@@ -107,7 +108,8 @@ async def download_handler(model_id: str):
107108

108109

109110
def run():
110-
uvicorn.run(app, host=config_instance.SERVER_IP, port=int(config_instance.SERVER_PORT))
111+
parsed = urlparse(config_instance.SERVER_URL)
112+
uvicorn.run(app, host=parsed.hostname, port=parsed.port)
111113

112114

113115
if __name__ == "__main__":

0 commit comments

Comments
 (0)