-
Notifications
You must be signed in to change notification settings - Fork 5
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 & bugfix: Added metadata features and fixed naming bug #11
Conversation
@masci should we disable more lint errors? I am not sure if these are valid errors, wdyt? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the formatting errors, it's a matter of style but those were legit in order to stay consistent with the rest of the codebase
src/banks/registries/directory.py
Outdated
msg = f"Prompt {name}.{version}.jinja not found in the index. Cannot set meta for a non-existing prompt." | ||
raise ValueError(msg) | ||
|
||
if f"{name}:{version}.json" in self._meta_path.glob("*.json"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glob
returns a generator so this should be something like
if f"{name}:{version}.json" in list(self._meta_path.glob("*.json"))
is it working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, it wasn't. I fixed and added unit tests as well. :)
Thanks for catching this one 🙌
Thanks a lot @masci 🙏 What do you think of the PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a comment about the overall plan of having a separate storage for metadata
src/banks/registries/directory.py
Outdated
if not self._index_path.exists() or force_reindex: | ||
self._scan() | ||
else: | ||
self._load() | ||
self._meta_path = self._path / DEFAULT_META_PATH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we want to use a separate index for the metadata? If we extend the PromptFile
model to include meta: dict[str, Any]
we would piggy back on the existing get/set infraastructure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this, I would make the changes.
src/banks/registries/directory.py
Outdated
raise FileNotFoundError(msg) | ||
return json.loads(open(meta_path, encoding="utf-8").read()) | ||
|
||
def set_meta(self, *, meta: dict, name: str, version: str | None = None, overwrite: bool = False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would try to pass meta to the regular set()
(see comment above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do that but I will also provide set_meta
separately because there are many use cases (i.e., adding accuracy, adding failed stats) that require setting meta after running the prompt. We also need such things per prompt so I will still keep the different folders for storing the meta and the prompt/index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments, almost there!!!
@@ -26,7 +32,7 @@ def __init__(self, directory_path: Path, *, force_reindex: bool = False): | |||
raise ValueError(msg) | |||
|
|||
self._path = directory_path | |||
self._index_path = self._path / "index.json" | |||
self._index_path = self._path / DEFAULT_INDEX_NAME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noice!
src/banks/registries/directory.py
Outdated
self._index.files.append(pf) | ||
self._index_path.write_text(self._index.model_dump_json()) | ||
|
||
def get(self, *, name: str, version: str | None = None) -> "Prompt": | ||
version = version or "0" | ||
def get_prompt(self, *, name: str, version: str | None = None) -> "Prompt": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why changing the method name? Its counterpart is still set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because with set
we can set both meta and prompt. I thought being explicit might be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah now I remember the convo, yeah let's scratch this. But I think get_meta
will end up being just an utility method calling get_prompt
under the hood? See comment below.
src/banks/registries/directory.py
Outdated
pf = PromptFile(name=name, version=version, path=new_prompt_file, meta=meta) | ||
return pf | ||
|
||
def set( # pylint: disable=too-many-arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can relax this rule to 10 args per method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool will do that.
src/banks/registries/directory.py
Outdated
name: str, | ||
prompt: Prompt, | ||
meta: dict | None = None, | ||
version: str | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since strings are immutable, why not defaulting here directly? version: str = DEFAULT_VERSION,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, will do it.
src/banks/registries/directory.py
Outdated
for pf in self._index.files: | ||
if pf.name == name and pf.version == version: | ||
return pf.meta | ||
raise MetaNotFoundError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this, the error will be triggered by the fact the requested pf
was not found in the index... Also what do you want to signal with MetaNotFound
, the absence of the dict or an emty dict?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was like that before. I changed it to be consistent with get_prompt
, it also raises TemplateNotFoundError
when the prompt is not found.
The idea was that if someone makes a mistake in the name, they should get the error instead of silently returning the empty dict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
for pf in self._index.files:
if pf.name == name and pf.version == version:
if not pf.meta:
raise MetaNotFoundError
return pf
raise TemplateNotFoundError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 🙌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, why not just return self.get_prompt(...).meta
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff, merging!
Allowing users to store metadata for each prompt
First create
meta
subdir inside the root template dir and then create prompt metadata.