class Intent: """ DOCSTRING """ def __init__(self, username=None, password=None, version=None): self.conversation = Conversation(username=username, password=password, version=version) def get_all_intents(self, workspace_id=None, export=False, page_limit=None, include_count=False, sort=None, cursor=None): response = self.conversation.list_intents(workspace_id=workspace_id, export=export, page_limit=page_limit, include_count=include_count, sort=sort, cursor=cursor) print(json.dumps(response, indent=2)) def create_intent(self, workspace_id=None, intent=None, description=None, examples=None): response = self.conversation.create_intent(workspace_id=workspace_id, intent=intent, description=description, examples=examples) print(json.dumps(response, indent=2)) def delete_intent(self, workspace_id=None, intent=None): self.conversation.delete_intent(workspace_id=workspace_id, intent=intent) print("[!]Deleted Intent {}[!]".format(intent)) def get_intent(self, workspace_id, intent, export): response = self.conversation.get_intent(workspace_id=workspace_id, intent=intent, export=export) print(json.dumps(response, indent=2)) def update_intent(self, workspace_id=None, intent=None, new_intent=None, new_description=None, new_examples=None): response = self.conversation.update_intent( workspace_id=workspace_id, intent=intent, new_intent=new_intent, new_description=new_description, new_examples=new_examples) print(json.dumps(response, indent=2))
def _load_intent_data(conversation: ConversationV1 = None, workspace_id: str = None, intent_data: List[dict] = None, config_data: dict = None): """ Add all the intent data to the target workspace parameters: conversation: instance of Conversation from WDC SDK workspace_id: target workspace id intent_data: list of intent dict objects config_data: Dict of configuration options clear_existing: will clear existing examples from target """ clear_existing = config_data['clear_existing'] \ if config_data is not None and \ 'clear_existing' in config_data.keys() else False if intent_data is None: return existing_intents = conversation.list_intents(workspace_id, export=True) for intent in intent_data: # check if there is an existing intent existing = None existing = _get_intent_from_export(intent['intent'], existing_intents) if existing is None: # intent does not exist in target, so free to create conversation.create_intent( workspace_id=workspace_id, intent=intent['intent'], examples=intent['examples'], description=intent['description'] if 'description' in intent.keys() else None) else: if clear_existing: # intent exists in target, but it should be overwritten conversation.update_intent( workspace_id=workspace_id, intent=existing['intent'], new_examples=intent['examples'], new_description=intent['description'] if 'description' in intent.keys() else None) else: # otherwise we need to merge existing = _merge_intents(existing, intent) conversation.update_intent( workspace_id=workspace_id, intent=existing['intent'], new_examples=existing['examples'], new_description=intent['description'] if 'description' in intent.keys() else existing['description'])