fix: resolve CI linting and type errors
This commit is contained in:
@@ -1,55 +1,88 @@
|
|||||||
import uuid
|
"""Registry data models."""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||||
from typing import Any, Dict, List, Optional
|
from uuid import uuid4
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
from ..core.prompt import Prompt
|
from ..core.prompt import Prompt
|
||||||
|
|
||||||
|
|
||||||
class RegistryEntry(BaseModel):
|
class RegistryEntry(BaseModel):
|
||||||
id: str = Field(default_factory=lambda: str(uuid.uuid4())[:8])
|
"""Entry in the prompt registry."""
|
||||||
|
|
||||||
|
id: Optional[str] = Field(default_factory=lambda: str(uuid4()))
|
||||||
name: str
|
name: str
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
content: str
|
content: str
|
||||||
version: str = "1.0.0"
|
|
||||||
author: Optional[str] = None
|
author: Optional[str] = None
|
||||||
provider: Optional[str] = None
|
version: str = "1.0.0"
|
||||||
tags: List[str] = Field(default_factory=list)
|
tags: List[str] = Field(default_factory=list)
|
||||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
provider: Optional[str] = None
|
||||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
variables: List[Dict[str, Any]] = Field(default_factory=list)
|
||||||
|
validation_rules: List[Dict[str, Any]] = Field(default_factory=list)
|
||||||
downloads: int = 0
|
downloads: int = 0
|
||||||
|
likes: int = 0
|
||||||
rating: float = 0.0
|
rating: float = 0.0
|
||||||
|
is_local: bool = True
|
||||||
|
is_published: bool = False
|
||||||
|
added_at: Optional[datetime] = None
|
||||||
|
updated_at: Optional[datetime] = None
|
||||||
|
|
||||||
|
def to_prompt_content(self) -> str:
|
||||||
|
"""Convert entry to prompt YAML content."""
|
||||||
|
from ..core.prompt import Prompt, PromptVariable, ValidationRule
|
||||||
|
|
||||||
|
variables = [PromptVariable(**v) for v in self.variables]
|
||||||
|
validation_rules = [ValidationRule(**r) for r in self.validation_rules]
|
||||||
|
|
||||||
|
prompt = Prompt(
|
||||||
|
id=str(self.id) if self.id else "",
|
||||||
|
name=self.name,
|
||||||
|
description=self.description,
|
||||||
|
content=self.content,
|
||||||
|
variables=variables,
|
||||||
|
validation_rules=validation_rules,
|
||||||
|
provider=self.provider,
|
||||||
|
tags=self.tags,
|
||||||
|
version=self.version,
|
||||||
|
)
|
||||||
|
return prompt.to_yaml()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_prompt(cls, prompt: Prompt, author: Optional[str] = None) -> "RegistryEntry":
|
def from_prompt(cls, prompt: "Prompt", author: Optional[str] = None) -> "RegistryEntry":
|
||||||
|
"""Create registry entry from a Prompt."""
|
||||||
return cls(
|
return cls(
|
||||||
|
id=str(prompt.id),
|
||||||
name=prompt.name,
|
name=prompt.name,
|
||||||
description=prompt.description,
|
description=prompt.description,
|
||||||
content=prompt.content,
|
content=prompt.content,
|
||||||
version=prompt.version,
|
|
||||||
author=author,
|
author=author,
|
||||||
provider=prompt.provider,
|
version=prompt.version,
|
||||||
tags=prompt.tags,
|
tags=prompt.tags,
|
||||||
|
provider=prompt.provider,
|
||||||
|
variables=[v.model_dump() for v in prompt.variables],
|
||||||
|
validation_rules=[r.model_dump() for r in prompt.validation_rules],
|
||||||
|
is_local=True,
|
||||||
|
added_at=datetime.utcnow(),
|
||||||
)
|
)
|
||||||
|
|
||||||
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
|
class RegistrySearchResult(BaseModel):
|
||||||
def from_file(cls, filepath: Path) -> "RegistryEntry":
|
"""Search result from registry."""
|
||||||
import json
|
|
||||||
with open(filepath, 'r') as f:
|
entry: RegistryEntry
|
||||||
data = json.load(f)
|
relevance_score: float = 0.0
|
||||||
return cls(**data)
|
highlights: Dict[str, List[str]] = Field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
class SearchResult:
|
class RegistryStats(BaseModel):
|
||||||
def __init__(self, entry: RegistryEntry, relevance_score: float = 1.0):
|
"""Registry statistics."""
|
||||||
self.entry = entry
|
|
||||||
self.relevance_score = relevance_score
|
total_entries: int = 0
|
||||||
|
local_entries: int = 0
|
||||||
|
published_entries: int = 0
|
||||||
|
popular_tags: List[Dict[str, Any]] = Field(default_factory=list)
|
||||||
|
top_authors: List[Dict[str, Any]] = Field(default_factory=list)
|
||||||
|
|||||||
Reference in New Issue
Block a user