Skip to content

Commit

Permalink
chore: update implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
aarnphm committed Nov 29, 2022
1 parent c9e86f6 commit 3378ae1
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 336 deletions.
55 changes: 11 additions & 44 deletions grpc-client/python/client.py
@@ -1,7 +1,6 @@
from __future__ import annotations

import asyncio
import functools
from typing import TYPE_CHECKING

import numpy as np
Expand All @@ -12,52 +11,20 @@
from bentoml.client import GrpcClient


async def arun(c: GrpcClient):
print("registered services:", await c.get_services())
async def arun(client: GrpcClient):
print("registered services:", await client.get_services())

async with c.aservice("health") as health_client:
res = await health_client.Check(service="bentoml.grpc.v1.BentoService")
print(res)
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 with c.aservice() as client:
res = await client.Call(
api_name="classify",
ndarray=dict(
dtype=1,
shape=[1, 4],
float_values=[5.9, 3, 5.1, 1.8],
),
)
print("Result from 'await client.Call':\n", res)
res = await client.async_classify(np.array([[5.9, 3, 5.1, 1.8]]))
print("Result from 'client.async_classify':\n", res)


def run(c: Client):
with c.service("health") as health_client:
Check = functools.partial(
health_client.Check, service="bentoml.grpc.v1.BentoService"
)
for to_json in (True, False):
print(
f"Health check ({'serialized' if to_json else 'deserialized'}):",
Check(to_json=to_json),
)

with c.service() as client:
res = client.Call(
api_name="classify",
ndarray=dict(
dtype=1,
shape=[1, 4],
float_values=[5.9, 3, 5.1, 1.8],
),
)
print("Result from 'client.Call':\n", res)
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)
def run(client: GrpcClient):
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__":
Expand Down
12 changes: 5 additions & 7 deletions pyproject.toml
Expand Up @@ -136,17 +136,15 @@ grpc = [
# Restrict maximum version due to breaking protobuf 4.21.0 changes
# (see https://github.com/protocolbuffers/protobuf/issues/10051)
# 3.19.5 is currently breaking on a lot of system.
"protobuf>=3.5.0, <3.20, !=3.19.5",
"protobuf>=3.5.0,<4.0dev,!=3.19.5",
# Lowest version that support 3.10. We need to set an upper bound
# We can't use 1.48.2 since it depends on 3.19.5
"grpcio>=1.41.0,!=1.48.2",
# grpcio>=1.48.0 provides a pre-built M1 wheel.
"grpcio>=1.48.0,!=1.48.2;platform_machine=='arm64' and platform_system=='Darwin'",
"grpcio-health-checking>=1.41.0,!=1.48.2",
"grpcio>=1.41.0",
"grpcio-health-checking>=1.41.0",
"opentelemetry-instrumentation-grpc==0.35b0",
]
grpc-reflection = ["bentoml[grpc]", "grpcio-reflection>=1.41.0,!=1.48.2"]
grpc-channelz = ["bentoml[grpc]", "grpcio-channelz>=1.41.0,!=1.48.2"]
grpc-reflection = ["bentoml[grpc]", "grpcio-reflection>=1.41.0"]
grpc-channelz = ["bentoml[grpc]", "grpcio-channelz>=1.41.0"]
# We kept for compatibility with previous
# versions of BentoML. It is discouraged to use this, instead use any
# of the above tracing.* extras.
Expand Down
2 changes: 0 additions & 2 deletions requirements/tests-requirements.txt
Expand Up @@ -17,6 +17,4 @@ imageio==2.22.4
pyarrow==10.0.1
build[virtualenv]==0.9.0
protobuf==3.19.6
grpcio>=1.41.0, <1.49, !=1.48.2
grpcio-health-checking>=1.41.0, <1.49, !=1.48.2
opentelemetry-instrumentation-grpc==0.35b0
5 changes: 4 additions & 1 deletion scripts/generate_grpc_stubs.sh
@@ -1,15 +1,18 @@
#!/usr/bin/env bash

set -e

GIT_ROOT=$(git rev-parse --show-toplevel)
STUBS_GENERATOR="bentoml/stubs-generator"
BASEDIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" &>/dev/null && pwd 2>/dev/null)"

cd "$GIT_ROOT/src" || exit 1

main() {
local VERSION="${1:-v1}"
# Use inline heredoc for even faster build
# Keeping image as cache should be fine since we only want to generate the stubs.
if [[ $(docker images --filter=reference="$STUBS_GENERATOR" -q) == "" ]] || test "$(git diff --name-only --diff-filter=d -- "$0")"; then
if test "$(git diff --name-only --diff-filter=d -- "$BASEDIR/$(basename "$0")")" || [[ $(docker images --filter=reference="$STUBS_GENERATOR" -q) == "" ]]; then
docker buildx build --platform=linux/amd64 -t "$STUBS_GENERATOR" --load -f- . <<EOF
# syntax=docker/dockerfile:1.4-labs
Expand Down

0 comments on commit 3378ae1

Please sign in to comment.