forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[serve] Update quickstart & getting started for explicit `Application…
…` concept (ray-project#34673) Signed-off-by: Jack He <[email protected]>
- Loading branch information
1 parent
8990f9f
commit 9e1603a
Showing
9 changed files
with
105 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import requests | ||
import starlette | ||
from typing import Dict | ||
from ray import serve | ||
from ray.serve.handle import RayServeHandle | ||
|
||
|
||
# 1. Define the models in our composition graph and an ingress that calls them. | ||
@serve.deployment | ||
class Adder: | ||
def __init__(self, increment: int): | ||
self.increment = increment | ||
|
||
def add(self, inp: int): | ||
return self.increment + inp | ||
|
||
|
||
@serve.deployment | ||
class Combiner: | ||
def average(self, *inputs) -> float: | ||
return sum(inputs) / len(inputs) | ||
|
||
|
||
@serve.deployment | ||
class Ingress: | ||
def __init__( | ||
self, adder1: RayServeHandle, adder2: RayServeHandle, combiner: RayServeHandle | ||
): | ||
self._adder1, self._adder2, self._combiner = adder1, adder2, combiner | ||
|
||
async def __call__(self, request: starlette.requests.Request) -> Dict[str, float]: | ||
input_json = await request.json() | ||
|
||
adder1_result = await self._adder1.add.remote(input_json["val"]) | ||
adder2_result = await self._adder2.add.remote(input_json["val"]) | ||
final_result = await self._combiner.average.remote(adder1_result, adder2_result) | ||
|
||
return {"result": await final_result} | ||
|
||
|
||
# 2. Build the application consisting of the models and ingress. | ||
app = Ingress.bind(Adder.bind(increment=1), Adder.bind(increment=2), Combiner.bind()) | ||
serve.run(app) | ||
|
||
# 3: Query the application and print the result. | ||
print(requests.post("http://localhost:8000/", json={"val": 100.0}).json()) | ||
# {"result": 101.5} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.