2022-01-27 02:14:25 +01:00
|
|
|
import requests
|
|
|
|
from ray import serve
|
|
|
|
|
|
|
|
|
2022-05-16 11:38:43 -05:00
|
|
|
# 1: Define a Ray Serve deployment.
|
|
|
|
@serve.deployment(route_prefix="/")
|
|
|
|
class MyModelDeployment:
|
|
|
|
def __init__(self, msg: str):
|
|
|
|
# Initialize model state: could be very large neural net weights.
|
|
|
|
self._msg = msg
|
2022-01-27 02:14:25 +01:00
|
|
|
|
2022-05-16 11:38:43 -05:00
|
|
|
def __call__(self, request):
|
|
|
|
return {"result": self._msg}
|
2022-01-27 02:14:25 +01:00
|
|
|
|
|
|
|
|
2022-05-16 11:38:43 -05:00
|
|
|
# 2: Deploy the model.
|
2022-08-11 09:24:17 -07:00
|
|
|
serve.run(MyModelDeployment.bind(msg="Hello world!"))
|
2022-01-27 02:14:25 +01:00
|
|
|
|
2022-05-16 11:38:43 -05:00
|
|
|
# 3: Query the deployment and print the result.
|
|
|
|
print(requests.get("http://localhost:8000/").json())
|
|
|
|
# {'result': 'Hello world!'}
|