Preserve nested model types in prediction requests
This commit is contained in:
parent
a26fae5064
commit
ca41feb328
1 changed files with 53 additions and 7 deletions
|
|
@ -20,13 +20,14 @@ def bootstrap_prediction_endpoint(
|
|||
@router.post("/predict", status_code=status.HTTP_200_OK, response_model=Trace)
|
||||
async def predict(input_value: schema) -> Trace: # type: ignore
|
||||
try:
|
||||
# model_dump() recursively converts nested models to dictionaries,
|
||||
# losing the validated argument types expected by the function.
|
||||
arguments = {
|
||||
name: getattr(input_value, name) for name in schema.model_fields
|
||||
}
|
||||
if inspect.iscoroutinefunction(func):
|
||||
return await cast(Callable[..., Awaitable[Trace]], func)(
|
||||
**cast(BaseModel, input_value).model_dump()
|
||||
)
|
||||
return cast(Callable[..., Trace], func)(
|
||||
**cast(BaseModel, input_value).model_dump()
|
||||
)
|
||||
return await cast(Callable[..., Awaitable[Trace]], func)(**arguments)
|
||||
return cast(Callable[..., Trace], func)(**arguments)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
|
|
|||
Loading…
Reference in a new issue