Nesting models
You've been asked to create a schema for a batch job that executes a weather prediction model on a list of inputs and returns all the results in a list.
Latihan ini adalah bagian dari kursus
Deploying AI into Production with FastAPI
Petunjuk latihan
- Import the class from
typingthat can be used for nested lists. - Create class
BatchInputusingBaseModel. - In the
BatchInputmodel, complete theinputsfield so that it has a list ofModelInputschemas.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
from datetime import date
from pydantic import BaseModel
# Import class for nested lists
from typing import ____
class ModelInput(BaseModel):
latitude: float
longitude: float
date: date
# Create batch input model
class ____(BaseModel):
job_name: str
# Inputs are list of model inputs
inputs: ___[___]