-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_url.py
31 lines (24 loc) · 880 Bytes
/
hello_url.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from ray import serve
from ray.serve.drivers import DAGDriver
from ray.serve.deployment_graph import InputNode
import starlette.requests
def query_params(request: starlette.requests.Request) -> dict[str,str]:
"""Returns request query parameters"""
return request.query_params
@serve.deployment
class Doubler:
def double(self, s: str):
return s + " " + s
@serve.deployment
class HelloDeployment:
def __init__(self, doubler):
self.doubler = doubler
async def say_hello_twice(self, name: str):
ref = await self.doubler.double.remote(f"Hello, {name}!")
return await ref
with InputNode() as req:
name = req["name"]
doubler = Doubler.bind()
hello = HelloDeployment.bind(doubler)
greeter = hello.say_hello_twice.bind(name)
graph = DAGDriver.options(route_prefix="/greet").bind(greeter, http_adapter=query_params)