def sample_import_documents(): # Create a client client = dialogflow_v2beta1.DocumentsClient() # Initialize request argument(s) gcs_source = dialogflow_v2beta1.GcsSources() gcs_source.uris = ['uris_value_1', 'uris_value_2'] document_template = dialogflow_v2beta1.ImportDocumentTemplate() document_template.mime_type = "mime_type_value" document_template.knowledge_types = "SMART_REPLY" request = dialogflow_v2beta1.ImportDocumentsRequest( gcs_source=gcs_source, parent="parent_value", document_template=document_template, ) # Make the request operation = client.import_documents(request=request) print("Waiting for operation to complete...") response = operation.result() # Handle the response print(response)
def sample_create_document(): # Create a client client = dialogflow_v2beta1.DocumentsClient() # Initialize request argument(s) document = dialogflow_v2beta1.Document() document.content_uri = "content_uri_value" document.display_name = "display_name_value" document.mime_type = "mime_type_value" document.knowledge_types = "SMART_REPLY" request = dialogflow_v2beta1.CreateDocumentRequest( parent="parent_value", document=document, ) # Make the request operation = client.create_document(request=request) print("Waiting for operation to complete...") response = operation.result() # Handle the response print(response)
def sample_get_document(): # Create a client client = dialogflow_v2beta1.DocumentsClient() # Initialize request argument(s) request = dialogflow_v2beta1.GetDocumentRequest(name="name_value", ) # Make the request response = client.get_document(request=request) # Handle the response print(response)
def sample_list_documents(): # Create a client client = dialogflow_v2beta1.DocumentsClient() # Initialize request argument(s) request = dialogflow_v2beta1.ListDocumentsRequest(parent="parent_value", ) # Make the request page_result = client.list_documents(request=request) # Handle the response for response in page_result: print(response)
def sample_delete_document(): # Create a client client = dialogflow_v2beta1.DocumentsClient() # Initialize request argument(s) request = dialogflow_v2beta1.DeleteDocumentRequest(name="name_value", ) # Make the request operation = client.delete_document(request=request) print("Waiting for operation to complete...") response = operation.result() # Handle the response print(response)
def delete_document(project_id, knowledge_base_id, document_id): """Deletes a Document. Args: project_id: The GCP project linked with the agent. knowledge_base_id: Id of the Knowledge base. document_id: Id of the Document.""" from google.cloud import dialogflow_v2beta1 as dialogflow client = dialogflow.DocumentsClient() document_path = client.document_path(project_id, knowledge_base_id, document_id) response = client.delete_document(name=document_path) print('operation running:\n {}'.format(response.operation)) print('Waiting for results...') print('Done.\n {}'.format(response.result()))
def create_document(project_id, knowledge_base_id, display_name, mime_type, knowledge_type, content_uri): """Creates a Document. Args: project_id: The GCP project linked with the agent. knowledge_base_id: Id of the Knowledge base. display_name: The display name of the Document. mime_type: The mime_type of the Document. e.g. text/csv, text/html, text/plain, text/pdf etc. knowledge_type: The Knowledge type of the Document. e.g. FAQ, EXTRACTIVE_QA. content_uri: Uri of the document, e.g. gs://path/mydoc.csv, http://mypage.com/faq.html.""" from google.cloud import dialogflow_v2beta1 as dialogflow client = dialogflow.DocumentsClient() knowledge_base_path = dialogflow.KnowledgeBasesClient.knowledge_base_path( project_id, knowledge_base_id) document = dialogflow.Document(display_name=display_name, mime_type=mime_type, content_uri=content_uri) document.knowledge_types.append( getattr(dialogflow.Document.KnowledgeType, knowledge_type)) response = client.create_document(parent=knowledge_base_path, document=document) print("Waiting for results...") document = response.result(timeout=120) print("Created Document:") print(" - Display Name: {}".format(document.display_name)) print(" - Knowledge ID: {}".format(document.name)) print(" - MIME Type: {}".format(document.mime_type)) print(" - Knowledge Types:") for knowledge_type in document.knowledge_types: print(" - {}".format(KNOWLEDGE_TYPES[knowledge_type])) print(" - Source: {}\n".format(document.content_uri))
def list_documents(project_id, knowledge_base_id): """Lists the Documents belonging to a Knowledge base. Args: project_id: The GCP project linked with the agent. knowledge_base_id: Id of the Knowledge base.""" from google.cloud import dialogflow_v2beta1 as dialogflow client = dialogflow.DocumentsClient() knowledge_base_path = dialogflow.KnowledgeBasesClient.knowledge_base_path( project_id, knowledge_base_id) print('Documents for Knowledge Id: {}'.format(knowledge_base_id)) response = client.list_documents(parent=knowledge_base_path) for document in response: print(' - Display Name: {}'.format(document.display_name)) print(' - Knowledge ID: {}'.format(document.name)) print(' - MIME Type: {}'.format(document.mime_type)) print(' - Knowledge Types:') for knowledge_type in document.knowledge_types: print(' - {}'.format(KNOWLEDGE_TYPES[knowledge_type])) print(' - Source: {}\n'.format(document.content_uri)) return response
def get_document(project_id, knowledge_base_id, document_id): """Gets a Document. Args: project_id: The GCP project linked with the agent. knowledge_base_id: Id of the Knowledge base. document_id: Id of the Document.""" from google.cloud import dialogflow_v2beta1 as dialogflow client = dialogflow.DocumentsClient() document_path = client.document_path(project_id, knowledge_base_id, document_id) response = client.get_document(name=document_path) print('Got Document:') print(' - Display Name: {}'.format(response.display_name)) print(' - Knowledge ID: {}'.format(response.name)) print(' - MIME Type: {}'.format(response.mime_type)) print(' - Knowledge Types:') for knowledge_type in response.knowledge_types: print(' - {}'.format(KNOWLEDGE_TYPES[knowledge_type])) print(' - Source: {}\n'.format(response.content_uri)) return response