Garden-AI / garden

https://garden-ai.readthedocs.io
MIT License
16 stars 4 forks source link

Hholb/422 connector design #478

Closed hholb closed 4 weeks ago

hholb commented 1 month ago

Resolves #422

Overview

:exclamation: BREAKING CHANGES :exclamation:

Redesign existing model connectors to inherit from a new ModelConnector abstract base class. The new class leverages pydantic v2 for validation and parsing of user input. This introduces a breaking change because the constructors for the GitHubConnector and HFConnector no longer accept positional arguments and require keyword args instead.

This no longer works and will raise an error:

c = HFConnector("Garden-AI/sklearn-iris")

Now it must be:

c = HFConnector(repo_id="Garden-AI/sklearn-iris")

Discussion

I created a new interface for users to construct these classes: a function called create_connector that takes a URL to a repo and returns the appropriate connector type. It is defined in garden_ai/model_connectors/model_utils.py

Instead of constructing the correct connector class directly users can now do this:

from garden_ai.model_connectors import create_connector

c = create_connector("https://huggingface.co/Garden-AI/sklearn-iris")
# or
c = create_connector("https://github.com/Garden-AI/garden")

I suggest we encourage users to use create_connector going forward as that will allow us to change the model connectors more easily without impacting user code. I updated the notebook templates to use create_connector as part of this PR.

Testing

Added new unit tests. Updated existing unit tests to handle the new constructors.

Can be tested pretty easily in Ipython by importing create_connector or the concrete model connectors and giving them a test drive.

Documentation

Added doc comments for all new functions and classes.


📚 Documentation preview 📚: https://garden-ai--478.org.readthedocs.build/en/478/

codecov-commenter commented 1 month ago

Codecov Report

Attention: Patch coverage is 86.94030% with 35 lines in your changes missing coverage. Please review.

Project coverage is 77.41%. Comparing base (e966643) to head (16d8947).

Files Patch % Lines
garden_ai/model_connectors/model_connector.py 83.72% 21 Missing :warning:
garden_ai/model_connectors/github_conn.py 85.36% 6 Missing :warning:
garden_ai/model_connectors/hugging_face.py 84.61% 4 Missing :warning:
garden_ai/model_connectors/exceptions.py 84.61% 2 Missing :warning:
garden_ai/model_connectors/model_utils.py 88.23% 2 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #478 +/- ## ========================================== + Coverage 76.73% 77.41% +0.67% ========================================== Files 52 53 +1 Lines 3465 3577 +112 ========================================== + Hits 2659 2769 +110 - Misses 806 808 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.