Skip to content

Commit

Permalink
if it quacks like a duck... (#164)
Browse files Browse the repository at this point in the history
* if it quacks like a duck...

isinstancechecks prove to be too restrictive

* restore exception if string does not end in .intent
  • Loading branch information
JarbasAl authored Dec 29, 2023
1 parent 19daf6b commit 40bf410
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,13 +1205,19 @@ def register_intent_layer(self, layer_name: str,
@param intent_list: List of intents associated with the intent layer
"""
for intent_file in intent_list:
if IntentBuilder is not None and isinstance(intent_file, IntentBuilder):
intent = intent_file.build()
name = intent.name
elif Intent is not None and isinstance(intent_file, Intent):
name = intent_file.name
else:
if isinstance(intent_file, str):
name = f'{self.skill_id}:{intent_file}'
else:
if hasattr(intent_file, "build"):
try:
intent_file = intent_file.build()
except:
pass
try:
name = intent_file.name
except:
name = f'{self.skill_id}:{intent_file}'

self.intent_layers.update_layer(layer_name, [name])

def register_intent(self, intent_parser: Union[IntentBuilder, Intent, str],
Expand All @@ -1224,8 +1230,9 @@ def register_intent(self, intent_parser: Union[IntentBuilder, Intent, str],
file to parse utterance for the handler.
handler (func): function to register with intent
"""
if (isinstance(intent_parser, str) and
intent_parser.endswith('.intent')):
if isinstance(intent_parser, str):
if not intent_parser.endswith('.intent'):
raise ValueError
return self.register_intent_file(intent_parser, handler)
return self._register_adapt_intent(intent_parser, handler)

Expand Down Expand Up @@ -1413,10 +1420,11 @@ def _register_adapt_intent(self,
intent_parser: Intent object to parse utterance for the handler.
handler (func): function to register with intent
"""
if isinstance(intent_parser, IntentBuilder):
intent_parser = intent_parser.build()
elif not isinstance(intent_parser, Intent):
raise ValueError('"' + str(intent_parser) + '" is not an Intent')
if hasattr(intent_parser, "build"):
try:
intent_parser = intent_parser.build()
except:
pass

# Default to the handler's function name if none given
is_anonymous = not intent_parser.name
Expand Down

0 comments on commit 40bf410

Please sign in to comment.