diff --git a/src/promptforge/registry/models.py b/src/promptforge/registry/models.py new file mode 100644 index 0000000..45af38a --- /dev/null +++ b/src/promptforge/registry/models.py @@ -0,0 +1,55 @@ +import uuid +from datetime import datetime +from pathlib import Path +from typing import Any, Dict, List, Optional + +from pydantic import BaseModel, Field + +from ..core.prompt import Prompt + + +class RegistryEntry(BaseModel): + id: str = Field(default_factory=lambda: str(uuid.uuid4())[:8]) + name: str + description: Optional[str] = None + content: str + version: str = "1.0.0" + author: Optional[str] = None + provider: Optional[str] = None + tags: List[str] = Field(default_factory=list) + created_at: datetime = Field(default_factory=datetime.utcnow) + updated_at: datetime = Field(default_factory=datetime.utcnow) + downloads: int = 0 + rating: float = 0.0 + + @classmethod + def from_prompt(cls, prompt: Prompt, author: Optional[str] = None) -> "RegistryEntry": + return cls( + name=prompt.name, + description=prompt.description, + content=prompt.content, + version=prompt.version, + author=author, + provider=prompt.provider, + tags=prompt.tags, + ) + + def to_file(self, registry_dir: Path) -> Path: + registry_dir.mkdir(parents=True, exist_ok=True) + filepath = registry_dir / f"{self.id}.yaml" + with open(filepath, 'w') as f: + f.write(self.model_dump_json(indent=2)) + return filepath + + @classmethod + def from_file(cls, filepath: Path) -> "RegistryEntry": + import json + with open(filepath, 'r') as f: + data = json.load(f) + return cls(**data) + + +class SearchResult: + def __init__(self, entry: RegistryEntry, relevance_score: float = 1.0): + self.entry = entry + self.relevance_score = relevance_score \ No newline at end of file