Idan
07/26/2023, 11:24 AMJessica Smith
07/26/2023, 1:31 PMIdan
07/26/2023, 1:34 PMJessica Smith
07/26/2023, 1:44 PMDeceivious
07/26/2023, 3:31 PMNate
07/26/2023, 3:35 PMclass Foo(BaseModel):
a: int
b: int
class Input(BaseModel):
foo: Foo
bar: str
@flow(log_prints=True)
def my_flow(input: Input) -> None:
print(f"got input: {input!r}")
then the form will show up nicely in the UI with each field of Input
(including the nested models), but if you have a list[Input]
then the input in the UI will be a freeform JSON field. perhaps you could adjust the model you're passing in so that it contains your lists instead of passing a list of the models?Idan
07/26/2023, 4:15 PMfoo: List[Foo]
?Nate
07/26/2023, 4:20 PMlist[Model]
its going to be a freeform JSON field like
(image is the Quick Run form for this deployment)
from prefect import flow
from pydantic import BaseModel
class Foo(BaseModel):
a: int
b: int
class Input(BaseModel):
foo: list[Foo]
bar: str
@flow(log_prints=True)
def my_flow(input: Input) -> None:
print(f"got input: {input!r}")
# prefect deploy typehints.py:my_flow
Idan
07/26/2023, 4:23 PM*args
for this? 🤔Nate
07/26/2023, 4:25 PMIdan
07/26/2023, 4:27 PMNate
07/26/2023, 4:33 PMfrom prefect import flow
from pydantic import BaseModel, Field
class Input(BaseModel):
foo: int = Field(..., description="foo is a required field")
bar: bool = Field(False, description="whether to bar or not")
baz: list = Field(default_factory=list, description="a list of bazzes")
@flow(log_prints=True)
def my_flow(user_input: Input) -> None:
print(f"got input: {user_input!r}")
Idan
07/26/2023, 4:35 PMNate
07/26/2023, 4:37 PMCraig Harshbarger
07/26/2023, 5:07 PMList[...]
question. Currently we don't have any ui to handle lists unless there is an enum
and then we give you a drop down. We would have to add some ui to visually let you add/remove values and render the schema for the model in the list. Which gets a little tricky considering there can be unions and such. But its possible! Just not a priority at the moment. But if this is something you'd like to see please open a github issue for it and if there are others that want this that will help us set an accurate priority.Idan
07/26/2023, 8:44 PMa list of bazzes
), I’d like to include e.g. a sample JSON with explanation for the different kwargs. Prefect minimizes it to one-line, so the formatting is lost.Nate
07/27/2023, 3:27 PMis there a way to maintain docstring structure?hmm I'm not quite sure what you mean, could you show an example? of what you mean by
a sample JSON with explanation for the different kwargs
Idan
07/27/2023, 3:41 PMclass Input(BaseModel):
a: SomeOtherClass = Field(..., description="""A foo that bars some bazzes, with the following structure:
{
# You may specify your foo as an integer here
"foo": Optional[int]
"bar": {
# Your baz goes here
"baz": str
"should_baz": bool = False
}
}
""")
This results in a single line, even though I’d like to maintain the multi-line descriptionCraig Harshbarger
07/27/2023, 5:29 PMIdan
07/27/2023, 5:32 PMCraig Harshbarger
07/27/2023, 8:23 PMIdan
07/28/2023, 9:00 AMCraig Harshbarger
08/08/2023, 4:56 PMIdan
08/24/2023, 7:44 AM