Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Signed-off-by: Ubuntu <29749331+aarnphm@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
1,004 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,43 @@ | ||
from __future__ import annotations | ||
|
||
import asyncio | ||
|
||
import grpc | ||
import numpy as np | ||
|
||
from bentoml.client import Client | ||
|
||
|
||
from bentoml.grpc.utils import import_generated_stubs | ||
async def arun(client: Client): | ||
|
||
pb, services = import_generated_stubs() | ||
res = await client.async_classify(np.array([[5.9, 3, 5.1, 1.8]])) | ||
print("Result from 'client.async_classify':\n", res) | ||
res = await client.async_call("classify", np.array([[5.9, 3, 5.1, 1.8]])) | ||
print("Result from 'client.async_call':\n", res) | ||
|
||
|
||
async def run(): | ||
async with grpc.aio.insecure_channel("localhost:3000") as channel: | ||
stub = services.BentoServiceStub(channel) | ||
req = await stub.Call( | ||
request=pb.Request( | ||
api_name="classify", | ||
ndarray=pb.NDArray( | ||
dtype=pb.NDArray.DTYPE_FLOAT, | ||
shape=(1, 4), | ||
float_values=[5.9, 3, 5.1, 1.8], | ||
), | ||
) | ||
) | ||
print(req) | ||
def run(client: Client): | ||
res = client.classify(np.array([[5.9, 3, 5.1, 1.8]])) | ||
print("Result from 'client.classify':\n", res) | ||
res = client.call("classify", np.array([[5.9, 3, 5.1, 1.8]])) | ||
print("Result from 'client.call(bentoml_api_name='classify')':\n", res) | ||
|
||
|
||
if __name__ == "__main__": | ||
loop = asyncio.new_event_loop() | ||
try: | ||
loop.run_until_complete(run()) | ||
finally: | ||
loop.close() | ||
assert loop.is_closed() | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-rwa", "--run-with-async", action="store_true", default=False) | ||
parser.add_argument("--grpc", action="store_true", default=False) | ||
args = parser.parse_args() | ||
|
||
c = Client.from_url("localhost:3000", grpc=args.grpc) | ||
|
||
if args.run_with_async: | ||
loop = asyncio.new_event_loop() | ||
try: | ||
loop.run_until_complete(arun(c)) | ||
finally: | ||
loop.close() | ||
assert loop.is_closed() | ||
else: | ||
run(c) |
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
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
Oops, something went wrong.