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 pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||
from uuid import uuid4
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ..core.prompt import Prompt
|
||||
if TYPE_CHECKING:
|
||||
from ..core.prompt import Prompt
|
||||
|
||||
|
||||
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
|
||||
description: Optional[str] = None
|
||||
content: str
|
||||
version: str = "1.0.0"
|
||||
author: Optional[str] = None
|
||||
provider: Optional[str] = None
|
||||
version: str = "1.0.0"
|
||||
tags: List[str] = Field(default_factory=list)
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
provider: Optional[str] = None
|
||||
variables: List[Dict[str, Any]] = Field(default_factory=list)
|
||||
validation_rules: List[Dict[str, Any]] = Field(default_factory=list)
|
||||
downloads: int = 0
|
||||
likes: int = 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
|
||||
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(
|
||||
id=str(prompt.id),
|
||||
name=prompt.name,
|
||||
description=prompt.description,
|
||||
content=prompt.content,
|
||||
version=prompt.version,
|
||||
author=author,
|
||||
provider=prompt.provider,
|
||||
version=prompt.version,
|
||||
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
|
||||
def from_file(cls, filepath: Path) -> "RegistryEntry":
|
||||
import json
|
||||
with open(filepath, 'r') as f:
|
||||
data = json.load(f)
|
||||
return cls(**data)
|
||||
class RegistrySearchResult(BaseModel):
|
||||
"""Search result from registry."""
|
||||
|
||||
entry: RegistryEntry
|
||||
relevance_score: float = 0.0
|
||||
highlights: Dict[str, List[str]] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class SearchResult:
|
||||
def __init__(self, entry: RegistryEntry, relevance_score: float = 1.0):
|
||||
self.entry = entry
|
||||
self.relevance_score = relevance_score
|
||||
class RegistryStats(BaseModel):
|
||||
"""Registry statistics."""
|
||||
|
||||
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