Skip to content

Commit

Permalink
docs: fix missing tag and simplify multipart (#3876)
Browse files Browse the repository at this point in the history
Co-authored-by: KhanhTV <khanhtv@nal.vn>
Co-authored-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 4, 2023
1 parent 8ef3c89 commit 33c8440
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
32 changes: 19 additions & 13 deletions docs/source/concepts/service.rst
Expand Up @@ -371,7 +371,7 @@ model and return. To learn more, see IO descrptor reference for
output=JSON(),
)
def classify(input_series: IrisFeatures) -> Dict[str, Any]:
input_df = pd.DataFrame([input_data.dict()])
input_df = pd.DataFrame([input_series.dict()])
results = iris_clf_runner.predict.run(input_df).to_list()
return {"predictions": results}
Expand Down Expand Up @@ -411,30 +411,36 @@ logic:

.. code-block:: python
import typing as t
from __future__ import annotations
from typing import Any
import numpy as np
from pydantic import BaseModel
from bentoml.io import Multipart, NumpyNdarray, Json
class FooModel(BaseModel):
field1: int
field2: float
field3: str
class IrisFeatures(BaseModel):
sepal_length: float
sepal_width: float
petal_length: float
petal_width: float
my_np_input = NumpyNdarray.from_sample(np.ndarray(...))
output_descriptor_numpy = NumpyNdarray.from_sample(np.array([2]))
@svc.api(
input=Multipart(
arr=NumpyNdarray(schema=np.dtype(int, 4), validate=True),
json=Json(pydantic_model=FooModel),
)
output=NumpyNdarray(schema=np.dtype(int), validate=True),
arr=NumpyNdarray(
shape=(-1, 4),
dtype=np.float32,
enforce_dtype=True,
enforce_shape=True,
),
json=JSON(pydantic_model=IrisFeatures),
),
output=output_descriptor_numpy,
)
def predict(arr: np.ndarray, json: t.Dict[str, t.Any]) -> np.ndarray:
def multi_part_predict(arr: np.ndarray, json: dict[str, Any]) -> np.ndarray:
...
Sync vs Async APIs
------------------

Expand Down
1 change: 1 addition & 0 deletions examples/custom_runner/nltk_pretrained_model/README.md
Expand Up @@ -72,6 +72,7 @@ curl -X POST -H "content-type: application/text" --data "BentoML is great" http:
<tr>
<td> <code>gRPC</code> </td>
<td>
</table>

```bash
grpcurl -d @ -plaintext 0.0.0.0:3000 bentoml.grpc.v1.BentoService/Call <<EOM
Expand Down

0 comments on commit 33c8440

Please sign in to comment.