-
Notifications
You must be signed in to change notification settings - Fork 20
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
Drop @register_assistant
decorator
#98
Conversation
raise AIAssistantNotDefinedError(f"Assistant with id={assistant_id} not found") | ||
assistant_cls = ASSISTANT_CLS_REGISTRY[assistant_id] | ||
assistant_cls = get_assistant_cls_registry()[assistant_id] |
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.
For this usage, we could have a get_assistant_cls
helper but there are a few side effects (please see the PR description for more details).
Overall LGTM.
Alias is fine on the use_cases import.
That's bad because it makes unit test harder... is the problem because the |
All right, I'll go for it.
I can refactor the code to use |
I added the |
@register_assistant
decorator@register_assistant
decorator
""" | ||
super().__init_subclass__(**kwargs) | ||
if hasattr(cls, "id") and cls.id is not None: | ||
if not re.match(r"^[a-zA-Z0-9_-]+$", cls.id): |
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.
Can we remove the re.match from the init?
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 added the verification in the __init_subclass__
method because it occurs at the time the subclass is created, not when an instance is initialized (__init__
). This way, inconsistencies in the id
could be detected earlier, preventing the creation of invalid subclasses.
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.
yes, that's good, but can we remove the one from __init__
?
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.
Yes, will do. I will move all checks from __init__
to __init_subclass__
return cls | ||
def get_assistant_cls(assistant_id: str) -> type[AIAssistant]: | ||
"""Get the AIAssistant class for the given assistant ID.""" | ||
return AIAssistant.get_registry()[assistant_id] |
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 we're adding classmethods to AIAssistant, maybe just make these classmethods too? This will simplify the API.
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.
Sure, I actually prefer this way too
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.
Done (commit b04abb4)
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.
Overall LGTM, but please check comments.
Also, please update docs.
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.
Nice! Much cleaner :)
Issues
Resolves #97
Description
Drop
@register_assistant
decoratorScreencast.from.19-06-2024.11.18.39.webm
Screencast.from.19-06-2024.11.16.55.webm
Discussion notes
Note
Hey there, I opened this draft to get your thoughts on the new approach.
[Click to see] Resolved discussion notes
We opted for the alias.
We used
__init_subclass__
inAIAssistant
, and@pytest.fixture(scope="module", autouse=True)
in the test files.