add models.py

This commit is contained in:
2026-05-27 14:01:27 +00:00
parent cf9849a2dd
commit 589c9135aa
+35 -41
View File
@@ -1,44 +1,38 @@
from typing import Optional, List
from pydantic import BaseModel
class TaskCard(BaseModel):
"""Pydantic model representing a task card.
Attributes:
title: The main title of the task.
subject: Optional subject or domain of the task.
deadline: Optional due date in ISO format or human readable string.
deliverable: Optional description of what should be produced.
criteria: List of acceptance criteria strings.
""" """
Pydantic model representing a structured assignment card.
Fields: title: str
- title: short title of the task (string) subject: Optional[str] = None
- subject: main topic or subject area (string, optional) deadline: Optional[str] = None
- deadline_hint: freeform hint about due date (string, optional) deliverable: Optional[str] = None
- deliverable_type: what is expected to be submitted (string, optional) criteria: List[str]
- grading_hints: list of strings describing evaluation criteria (list[str], optional)
def to_markdown(self) -> str:
"""Return a Markdown representation of the task card.
The format follows a simple, readable structure that can be used in
documentation or issue trackers. Empty optional fields are omitted.
""" """
from __future__ import annotations lines = [f"# {self.title}"]
if self.subject:
from typing import List, Optional lines.append(f"**Subject:** {self.subject}")
if self.deadline:
from pydantic import BaseModel, Field lines.append(f"**Deadline:** {self.deadline}")
if self.deliverable:
class AssignmentCard(BaseModel): lines.append(f"**Deliverable:** {self.deliverable}")
"""Structured representation of an informal assignment description.""" if self.criteria:
lines.append("## Acceptance Criteria")
title: str = Field(..., description="Short title or main action of the task") for idx, crit in enumerate(self.criteria, 1):
subject: Optional[str] = Field(None, description="Primary subject or topic of the task") lines.append(f"{idx}. {crit}")
deadline_hint: Optional[str] = Field( return "\n\n".join(lines)
None,
description="Freeform hint about when the task is due (e.g., 'к пятнице')",
)
deliverable_type: Optional[str] = Field(
None, description="What should be submitted: report, code, presentation, etc."
)
grading_hints: List[str] = Field(
default_factory=list,
description="List of evaluation criteria mentioned in the text",
)
class Config:
arbitrary_types_allowed = True
json_schema_extra = {
"example": {
"title": "Мини‑отчёт по LangChain",
"subject": "LangChain",
"deadline_hint": "к пятнице",
"deliverable_type": "отчёт",
"grading_hints": ["полнота", "пример кода"],
}
}