Skip to content

Commit

Permalink
make registry protocol compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Sep 28, 2024
1 parent 58196e5 commit 6210a8d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ path = "src/banks/__about__.py"
dependencies = [
"coverage[toml]>=6.5",
"pytest",
"pytest-cov",
"mkdocs-material",
"mkdocstrings[python]",
"simplemma",
Expand Down
6 changes: 4 additions & 2 deletions src/banks/registries/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def _scan(self):
self._index.files.append(pf)
self._index_path.write_text(self._index.model_dump_json())

def get(self, *, name: str, version: str = DEFAULT_VERSION) -> "PromptFile":
def get(self, *, name: str, version: str | None = None) -> "PromptFile":
version = version or DEFAULT_VERSION
for pf in self._index.files:
if pf.name == name and pf.version == version and pf.path.exists():
return pf
Expand Down Expand Up @@ -84,9 +85,10 @@ def set(
name: str,
prompt: Prompt,
meta: dict | None = None,
version: str = DEFAULT_VERSION,
version: str | None = None,
overwrite: bool = False,
):
version = version or DEFAULT_VERSION
meta = {**(meta or {}), "created_at": time.ctime()}

pf = self._create_pf(name=name, prompt=prompt, version=version, overwrite=overwrite, meta=meta)
Expand Down
10 changes: 9 additions & 1 deletion src/banks/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ class InvalidTemplateError(Exception): ...
class TemplateRegistry(Protocol):
def get(self, *, name: str, version: str | None = None) -> "Prompt": ...

def set(self, *, name: str, prompt: Prompt, version: str | None = None, overwrite: bool = False): ...
def set(
self,
*,
name: str,
prompt: Prompt,
meta: dict | None = None,
version: str | None = None,
overwrite: bool = False,
): ...

0 comments on commit 6210a8d

Please sign in to comment.