ray/doc/source/serve/doc_code/quickstart.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
555 B
Python
Raw Normal View History

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.start()
MyModelDeployment.deploy(msg="Hello world!")
# 3: Query the deployment and print the result.
print(requests.get("http://localhost:8000/").json())
# {'result': 'Hello world!'}