deeppavlov.skills.dsl_skill¶
-
class
deeppavlov.skills.dsl_skill.dsl_skill.
DSLMeta
(name, bases, namespace, **kwargs)[source]¶ This metaclass is used for creating a skill. Skill is register by its class name in registry.
Example:
class ExampleSkill(metaclass=DSLMeta): @DSLMeta.handler(commands=["hello", "hey"]) def __greeting(context: UserContext): response = "Hello, my friend!" confidence = 1.0 return response, confidence
-
name
¶ class name
-
state_to_handler
¶ dict with states as keys and lists of Handler objects as values
-
user_to_context
¶ dict with user ids as keys and UserContext objects as values
-
universal_handlers
¶ list of handlers that can be activated from any state
-
static
handler
(commands: Optional[List[str]] = None, state: Optional[str] = None, context_condition: Optional[Callable] = None, priority: int = 0) → Callable[source]¶ Decorator to be used in skills’ classes. Sample usage:
class ExampleSkill(metaclass=DSLMeta): @DSLMeta.handler(commands=["hello", "hi", "sup", "greetings"]) def __greeting(context: UserContext): response = "Hello, my friend!" confidence = 1.0 return response, confidence
- Parameters
priority – integer value to indicate priority. If multiple handlers satisfy all the requirements, the handler with the greatest priority value will be used
context_condition – function that takes context and returns True if this handler should be enabled and False otherwise. If None, no condition is checked
commands – phrases/regexs on what the function wrapped by this decorator will trigger
state – state name
- Returns
function decorated into Handler class
-