Skip to content

Commit d41daad

Browse files
committed
hints: add configuration in DSSMLTaskSettings
1 parent 5ec8a8e commit d41daad

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

dataikuapi/dss/ml.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,50 @@ def get_algorithm_settings(self, algorithm_name):
253253

254254
return self.mltask_settings["modeling"][algorithm_name.lower()]
255255

256+
def get_hints_settings(self):
257+
"""
258+
Gets the hints settings for a mltask. This returns a reference to the
259+
hints' settings, not a copy, so changes made to the returned object will be reflected when saving.
260+
261+
This method returns a dictionary of the settings with:
262+
- 'enabled': indicates if the hints are enabled globally, if False, all hints will be disabled
263+
- 'settings': a dict comprised of:
264+
- 'type': the hint type
265+
- 'enabled': indicates if the hint type is enabled, if False, all hints of that type will be disabled
266+
267+
Please refer to the documentation for details on available hints.
268+
269+
:return: A dict of hints settings
270+
:rtype: dict
271+
"""
272+
return self.mltask_settings["hintSettings"]
273+
274+
def set_hints_enabled(self, enabled):
275+
"""
276+
Globally enables or disables all hints.
277+
278+
:param bool enabled: if the hints should be enabled or not
279+
"""
280+
settings = self.get_hints_settings()
281+
settings["enabled"] = enabled
282+
283+
def set_hint_type_enabled(self, hint_type, enabled):
284+
"""
285+
Enables or disables a hint based on its type.
286+
287+
Please refer to the documentation for details on available hints.
288+
289+
:param str hint_type: Name (in capitals) of the hint type.
290+
:param bool enabled: if the hint should be enabled or not
291+
"""
292+
settings = self.get_hints_settings()["settings"]
293+
hint = [h for h in settings if h["type"] == hint_type]
294+
if len(hint) == 0:
295+
raise ValueError("hint type {} not found in settings".format(hint_type))
296+
if len(hint) > 1:
297+
raise ValueError("should not happen: multiple hint types {} not found in settings".format(hint_type))
298+
hint[0]["enabled"] = enabled
299+
256300
def set_algorithm_enabled(self, algorithm_name, enabled):
257301
"""
258302
Enables or disables an algorithm based on its name.

0 commit comments

Comments
 (0)