Skip to content

Commit

Permalink
feat: add name field to prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Sep 28, 2024
1 parent 2ff5d89 commit a1d581e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
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

0 comments on commit a1d581e

Please sign in to comment.