Slackbot
01/24/2023, 4:28 PMJim Rohrer
01/24/2023, 5:25 PMNickolas da Rocha Machado
01/24/2023, 6:10 PMShaohong Bai
01/24/2023, 6:22 PMChaoyu
01/26/2023, 9:15 AMChaoyu
01/26/2023, 9:18 AMChaoyu
01/26/2023, 9:18 AMawait
part if this is not an async APIJim Rohrer
01/26/2023, 3:29 PMJack Norman
04/29/2023, 12:07 AMfor runner in svc.runners:
runner.init_local()
test_json = {<dict with features>}
input_data = PydanticInputDescriptor(**test_json)
result = svc.apis[service_name].func(input_data)
output_data = PydanticOutputDescriptor(**result)
^ this all works, locally, but when I make requests to the API when serving, I get errors during Bentoml JSON’s to_http_response()
. I’d like to be able to catch this in my tests, but I’m not sure how. If I define JSON(pydantic_model=PydanticOutputDescriptor)
, how do I test the functionality that’s used in the svc.api decorator? Or am I thinking about this wrong?Chaoyu
04/30/2023, 5:21 PMJack Norman
04/30/2023, 5:23 PMinput_descriptor = (
JSON(pydantic_model=PydanticInputDescriptor))
output_descriptor = (
JSON(pydantic_model=PydanticOutputDescriptor))
@svc.api(input=input_descriptor,
output=output_descriptor)
def predict_proba(
input_data: PydanticInputDescriptor) -> dict:
# run pipeline to get results_df
results = {"data": results_df.to_dict(orient="records")}
return results
Jack Norman
04/30/2023, 5:24 PMJack Norman
04/30/2023, 5:29 PMfor runner in svc.runners:
runner.init_local()
test_json = {<dict with features>}
input_data = PydanticInputDescriptor(**test_json)
result = svc.apis[service_name].func(input_data)
output_data = PydanticOutputDescriptor(**result)
output_descriptor = (
JSON(pydantic_model=PydanticOutputDescriptor))
blah = asyncio.run(output_descriptor.to_http_response(output_data))
assert blah.status_code == 200
but when I run the test, I pass with a status code of 200, yet when I send a request to my localhost, I get: ValueError: Out of range float values are not JSON compliant
status code 500Jack Norman
04/30/2023, 5:38 PMJack Norman
04/30/2023, 6:54 PMresults = {"data": results_df.to_dict(orient="records")}
results2 = PydanticOutputDescriptor(**results)
return results2
my endpoint works. (the PydanticOutputDescriptor
handles the out-of-range floats, mentioned above).
So, that is workable. But I still feel like I’m not understanding it completely. Is it true that the output descriptor expects the api output to already be the pydantic object?Chaoyu
05/01/2023, 12:16 AMJack Norman
05/01/2023, 7:14 PM