Skip to content

Commit

Permalink
fix python supported versions and added a check for : in template name (
Browse files Browse the repository at this point in the history
  • Loading branch information
mayankjobanputra authored Jun 7, 2024
1 parent 28348b7 commit fb8a9dc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
9 changes: 6 additions & 3 deletions docs/registry.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
4 changes: 3 additions & 1 deletion src/banks/registries/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/banks/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
class TemplateNotFoundError(Exception): ...


class InvalidTemplateError(Exception): ...


class PromptTemplate(BaseModel):
id: str
name: str
Expand Down
6 changes: 4 additions & 2 deletions tests/test_file_registry.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit fb8a9dc

Please sign in to comment.