Slackbot
03/28/2023, 2:38 PMsauyon
03/28/2023, 3:20 PMcontext
.Sidekick
03/28/2023, 3:20 PMJSONResponse
function from the fastapi.responses
module. Here's an example of how to modify your code to return a custom status code and detail message:
python
from fastapi import HTTPException
from fastapi.responses import JSONResponse
try:
results = await pub_classifier_runner.async_run(input_text)
label_id = results[0]['label'].split('_')[1]
score = round(results[0]['score'], 2)
return [{
'label': ids_mapping.get(label_id),
'score': score,
'model_version': pub_classifier_model.info.metadata.get('version')
}]
except Exception as e:
bentoml_logger.error(f'Error running pub_classifier_runner: {e}')
raise HTTPException(status_code=503, detail=str(e))
Sidekick
03/28/2023, 3:20 PMsauyon
03/28/2023, 3:21 PMJSONResponse
comes from. But yeah, fastapi APIs won't work in BentoMLPatrick Alves
03/28/2023, 4:54 PM