added prompt ingestion
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from collections.abc import Generator
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import field
|
||||
from importlib.abc import Traversable
|
||||
from importlib.resources.abc import Traversable
|
||||
from itertools import starmap
|
||||
from pathlib import PurePosixPath
|
||||
from typing import Self
|
||||
@@ -37,6 +37,12 @@ class MarkdownDocument:
|
||||
if parts[0] == "skills" and len(parts) >= 3:
|
||||
return parts[1]
|
||||
|
||||
@property
|
||||
def prompt_slug(self) -> str | None:
|
||||
parts = self.relpath.parts
|
||||
if parts[0] == "prompts" and len(parts) >= 3:
|
||||
return parts[1]
|
||||
|
||||
|
||||
def walk_resources(
|
||||
node: Traversable,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import dataclass
|
||||
from importlib.resources.abc import Traversable
|
||||
from itertools import starmap
|
||||
from typing import Self
|
||||
|
||||
from .document import MarkdownDocument
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class PromptFilesBundle:
|
||||
"""Represents a prompt and all of its associated markdown files."""
|
||||
|
||||
slug: str
|
||||
prompt: MarkdownDocument
|
||||
other: tuple[MarkdownDocument, ...]
|
||||
|
||||
@classmethod
|
||||
def from_root(cls, root: Traversable) -> list[Self]:
|
||||
# Should only be used for testing
|
||||
return list(cls.from_docs(MarkdownDocument.from_root(root).values()))
|
||||
|
||||
@classmethod
|
||||
def from_docs(cls, docs: Iterable[MarkdownDocument]) -> tuple[Self, ...]:
|
||||
return tuple(starmap(cls.from_paths, group_prompt_paths(docs).items()))
|
||||
|
||||
@classmethod
|
||||
def from_paths(cls, slug: str, paths: set[MarkdownDocument]) -> Self:
|
||||
prompt = next(iter(p for p in paths if p.relpath.name == "PROMPT.md"))
|
||||
sorted_paths = tuple(sorted(paths, key=lambda p: p.relpath.as_posix()))
|
||||
other = tuple(p for p in sorted_paths if p != prompt)
|
||||
return cls(
|
||||
slug=slug,
|
||||
prompt=prompt,
|
||||
other=other,
|
||||
)
|
||||
|
||||
|
||||
def group_prompt_paths(docs: Iterable[MarkdownDocument]) -> dict[str, set[MarkdownDocument]]:
|
||||
"""Group prompts from a list of markdown documents by their prompt slug."""
|
||||
grouped: dict[str, set[MarkdownDocument]] = {}
|
||||
for doc in sorted(
|
||||
filter(lambda d: d.prompt_slug is not None, docs),
|
||||
key=lambda d: d.relpath.as_posix(),
|
||||
):
|
||||
if doc.prompt_slug:
|
||||
grouped.setdefault(doc.prompt_slug, set()).add(doc)
|
||||
return grouped
|
||||
@@ -1,47 +1 @@
|
||||
from .common import SEMVER_RE
|
||||
from .common import SKILL_ID_RE
|
||||
from .common import ReferenceEntry
|
||||
from .common import StrictFrozenModel
|
||||
from .document import MarkdownDocumentModel
|
||||
from .document import SkillFilesBundleModel
|
||||
from .document import to_markdown_document_model
|
||||
from .prompt import PromptArgumentEntry
|
||||
from .prompt import PromptDocumentModel
|
||||
from .prompt import PromptFrontmatter
|
||||
from .prompt import PromptMetadata
|
||||
from .registry import DocsRegistry
|
||||
from .registry import PromptRecord
|
||||
from .registry import PromptSummaryRecord
|
||||
from .registry import ReferenceRecord
|
||||
from .registry import SkillRecord
|
||||
from .registry import SkillSummaryRecord
|
||||
from .skill import PersonalMcpMetadata
|
||||
from .skill import SkillDocumentModel
|
||||
from .skill import SkillFrontmatter
|
||||
from .skill import SkillMetadata
|
||||
from .skill import SkillReferenceDocumentModel
|
||||
|
||||
__all__ = [
|
||||
"SEMVER_RE",
|
||||
"SKILL_ID_RE",
|
||||
"DocsRegistry",
|
||||
"MarkdownDocumentModel",
|
||||
"PersonalMcpMetadata",
|
||||
"PromptArgumentEntry",
|
||||
"PromptDocumentModel",
|
||||
"PromptFrontmatter",
|
||||
"PromptMetadata",
|
||||
"PromptRecord",
|
||||
"PromptSummaryRecord",
|
||||
"ReferenceEntry",
|
||||
"ReferenceRecord",
|
||||
"SkillDocumentModel",
|
||||
"SkillFilesBundleModel",
|
||||
"SkillFrontmatter",
|
||||
"SkillMetadata",
|
||||
"SkillRecord",
|
||||
"SkillReferenceDocumentModel",
|
||||
"SkillSummaryRecord",
|
||||
"StrictFrozenModel",
|
||||
"to_markdown_document_model",
|
||||
]
|
||||
"""Pydantic models for the document registry."""
|
||||
|
||||
Reference in New Issue
Block a user