add models.py
This commit is contained in:
@@ -1,61 +1,44 @@
|
||||
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.
|
||||
"""
|
||||
Pydantic model representing a structured assignment card.
|
||||
|
||||
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")
|
||||
Fields:
|
||||
- title: short title of the task (string)
|
||||
- subject: main topic or subject area (string, optional)
|
||||
- deadline_hint: free‑form hint about due date (string, optional)
|
||||
- deliverable_type: what is expected to be submitted (string, optional)
|
||||
- grading_hints: list of strings describing evaluation criteria (list[str], optional)
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@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
|
||||
from typing import List, Optional
|
||||
|
||||
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)
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
# End of models.py
|
||||
class AssignmentCard(BaseModel):
|
||||
"""Structured representation of an informal assignment description."""
|
||||
|
||||
title: str = Field(..., description="Short title or main action of the task")
|
||||
subject: Optional[str] = Field(None, description="Primary subject or topic of the task")
|
||||
deadline_hint: Optional[str] = Field(
|
||||
None,
|
||||
description="Free‑form 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": ["полнота", "пример кода"],
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user