diff --git a/docs/registry.md b/docs/registry.md index c8f9def..cb3666b 100644 --- a/docs/registry.md +++ b/docs/registry.md @@ -1,5 +1,8 @@ -## Template registry +## Template registry (BETA) -::: banks.registry.TemplateRegistry +Template registry is a storage API for versioned prompts. It allows you to store and retrieve templates from local storage. +Currently, it supports storing templates in a JSON file, but it can be extended to support other storage backends. -::: banks.registry.PromptTemplate +### Usage + +Coming soon. \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 16b6855..8ec4b8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "banks" dynamic = ["version"] description = 'A prompt programming language' readme = "README.md" -requires-python = ">=3.9" +requires-python = ">=3.10" license = "MIT" keywords = [] authors = [ diff --git a/src/banks/registries/file.py b/src/banks/registries/file.py index f2525e6..7fe7f07 100644 --- a/src/banks/registries/file.py +++ b/src/banks/registries/file.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: MIT from pathlib import Path -from banks.registry import PromptTemplate, PromptTemplateIndex, TemplateNotFoundError +from banks.registry import PromptTemplate, PromptTemplateIndex, TemplateNotFoundError, InvalidTemplateError class FileTemplateRegistry: @@ -18,6 +18,8 @@ def __init__(self, user_data_path: Path) -> None: @staticmethod def _make_id(name: str, version: str | None): + if ":" in name: + raise InvalidTemplateError("Template name cannot contain ':'") if version: return f"{name}:{version}" return name diff --git a/src/banks/registry.py b/src/banks/registry.py index 976111e..19b5c0e 100644 --- a/src/banks/registry.py +++ b/src/banks/registry.py @@ -9,6 +9,9 @@ class TemplateNotFoundError(Exception): ... +class InvalidTemplateError(Exception): ... + + class PromptTemplate(BaseModel): id: str name: str diff --git a/tests/test_file_registry.py b/tests/test_file_registry.py index 5647db4..98617e2 100644 --- a/tests/test_file_registry.py +++ b/tests/test_file_registry.py @@ -1,7 +1,7 @@ import pytest from banks.registries.file import FileTemplateRegistry -from banks.registry import PromptTemplate, PromptTemplateIndex, TemplateNotFoundError +from banks.registry import PromptTemplate, PromptTemplateIndex, TemplateNotFoundError, InvalidTemplateError @pytest.fixture @@ -31,9 +31,11 @@ def test_init_from_existing_index(populated_index_dir): r.get("name", "version") -def test__make_id(): +def test_make_id(): assert FileTemplateRegistry._make_id("name", "version") == "name:version" assert FileTemplateRegistry._make_id("name", None) == "name" + with pytest.raises(InvalidTemplateError, match="Template name cannot contain ':'"): + _ = FileTemplateRegistry._make_id("name:version", None) def test_get(populated_index_dir):