Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return model predictions as dataclasses instead of pydantic models #47

Merged
merged 5 commits into from
Dec 14, 2023

Conversation

kmaziarz
Copy link
Contributor

The Prediction and PredictionList objects were made based on pydantic, anticipating this will make it easier to e.g. expose a model through an API using a framework such as FastAPI. However, this meant introducing pydantic 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 that pydantic (and further dependencies like fastapi) 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 in dictify, using default_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 by pydantic).

syntheseus/interface/models.py Show resolved Hide resolved
Copy link
Collaborator

@AustinT AustinT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kmaziarz kmaziarz merged commit 2310e89 into main Dec 14, 2023
6 checks passed
@kmaziarz kmaziarz deleted the kmaziarz/separate-from-pydantic branch December 14, 2023 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants