BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Deploying AI into Production with FastAPI

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Import the class from typing that can be used for nested lists.
  • Create class BatchInput using BaseModel.
  • In the BatchInput model, complete the inputs field so that it has a list of ModelInput schemas.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

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: ___[___]
Kodu Düzenle ve Çalıştır