From 3ad89d5c75ca8628c9991b370e2f33468d891e53 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 18 Sep 2024 03:48:08 +0800 Subject: [PATCH] doc: add instruction for `bentoml.IODescriptor` (#4975) Signed-off-by: Frost Ming --- docs/source/guides/iotypes.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/source/guides/iotypes.rst b/docs/source/guides/iotypes.rst index 08c83bf22dc..ce915a00153 100644 --- a/docs/source/guides/iotypes.rst +++ b/docs/source/guides/iotypes.rst @@ -141,6 +141,15 @@ You can also use a Pydantic model directly at the top level for a BentoML Servic In the above code snippet, all the validated and parsed fields from the incoming request are passed into the ``generate`` method as keyword arguments stored in the ``params`` dictionary. You can access these parameters directly by their field names defined in ``AdsGenerationParams`` as keys in the dictionary. +Pydantic's ``BaseModel`` only supports built-in types in Python as field types. You can use ``bentoml.IODescriptor`` instead of ``pydantic.BaseModel`` to gain support for types such as ``numpy.ndarray``, ``pandas.DataFrame``, and ``torch.Tensor``. + +.. code-block:: python + + import bentoml + + class MyInputParams(bentoml.IODescriptor): + data: np.ndarray[tuple[int], np.dtype[np.float16]] + Files ^^^^^