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

feat: add name field to Prompt #13

Merged
merged 1 commit into from
Sep 28, 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
6 changes: 6 additions & 0 deletions src/banks/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(
self,
text: str,
*,
name: str | None = None,
version: str | None = None,
metadata: dict[str, Any] | None = None,
canary_word: str | None = None,
Expand All @@ -31,6 +32,7 @@ def __init__(
be used.
"""
self._metadata = metadata or {}
self._name = name
self._raw: str = text
self._render_cache = render_cache or DefaultCache()
self._template = env.from_string(text)
Expand All @@ -47,6 +49,10 @@ def _get_context(self, data: dict | None) -> dict:
def metadata(self) -> dict[str, Any]:
return self._metadata

@property
def name(self) -> str | None:
return self._name

@property
def raw(self) -> str:
"""Returns the raw text of the prompt."""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ def test_ctor():
text="This is raw text",
version="1.0",
metadata={"LLM": "GPT-3.5"},
name="test_prompt",
canary_word="FOO",
render_cache=DefaultCache(),
)
assert p.raw == "This is raw text"
assert p.version == "1.0"
assert p.metadata == {"LLM": "GPT-3.5"}
assert p.name == "test_prompt"
assert p.canary_leaked("The message is FOO")
assert p.text() == "This is raw text"
assert p.text() == "This is raw text"
Expand Down