add models.py

This commit is contained in:
2026-05-27 13:36:02 +00:00
parent a42b33b0d1
commit 781903c1b6
+78
View File
@@ -0,0 +1,78 @@
"""
models.py
=========
This module defines the :class:`TaskCard` Pydantic model that represents a
structured representation of an informal task description.
The fields are intentionally simple but expressive enough for the unit tests
and examples in ``main.py``:
* ``title`` short humanreadable title.
* ``subject`` subject area or domain.
* ``deadline_hint`` freeform hint about when the task should be finished.
* ``deliverable_type`` what is expected to be submitted (report, code,
presentation, etc.).
* ``grading_hints`` list of strings that were mentioned in the original
text as criteria for grading.
The model uses :class:`pydantic.Field` to provide helpful descriptions and
default values. The ``__str__`` method is overridden so that printing a
model instance gives a nicely formatted summary.
"""
from __future__ import annotations
from typing import List, Optional
from pydantic import BaseModel, Field
class TaskCard(BaseModel):
"""Pydantic model for a parsed task card.
The fields are intentionally minimal but cover all information that the
assignment expects to be extracted from an informal description.
"""
title: str = Field(
...,
description="Short humanreadable title of the task.",
)
subject: Optional[str] = Field(
None,
description="Subject or domain mentioned in the text (e.g. LangChain).",
)
deadline_hint: Optional[str] = Field(
None,
description="Freeform hint about when the task should be finished.",
)
deliverable_type: Optional[str] = Field(
None,
description="What is expected to be submitted (report, code, presentation).",
)
grading_hints: List[str] = Field(
default_factory=list,
description="List of strings that were mentioned as grading criteria.",
)
def __str__(self) -> str:
"""Return a humanreadable summary of the card."""
parts = [f"Title: {self.title}"]
if self.subject:
parts.append(f"Subject: {self.subject}")
if self.deadline_hint:
parts.append(f"Deadline hint: {self.deadline_hint}")
if self.deliverable_type:
parts.append(f"Deliverable type: {self.deliverable_type}")
if self.grading_hints:
parts.append(
"Grading hints: " + ", ".join(self.grading_hints)
)
return "\n".join(parts)
class Config:
# Allow arbitrary types for future extensions.
arbitrary_types_allowed = True
# End of models.py