-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: dynamic invocation definitions #4334
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
17314ea
feat: dynamic invocation definitions
psychedelicious 3dbfee2
fix: do not clobber `api/v1/sessions/` route
psychedelicious 877348a
Merge remote-tracking branch 'origin/main' into feat/dynamic-invocations
keturn 751fe68
feat(dev_reload): notice when files with Invocation classes are re-lo…
keturn 3985c16
lint(api_app): replace import that was only there to test if we could…
keturn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import jurigged | ||
| from jurigged.codetools import ClassDefinition | ||
|
|
||
| from invokeai.app.invocations.baseinvocation import BaseInvocation | ||
| from invokeai.backend.util.logging import InvokeAILogger | ||
|
|
||
| logger = InvokeAILogger.getLogger(name=__name__) | ||
|
|
||
|
|
||
| def reload_nodes(path: str, codefile: jurigged.CodeFile): | ||
| """Callback function for jurigged post-run events.""" | ||
| # Things we have access to here: | ||
| # codefile.module:module - the module object associated with this file | ||
| # codefile.module_name:str - the full module name (its key in sys.modules) | ||
| # codefile.root:ModuleCode - an AST of the current source | ||
|
|
||
| # This is only reading top-level statements, not walking the whole AST, but class definition should be top-level, right? | ||
| class_names = [statement.name for statement in codefile.root.children if isinstance(statement, ClassDefinition)] | ||
| classes = [getattr(codefile.module, name) for name in class_names] | ||
| invocations = [cls for cls in classes if issubclass(cls, BaseInvocation)] | ||
| # outputs = [cls for cls in classes if issubclass(cls, BaseInvocationOutput)] | ||
|
|
||
| # We should assume jurigged has already replaced all references to methods of these classes, | ||
| # but it hasn't re-executed any annotations on them (like @title or @tags). | ||
| # We need to re-do anything that involved introspection like BaseInvocation.get_all_subclasses() | ||
| logger.info("File reloaded: %s contains invocation classes %s", path, invocations) | ||
|
|
||
|
|
||
| def start_reloader(): | ||
| watcher = jurigged.watch(logger=InvokeAILogger.getLogger(name="jurigged").info) | ||
| watcher.postrun.register(reload_nodes, apply_history=False) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Here, I gave you a function that will run after jurigged reloads anything. I haven't yet hooked it up to any of the update functions in this PR.