This message was deleted.
# ask-for-help
s
This message was deleted.
c
that’s supported in BentoML 1.2 I believe!
Simply set the return type to this class
And return a instance of it in your api function
a
I tried that, but unfortunately it doesn’t seem to work. I’m using bento v1.2.1 and I get the following error. That’s why I was hoping to see an example
I’m wondering if I messed up some sort of
Annotated
tagging or something. It seems very tricky to get it right.
Here’s an example of what doesn’t work:
Copy code
from typing import Generator
import bentoml
from pydantic import BaseModel, Field
import pandas as pd


class Input(BaseModel):
    df1: pd.DataFrame = Field(description="df1")


class Output(BaseModel):
    df1: pd.DataFrame = Field(description="df1")
    df2: pd.DataFrame = Field(description="df2")
    df3: pd.DataFrame = Field(description="df3")


@bentoml.service
class Service:
    @bentoml.api
    def echo_df(self, df1: pd.DataFrame) -> Output:
        return Output(df1=df1, df2=df1, df3=df1)

    @bentoml.api
    def stream_df(self, df1: pd.DataFrame) -> Generator[Output, None, None]:
        for i in range(3):
            yield Output(df1=df1, df2=df1, df3=df1)


if __name__ == "__main__":
    from bentoml import SyncHTTPClient

    data = pd.DataFrame({
        "a": [1, 2, 3],
        "b": ["1", "2", "3"],
    })

    with SyncHTTPClient("localhost:3000") as client:
        value = client.echo_df(df1=data)
        print(value)

        for item in client.stream_df(df1=data):
            print(item)
c
cc @Frost Ming
a
Here’s a github issue with a bit more detail https://github.com/bentoml/BentoML/issues/4489
🙌 1
It’s very possible this is just a misunderstanding on my part, but it would be great to see an example of using these types.
f
Thanks, will investigate it
a
There’s a minor bug there that I changed the names. The first input shouldn’t be a data frame, but input. The issue seems to come from the objects not being mapped through model_dump before being sent to the serializer. I couldn’t figure out how to use an IODescriptor either.
f
I’ve made a fix and your example successfully run on this branch https://github.com/bentoml/BentoML/pull/4491/files
🙌 1
a
Cool, I’ll give it a shot. Thanks for the quick fix!