Skip to content

Commit

Permalink
feat: issue cheshire-cat-ai#980
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe Coco committed Dec 4, 2024
1 parent 8c7f2b5 commit a75fdc7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions core/cat/mad_hatter/mad_hatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ def toggle_plugin(self, plugin_id):
# Execute hook on plugin deactivation
# Deactivation hook must happen before actual deactivation,
# otherwise the hook will not be available in _plugin_overrides anymore
for hook in self.plugins[plugin_id]._plugin_overrides:
if hook.name == "deactivated":
hook.function(self.plugins[plugin_id])
for name, function in self.plugins[plugin_id]._plugin_overrides.items():
if name == "deactivated":
function(self.plugins[plugin_id])

# Deactivate the plugin
self.plugins[plugin_id].deactivate()
Expand All @@ -221,9 +221,9 @@ def toggle_plugin(self, plugin_id):
# Execute hook on plugin activation
# Activation hook must happen before actual activation,
# otherwise the hook will still not be available in _plugin_overrides
for hook in self.plugins[plugin_id]._plugin_overrides:
if hook.name == "activated":
hook.function(self.plugins[plugin_id])
for name, function in self.plugins[plugin_id]._plugin_overrides.items():
if name == "activated":
function(self.plugins[plugin_id])

# Add the plugin in the list of active plugins
self.active_plugins.append(plugin_id)
Expand Down
12 changes: 6 additions & 6 deletions core/cat/mad_hatter/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ def deactivate(self):
def settings_schema(self):
# is "settings_schema" hook defined in the plugin?
if "settings_schema" in self._plugin_overrides:
return self._plugin_overrides["settings_schema"]()
return self._plugin_overrides["settings_schema"].function()
else:
# if the "settings_schema" is not defined but
# "settings_model" is it get the schema from the model
if "settings_model" in self._plugin_overrides:
return self._plugin_overrides["settings_model"]().model_json_schema()
return self._plugin_overrides["settings_model"].function().model_json_schema()

# default schema (empty)
return PluginSettingsModel.model_json_schema()
Expand All @@ -122,7 +122,7 @@ def settings_schema(self):
def settings_model(self):
# is "settings_model" hook defined in the plugin?
if "settings_model" in self._plugin_overrides:
return self._plugin_overrides["settings_model"]()
return self._plugin_overrides["settings_model"].function()

# default schema (empty)
return PluginSettingsModel
Expand All @@ -131,7 +131,7 @@ def settings_model(self):
def load_settings(self):
# is "settings_load" hook defined in the plugin?
if "load_settings" in self._plugin_overrides:
return self._plugin_overrides["load_settings"]()
return self._plugin_overrides["load_settings"].function()

# by default, plugin settings are saved inside the plugin folder
# in a JSON file called settings.json
Expand All @@ -157,7 +157,7 @@ def load_settings(self):
def save_settings(self, settings: Dict):
# is "settings_save" hook defined in the plugin?
if "save_settings" in self._plugin_overrides:
return self._plugin_overrides["save_settings"](settings)
return self._plugin_overrides["save_settings"].function(settings)

# by default, plugin settings are saved inside the plugin folder
# in a JSON file called settings.json
Expand Down Expand Up @@ -327,7 +327,7 @@ def _load_decorated_functions(self):
self._tools = list(map(self._clean_tool, tools))
self._forms = list(map(self._clean_form, forms))
self._endpoints = list(map(self._clean_endpoint, endpoints))
self._plugin_overrides = {override.name: override for _, override in plugin_overrides}
self._plugin_overrides = {override.name: override for override in list(map(self._clean_plugin_override, plugin_overrides))}


def plugin_specific_error_message(self):
Expand Down

0 comments on commit a75fdc7

Please sign in to comment.