[serve] Specify how to pass init args to actors (#8738)

This commit is contained in:
Edward Oakes
2020-06-02 16:03:18 -05:00
committed by GitHub
parent 4d0e9f3c71
commit b8a9be0378
+8 -4
View File
@@ -25,7 +25,7 @@ model that you'll be serving. To create one, we'll simply specify the name, rout
serve.create_endpoint("simple_endpoint", "/simple")
You can also delete an endpoint using `serve.delete_endpoint`.
You can also delete an endpoint using ``serve.delete_endpoint``.
Note that this will not delete any associated backends, which can be reused for other endpoints.
.. code-block:: python
@@ -45,6 +45,7 @@ Use a function when your response is stateless and a class when you
might need to maintain some state (like a model).
For both functions and classes (that take as input Flask Requests), you'll need to
define them as backends to Ray Serve.
You can specify arguments to be passed to class constructors in ``serve.create_backend``, shown below.
It's important to note that Ray Serve places these backends in individual worker processes, which are replicas of the model.
@@ -54,14 +55,17 @@ It's important to note that Ray Serve places these backends in individual worker
return "hello world"
class RequestHandler:
def __init__(self):
self.msg = "hello, world!"
# Take the message to return as an argument to the constructor.
def __init__(self, msg):
self.msg = msg
def __call__(self, flask_request):
return self.msg
serve.create_backend("simple_backend", handle_request)
serve.create_backend("simple_backend_class", RequestHandler)
# Pass in the message that the backend will return as an argument.
# If we call this backend, it will respond with "hello, world!".
serve.create_backend("simple_backend_class", RequestHandler, "hello, world!")
Setting Traffic
===============