-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
41 lines (34 loc) · 1.1 KB
/
Copy pathmodels.py
File metadata and controls
41 lines (34 loc) · 1.1 KB
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
33
34
35
36
37
38
39
40
41
from pydantic import BaseModel, Field
"""
What is a Data Model?
- Defines the structure of incoming requests
- Automatically validates data (type checking, required fields)
- Provides clear error messages if validation fails
- Think of it as a "contract" for what your API expects
Example: If someone sends character_age as "five" instead of 5,
FastAPI will automatically return a 422 error with a helpful message.
"""
class StoryRequest(BaseModel):
"""Defines what data we need to generate a story"""
character_name: str = Field(
...,
min_length=1,
max_length=50,
description="The name of the story's main character"
)
character_age: int = Field(
...,
ge=1,
le=18,
description="Age of the character (1-18 years)"
)
story_theme: str = Field(
...,
min_length=1,
max_length=100,
description="The theme or topic of the story (e.g., 'friendship', 'adventure')"
)
story_length: str = Field(
...,
description="Desired length: 'short', 'medium', or 'long'"
)