Created
July 2, 2024 18:35
-
-
Save tuulos/9c730ebc66baf914e924c3c5fade6d1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from metaflow import FlowSpec, Parameter, step, JSONType, Task, current | |
from datetime import datetime | |
from functools import wraps | |
from pydantic import BaseModel | |
class Config(BaseModel): | |
id: int | |
name = 'John Doe' | |
def validate(f): | |
@wraps(f) | |
def wrapper(self): | |
for param in self._graph_info['parameters']: | |
config = getattr(self, param['name']) | |
user = Config(**config) | |
f(self) | |
return wrapper | |
class PydanticFlow(FlowSpec): | |
user = Parameter("user", | |
help="Configuration", | |
type=JSONType) | |
@validate | |
@step | |
def start(self): | |
pass | |
self.next(self.end) | |
@step | |
def end(self): | |
print("done!") | |
if __name__ == '__main__': | |
PydanticFlow() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment