Skip to content

Commit adb9531

Browse files
author
Bryannah Hernandez
committed
fastapi fixes
1 parent de9a36c commit adb9531

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

src/sagemaker/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ async def main():
5858
use_colors=True,
5959
)
6060
server = uvicorn.Server(config)
61+
logger.info("I'm just waiting for a connection")
6162
await server.serve()

src/sagemaker/local_run.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Entry point for running the service locally
4+
5+
# Verify if uvicorn and fastapi are installed
6+
if ! command -v uvicorn &> /dev/null
7+
then
8+
echo "uvicorn could not be found, installing..."
9+
pip install "uvicorn[standard]"
10+
fi
11+
12+
echo "Starting the service locally"
13+
uvicorn $1:app --port 8000 --host 0.0.0.0 --reload &
14+
UVICORN_PID=$!
15+
16+
echo $UVICORN_PID
17+
18+
echo "Wait for the service to be completely ready"
19+
# uvicorn takes couple of seconds to launch the service
20+
sleep 10
21+
22+
exit 0

src/sagemaker/serve/model_server/multi_model_server/server.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import requests
77
import logging
88
import platform
9+
import time
10+
import json
911
from pathlib import Path
1012
from sagemaker import Session, fw_utils
1113
from sagemaker.serve.utils.exceptions import LocalModelInvocationException
@@ -27,28 +29,43 @@ class InProcessMultiModelServer:
2729

2830
def _start_serving(self):
2931
"""Initializes the start of the server"""
30-
31-
logger.info("Server started at http://0.0.0.0")
32-
3332
asyncio.create_task(main())
3433

34+
time.sleep(10)
35+
3536
def _invoke_multi_model_server_serving(self, request: object, content_type: str, accept: str):
36-
"""Invokes the MMS server by sending POST request"""
37+
"""Placeholder docstring"""
3738

38-
logger.info(request)
39-
logger.info(content_type)
40-
logger.info(accept)
39+
logger.info("Now im here ")
40+
41+
try: # for Python 3
42+
from http.client import HTTPConnection
43+
except ImportError:
44+
from httplib import HTTPConnection
45+
46+
HTTPConnection.debuglevel = 1
47+
logging.basicConfig() # you need to initialize logging, otherwise you will not see
48+
# anything from requests
49+
logging.getLogger().setLevel(logging.DEBUG)
50+
requests_log = logging.getLogger("urllib3")
51+
requests_log.setLevel(logging.DEBUG)
52+
requests_log.propagate = True
4153

4254
try:
43-
response = requests.post(
55+
requests.get("http://localhost:8000/", verify=False).json()
56+
except Exception as ex:
57+
logger.error(ex)
58+
raise ex
59+
60+
try:
61+
response = requests.get(
4462
"http://0.0.0.0:8000/generate",
45-
data=request,
63+
json=json.dumps(request),
4664
headers={"Content-Type": content_type, "Accept": accept},
4765
timeout=600,
48-
)
49-
response.raise_for_status()
66+
).json()
5067

51-
return response.content
68+
return response
5269
except requests.exceptions.ConnectionError as e:
5370
logger.debug(f"Error connecting to the server: {e}")
5471
except requests.exceptions.HTTPError as e:

src/sagemaker/serve/utils/predictors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ def __init__(
227227

228228
def predict(self, data):
229229
"""Placeholder docstring"""
230+
logger.info("Entering predict to make a prediction on ")
231+
logger.info(data)
230232
return [
231233
self.deserializer.deserialize(
232234
io.BytesIO(

0 commit comments

Comments
 (0)