mirror of
https://github.com/wassname/ray.git
synced 2026-07-09 15:20:26 +08:00
[serve] Specify how to pass init args to actors (#8738)
This commit is contained in:
@@ -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
|
||||
===============
|
||||
|
||||
Reference in New Issue
Block a user