-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Redis prompt registry (#21)
* add redis registry * run redis in the CI * split the jobs * skip coverage on mac and win * reformat * fix linting * add docs
- Loading branch information
Showing
11 changed files
with
622 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,3 +155,4 @@ cython_debug/ | |
# IDEs and editors | ||
.idea/ | ||
.vscode/ | ||
.zed/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,63 @@ | ||
## Prompt registry (BETA) | ||
|
||
Prompt registry is a storage API for versioned prompts. It allows you to store and retrieve prompts from local storage. | ||
Currently, it supports storing templates in a single JSON file or in a file system directory, but it can be extended to | ||
support other storage backends. | ||
The Prompt Registry provides a storage API for managing versioned prompts. It allows you to store and retrieve prompts from different storage backends. Currently, Banks supports two storage implementations: | ||
|
||
- Directory-based storage | ||
- Redis-based storage | ||
|
||
### Usage | ||
|
||
Coming soon. | ||
```python | ||
from banks import Prompt | ||
from banks.registries.directory import DirectoryPromptRegistry | ||
from pathlib import Path | ||
|
||
# Create a registry | ||
registry = DirectoryPromptRegistry(Path("./prompts")) | ||
|
||
# Create and store a prompt | ||
prompt = Prompt( | ||
text="Write a blog post about {{topic}}", | ||
name="blog_writer", | ||
version="1.0", | ||
metadata={"author": "John Doe"} | ||
) | ||
registry.set(prompt=prompt) | ||
|
||
# Retrieve a prompt | ||
retrieved_prompt = registry.get(name="blog_writer", version="1.0") | ||
``` | ||
|
||
### Directory Registry | ||
|
||
The DirectoryPromptRegistry stores prompts as individual files in a directory. Each prompt is saved as a `.jinja` file with the naming pattern `{name}.{version}.jinja`. | ||
|
||
```python | ||
# Initialize directory registry | ||
registry = DirectoryPromptRegistry( | ||
directory_path=Path("./prompts"), | ||
force_reindex=False # Set to True to rebuild the index | ||
) | ||
``` | ||
|
||
### Redis Registry | ||
|
||
The RedisPromptRegistry stores prompts in Redis using a key-value structure. | ||
|
||
```python | ||
from banks.registries.redis import RedisPromptRegistry | ||
|
||
registry = RedisPromptRegistry( | ||
redis_url="redis://localhost:6379", | ||
prefix="banks:prompt:" | ||
) | ||
``` | ||
|
||
### Common Features | ||
|
||
Both implementations support: | ||
|
||
- Versioning with automatic "0" default version | ||
- Overwrite protection with `overwrite=True` option | ||
- Metadata storage | ||
- Error handling for missing/invalid prompts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.