Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix python supported versions and added a check for : in template name #7

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ':'")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

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():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahah that's my OCD strictly following the convention test_<func_name> but it's ok 👍

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