From 2e0023337c0ebdbcfc9b4c9d71881b89ec286a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Tue, 26 May 2026 13:02:23 +0000 Subject: [PATCH] add models.py --- models.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 models.py diff --git a/models.py b/models.py new file mode 100644 index 0000000..7302698 --- /dev/null +++ b/models.py @@ -0,0 +1,61 @@ +import os +from typing import List, Optional +from pydantic import BaseModel, Field, validator + +class TaskCard(BaseModel): + """Pydantic model representing a structured task card. + + Attributes + ---------- + title: str + Short title of the task (max 10 words). + subject: str + Subject or topic of the task. + deadline: Optional[str] + Deadline string if mentioned, otherwise None. + deliverable: str + What needs to be submitted. + requirements: List[str] + List of concrete requirements extracted from the raw text. + difficulty: str + Difficulty level: "легко", "средне" or "сложно". + grading_criteria: Optional[str] + Grading criteria if present. + tags: List[str] + Tags describing the task. + """ + + title: str = Field(..., description="Short title of the task (max 10 words)") + subject: str = Field(..., description="Subject or topic of the task") + deadline: Optional[str] = Field(None, description="Deadline if mentioned") + deliverable: str = Field(..., description="What needs to be submitted") + requirements: List[str] = Field(default_factory=list, description="Concrete requirements") + difficulty: str = Field(..., description="Difficulty level: легко, средне, сложно") + grading_criteria: Optional[str] = Field(None, description="Grading criteria if present") + tags: List[str] = Field(default_factory=list, description="Tags describing the task") + + @validator("title") + def title_word_limit(cls, v: str) -> str: + if len(v.split()) > 10: + raise ValueError("Title must be at most 10 words") + return v + + def to_markdown(self) -> str: + """Return a nicely formatted Markdown representation of the card.""" + md = [f"## {self.title}"] + md.append(f"**Предмет:** {self.subject}") + if self.deadline: + md.append(f"**Дедлайн:** {self.deadline}") + md.append(f"**Сдать:** {self.deliverable}") + if self.requirements: + md.append("**Требования:**") + for req in self.requirements: + md.append(f"- {req}") + md.append(f"**Сложность:** {self.difficulty}") + if self.grading_criteria: + md.append(f"**Критерии оценки:** {self.grading_criteria}") + if self.tags: + md.append("**Теги:** " + ", ".join(self.tags)) + return "\n".join(md) + +# End of models.py