Created
July 23, 2024 03:00
-
-
Save tuulos/0057d42774bd8640034f3496bbd5e153 to your computer and use it in GitHub Desktop.
This file contains hidden or 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