Spaces:
Sleeping
Sleeping
File size: 1,775 Bytes
0f1954e |
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 42 43 44 45 46 |
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")
|