I need advice on accepting a JSON list of strings ...
# ask-for-help
e
I need advice on accepting a JSON list of strings as an input to an API. For example:
Copy code
["ABC", "DEF"]
Rather than an object:
Copy code
{
  "item_arr": [
    "ABC",
    "DEF"
  ]
}
I'm upgrading from BentoML 1.2.x where the old syntax supported a list of inputs by specifying a JSON() input in the decorator:
Copy code
@svc.api(input=JSON(), output=JSON(pydantic_model=ResponseV1), route="/predict")
However, as I try to use the new syntax with a class, I'm unsure of what the
input_spec
should be.
Copy code
@bentoml.api(route="/2.0/predict", input_spec=???)
    def predict(self, input_arr: List[str]):
The only examples I see of lists as inputs are using a numpy ndarray, which I don't need here. I needed to upgrade versions partially because I needed to enforce the process count -- which didn't seem to be something I could do with the older version of bentoml:
Copy code
@bentoml.service(
    resources={"cpu": "1"}
)
Maybe I overlooked the mechanism?
j
e
Thanks for trying, but it does not. As far as I can tell, it's impossible to make bentoml 1.3.x take input that looks like:
Copy code
["ABC", "DEF"]
Those examples would only work for:
Copy code
{
  "item_arr": [
    "ABC",
    "DEF"
  ]
}
For the moment, I've worked around the issue, but it appears to be a limitation that I'll need to work with in the future if we are going to upgrade.
j
@Frost Ming what is your suggestion here?
f
not supported in 1.2 style io descriptors for now
e
Is there a way to do it with 1.3? (we have it working in 1.2 by describing it as
JSON()
and not specifying whether it is an array, object, or whatever.)
that trick doesn't work with 1.3
And, it doesn't feel like 1.2 really wanted it done that way... but it worked.
f
You have to implement it in a FastAPI and mount it until we support it officially
e
thanks