Run_code_api / src /apis /models /lesson_models.py
ABAO77's picture
Add lesson management functionality with JSON data integration and response models
0f1954e
raw
history blame
1.78 kB
from pydantic import BaseModel, Field
from typing import List, Dict, Any, Optional
class VocabularyItem(BaseModel):
english: str = Field(..., description="English word or phrase")
ipa: str = Field(..., description="IPA pronunciation")
vietnamese: str = Field(..., description="Vietnamese translation")
class KeyStructure(BaseModel):
question: str = Field(..., description="Question structure")
answer: str = Field(..., description="Answer structure")
class RolePlayItem(BaseModel):
"""Dynamic role play item that can have any speaker name as key"""
def __init__(self, **data):
# Extract the first key-value pair as speaker and dialogue
if data:
speaker, dialogue = next(iter(data.items()))
super().__init__(speaker=speaker, dialogue=dialogue)
else:
super().__init__(speaker="", dialogue="")
speaker: str = Field(..., description="Speaker name")
dialogue: str = Field(..., description="What the speaker says")
class Lesson(BaseModel):
id: str = Field(..., description="Unique lesson identifier")
unit: str = Field(..., description="Unit title")
vocabulary: List[VocabularyItem] = Field(..., description="Vocabulary list")
key_structures: List[KeyStructure] = Field(..., description="Key grammar structures")
role_play: List[Dict[str, str]] = Field(..., description="Role play dialogue")
practice_questions: List[str] = Field(..., description="Practice questions")
class LessonResponse(BaseModel):
lessons: List[Lesson] = Field(..., description="List of all lessons")
total: int = Field(..., description="Total number of lessons")
class LessonDetailResponse(BaseModel):
lesson: Lesson = Field(..., description="Lesson details")