ray/doc/source/serve/doc_code/quickstart.py
Sihan Wang 786c7f45cf
[Serve][Doc] Update the doc code to use new api (#27689)
Co-authored-by: Archit Kulkarni <architkulkarni@users.noreply.github.com>
2022-08-11 11:24:17 -05:00

21 lines
550 B
Python

import requests
from ray import serve
# 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
def __call__(self, request):
return {"result": self._msg}
# 2: Deploy the model.
serve.run(MyModelDeployment.bind(msg="Hello world!"))
# 3: Query the deployment and print the result.
print(requests.get("http://localhost:8000/").json())
# {'result': 'Hello world!'}