SuperDuperDB / superduperdb

🔮 SuperDuperDB: Bring AI to your database! Build, deploy and manage any AI application directly with your existing data infrastructure, without moving your data. Including streaming inference, scalable model training and vector search.
https://superduperdb.com
Apache License 2.0
4.54k stars 444 forks source link

[CORE-0.3] Remove `@dc.dataclass` wrappers everywhere #2129

Closed blythed closed 18 hours ago

blythed commented 1 month ago

Currently, everytime a user wants to create his/her own Component, he has to additionally wrap with @dc.dataclass. This is unnecessary overhead and should be removed as a requirement.

Should be possible with something like this:

import dataclasses as dc

class AutoDataclassMeta(type):
    def __new__(cls, name, bases, dct):
        # Automatically applies the dataclass decorator to the new class
        new_cls = super().__new__(cls, name, bases, dct)
        new_cls = dc.dataclass(kw_only=True)(new_cls)
        return new_cls

class Component(metaclass=AutoDataclassMeta):
    # Now every subclass of Component will automatically be a keyword-only dataclass
    pass

class MyComponent(Component):
    some_field: int
    another_field: str = "default"

# When you instantiate MyComponent, it behaves as a dataclass with keyword-only arguments
comp = MyComponent(some_field=10, another_field='example')
jieguangzhou commented 1 month ago

BTW, If we use metaclass, we can also add @ensure_initialized to predict and predict_one