Return model predictions as dataclasses instead of pydantic models #47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
Prediction
andPredictionList
objects were made based onpydantic
, anticipating this will make it easier to e.g. expose a model through an API using a framework such as FastAPI. However, this meant introducingpydantic
into the core of the library in order to facilitate a feature that most users may not care about. On the other hand, FastAPI can deal with non-pydantic
classes too (pydantic
is only needed for some extras like validation). Thus, once we want to integrate the server code properly, we should do it in such a way thatpydantic
(and further dependencies likefastapi
) remain optional extras rather than part of the core of the library.For now, in this PR I make the core prediction objects plain dataclasses, and drop
pydantic
from dependencies. This required a few changes (e.g. dropping special handling of prediction classes indictify
, usingdefault_factory
for the dict-valued fields), as well as fixing some of the tests, which did not provide all fields needed to construct the prediction objects (which for some reason is still accepted bypydantic
).