ray/doc/source/serve/doc_code/ml_models_examples.py
Sihan Wang 786c7f45cf
[Serve][Doc] Update the doc code to use new api (#27689)
Co-authored-by: Archit Kulkarni <architkulkarni@users.noreply.github.com>
2022-08-11 11:24:17 -05:00

24 lines
576 B
Python

from ray import serve
from typing import List, Dict, Any
# __batch_example_start__
@serve.deployment(route_prefix="/increment")
class BatchingExample:
def __init__(self):
self.count = 0
@serve.batch
async def handle_batch(self, requests: List[Any]) -> List[Dict]:
responses = []
for request in requests:
responses.append(request.json())
return responses
async def __call__(self, request) -> List[Dict]:
return await self.handle_batch(request)
serve.run(BatchingExample.bind())
# __batch_example_end__