Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated grpc example based on recent updates #872

Merged
merged 2 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/examples/custom-json/README.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
"import requests\n",
"import json\n",
"import grpc\n",
"from mlserver.codecs.string import StringRequestCodec\n",
"import mlserver.grpc.converters as converters\n",
"import mlserver.grpc.dataplane_pb2_grpc as dataplane\n",
"import mlserver.types as types\n",
Expand Down Expand Up @@ -279,7 +280,9 @@
"print(f\"full response:\\n\")\n",
"print(response)\n",
"# retrive text output as dictionary\n",
"output = json.loads(response.outputs[0].contents.bytes_contents[0])\n",
"inference_response = converters.ModelInferResponseConverter.to_types(response)\n",
"raw_json = StringRequestCodec.decode_response(inference_response)\n",
"output = json.loads(raw_json[0])\n",
"print(f\"\\ndata part:\\n\")\n",
"pp.pprint(output)"
]
Expand All @@ -301,7 +304,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.8.15"
},
"vscode": {
"interpreter": {
Expand Down
5 changes: 4 additions & 1 deletion docs/examples/custom-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Python clients.
import requests
import json
import grpc
from mlserver.codecs.string import StringRequestCodec
import mlserver.grpc.converters as converters
import mlserver.grpc.dataplane_pb2_grpc as dataplane
import mlserver.types as types
Expand Down Expand Up @@ -209,7 +210,9 @@ response = grpc_stub.ModelInfer(inference_request_g)
print(f"full response:\n")
print(response)
# retrive text output as dictionary
output = json.loads(response.outputs[0].contents.bytes_contents[0])
inference_response = converters.ModelInferResponseConverter.to_types(response)
raw_json = StringRequestCodec.decode_response(inference_response)
output = json.loads(raw_json[0])
print(f"\ndata part:\n")
pp.pprint(output)
```