better data models
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import re
|
||||
from collections.abc import Mapping
|
||||
from pathlib import PurePosixPath
|
||||
from typing import Any
|
||||
from typing import Literal
|
||||
|
||||
import yaml
|
||||
from pydantic import Field
|
||||
from pydantic import field_validator
|
||||
|
||||
@@ -100,10 +102,21 @@ class PromptFrontmatter(StrictFrozenModel):
|
||||
return value
|
||||
|
||||
|
||||
class PromptDocumentModel(StrictFrozenModel):
|
||||
"""Structured representation of a prompt markdown document."""
|
||||
class StoredPrompt(StrictFrozenModel):
|
||||
"""Normalized prompt document content with path and frontmatter for storage in the registry."""
|
||||
|
||||
prompt_id: str
|
||||
relpath: str
|
||||
relpath: PurePosixPath
|
||||
content: str
|
||||
frontmatter: PromptFrontmatter
|
||||
frontmatter: PromptFrontmatter | None = None
|
||||
|
||||
@field_validator("frontmatter", mode="before")
|
||||
@classmethod
|
||||
def parse_frontmatter_yaml(cls, value: str | None):
|
||||
if value is None:
|
||||
return None
|
||||
try:
|
||||
data = yaml.safe_load(value)
|
||||
except yaml.YAMLError as e:
|
||||
raise ValueError(f"invalid YAML in frontmatter: {e}") from e
|
||||
return PromptFrontmatter.model_validate(data)
|
||||
|
||||
Reference in New Issue
Block a user