File size: 1,380 Bytes
5ba984e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from pydantic import BaseModel, Field

class CountryPopulation(BaseModel):
    country: str
    population: int

class ContinentPopulationResponse(BaseModel):
    continent: str = Field(..., description="Name of the continent")
    total_population: int = Field(..., description="Total population of the continent")
    total_area: int = Field(..., description="Total area of the continent")
    continent_population_density: float = Field(..., description="Population density of the continent")
    max_population: CountryPopulation = Field(..., description="Country with the maximum population")
    min_population: CountryPopulation = Field(..., description="Country with the minimum population")
    avg_population: int = Field(..., description="Average population of the continent")

    # Schema-level configuration
    model_config = {
        "json_schema_extra": {
            "examples": [
                {
                    "continent": "Asia",
                    "total_population": 4641054775,
                    "total_area": 44579000,
                    "continent_population_density": 104.1,
                    "max_population": {"country": "China", "population": 1411778724},
                    "min_population": {"country": "Maldives", "population": 521874},
                    "avg_population": 92821192
                }
            ]
        }
    }