-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
35 lines (28 loc) · 1.21 KB
/
models.py
File metadata and controls
35 lines (28 loc) · 1.21 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
# This file is like a blueprint for your data.
# It defines what a User looks like,
# what a TranslationRequest should contain,
# And what the final TranslationResponse.
from pydantic import BaseModel, Field, EmailStr
# This line imports the main tools from the Pydantic library:
# - BaseModel: The basic building block for all your data blueprints (schemas).
# - Field: A tool to add extra details, like a default value.
# - EmailStr: A special type that ensures a string is a valid email address.
from typing import Any, Dict
# This imports useful tools from Python's 'typing' system:
# - Any: Means "could be any type of data."
# - Dict: Stands for 'Dictionary' (a collection of key-value pairs).
from datetime import datetime
# This imports the 'datetime' tool, which is used to record a specific moment in time.
class User(BaseModel):
name: str
email: EmailStr
class TranslationRequest(BaseModel):
text: Dict[str, Any]
target_language: str
user: User
class TranslationResponse(BaseModel):
original_text: Dict[str, Any]
translated_text: Dict[str, Any]
source_language: str
target_language: str
timestamp: datetime = Field(default_factory=datetime.utcnow)