mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00
[serve] Modify serve debugger example to use current APIs (#19513)
This commit is contained in:
parent
56e46c3c23
commit
a596d59863
1 changed files with 11 additions and 8 deletions
|
@ -228,34 +228,37 @@ We will show how this works using a Ray serve application. Copy the following co
|
|||
|
||||
import time
|
||||
|
||||
import ray
|
||||
from ray import serve
|
||||
from sklearn.datasets import load_iris
|
||||
from sklearn.ensemble import GradientBoostingClassifier
|
||||
|
||||
import ray
|
||||
from ray import serve
|
||||
|
||||
serve.start()
|
||||
|
||||
# Train model
|
||||
iris_dataset = load_iris()
|
||||
model = GradientBoostingClassifier()
|
||||
model.fit(iris_dataset["data"], iris_dataset["target"])
|
||||
|
||||
# Define Ray Serve model,
|
||||
@serve.deployment(route_prefix="/iris")
|
||||
class BoostingModel:
|
||||
def __init__(self):
|
||||
self.model = model
|
||||
self.label_list = iris_dataset["target_names"].tolist()
|
||||
|
||||
def __call__(self, flask_request):
|
||||
payload = flask_request.json["vector"]
|
||||
print("Worker: received flask request with data", payload)
|
||||
await def __call__(self, starlette_request):
|
||||
payload = await starlette_request.json()["vector"]
|
||||
print(f"Worker: received request with data: {payload}")
|
||||
|
||||
prediction = self.model.predict([payload])[0]
|
||||
human_name = self.label_list[prediction]
|
||||
return {"result": human_name}
|
||||
|
||||
# Deploy model
|
||||
client = serve.start()
|
||||
client.create_backend("iris:v1", BoostingModel)
|
||||
client.create_endpoint("iris_classifier", backend="iris:v1", route="/iris")
|
||||
serve.start()
|
||||
BoostingModel.deploy()
|
||||
|
||||
time.sleep(3600.0)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue