diff --git a/samples/snippets/README.rst b/samples/snippets/README.rst index 3d4be7bef..b52a75d7d 100644 --- a/samples/snippets/README.rst +++ b/samples/snippets/README.rst @@ -1,4 +1,3 @@ - .. This file is automatically generated. Do not edit this file directly. Dialogflow Enterprise Edition API Python Samples @@ -16,11 +15,13 @@ This directory contains samples for Dialogflow Enterprise Edition API. The `Dia .. _Dialogflow Enterprise Edition API: https://cloud.google.com/dialogflow-enterprise/docs/ + + + Setup ------------------------------------------------------------------------------- - Authentication ++++++++++++++ @@ -31,9 +32,6 @@ credentials for applications. .. _Authentication Getting Started Guide: https://cloud.google.com/docs/authentication/getting-started - - - Install Dependencies ++++++++++++++++++++ @@ -64,15 +62,9 @@ Install Dependencies .. _pip: https://pip.pypa.io/ .. _virtualenv: https://virtualenv.pypa.io/ - - - - - Samples ------------------------------------------------------------------------------- - Detect Intent Text +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -88,7 +80,6 @@ To run this sample: $ python detect_intent_texts.py - usage: detect_intent_texts.py [-h] --project-id PROJECT_ID [--session-id SESSION_ID] [--language-code LANGUAGE_CODE] @@ -116,8 +107,6 @@ To run this sample: - - Detect Intent Audio +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -133,7 +122,6 @@ To run this sample: $ python detect_intent_audio.py - usage: detect_intent_audio.py [-h] --project-id PROJECT_ID [--session-id SESSION_ID] [--language-code LANGUAGE_CODE] @@ -161,8 +149,6 @@ To run this sample: - - Detect Intent Stream +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -178,7 +164,6 @@ To run this sample: $ python detect_intent_stream.py - usage: detect_intent_stream.py [-h] --project-id PROJECT_ID [--session-id SESSION_ID] [--language-code LANGUAGE_CODE] @@ -206,8 +191,6 @@ To run this sample: - - Detect Intent Knowledge Base +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -223,7 +206,6 @@ To run this sample: $ python detect_intent_knowledge.py - usage: detect_intent_knowledge.py [-h] --project-id PROJECT_ID [--session-id SESSION_ID] [--language-code LANGUAGE_CODE] @@ -253,8 +235,6 @@ To run this sample: - - Detect Intent with Sentiment Analysis +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -270,7 +250,6 @@ To run this sample: $ python detect_intent_with_sentiment_analysis.py - usage: detect_intent_with_sentiment_analysis.py [-h] --project-id PROJECT_ID [--session-id SESSION_ID] [--language-code LANGUAGE_CODE] @@ -297,8 +276,6 @@ To run this sample: - - Detect Intent with Text to Speech Response +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -314,7 +291,6 @@ To run this sample: $ python detect_intent_with_texttospeech_response.py - usage: detect_intent_with_texttospeech_response.py [-h] --project-id PROJECT_ID [--session-id SESSION_ID] @@ -342,8 +318,6 @@ To run this sample: - - Intent Management +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -359,7 +333,6 @@ To run this sample: $ python intent_management.py - usage: intent_management.py [-h] --project-id PROJECT_ID {list,create,delete} ... @@ -385,8 +358,6 @@ To run this sample: - - Knowledge Base Management +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -402,18 +373,24 @@ To run this sample: $ python knowledge_base_management.py - - usage: knowledge_base_management.py [-h] --project-id PROJECT_ID {create} ... + usage: knowledge_base_management.py [-h] --project-id PROJECT_ID + {list,create,get,delete} ... Dialogflow API Python sample showing how to manage Knowledge bases. Examples: python knowledge_base_management.py -h + python knowledge_base_management.py --project-id PROJECT_ID list python knowledge_base_management.py --project-id PROJECT_ID create --display-name DISPLAY_NAME + python knowledge_base_management.py --project-id PROJECT_ID get --knowledge-base-id knowledge_base_id + python knowledge_base_management.py --project-id PROJECT_ID delete --knowledge-base-id knowledge_base_id positional arguments: - {create} + {list,create,get,delete} + list List all Knowledge bases that belong to the project. create Create a new Knowledge base. + get Get a Knowledge base by its id. + delete Delete a Knowledge base by its id. optional arguments: -h, --help show this help message and exit @@ -422,8 +399,6 @@ To run this sample: - - Document Management +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -439,21 +414,26 @@ To run this sample: $ python document_management.py - usage: document_management.py [-h] --project-id PROJECT_ID --knowledge-base-id KNOWLEDGE_BASE_ID - {create} ... + {list,create,get,delete} ... Dialogflow API Python sample showing how to manage Knowledge Documents. Examples: python document_management.py -h + python document_management.py --project-id PROJECT_ID --knowledge-base-id knowledge_base_id list python document_management.py --project-id PROJECT_ID --knowledge-base-id knowledge_base_id create --display-name DISPLAY_NAME --mime-type MIME_TYPE --knowledge-type KNOWLEDGE_TYPE --content-uri CONTENT_URI - python document_management.py --project-id PROJECT_ID --knowledge-base-id knowledge_base_id + python document_management.py --project-id PROJECT_ID --knowledge-base-id knowledge_base_id get --document-id DOCUMENT_ID + python document_management.py --project-id PROJECT_ID --knowledge-base-id knowledge_base_id delete --document-id DOCUMENT_ID positional arguments: - {create} + {list,create,get,delete} + list List all Documents that belong to a certain Knowledge + base. create Create a Document for a certain Knowledge base. + get Get a Document by its id and the Knowledge base id. + delete Delete a Document by its id and the Knowledge baseid. optional arguments: -h, --help show this help message and exit @@ -467,10 +447,6 @@ To run this sample: - - - - The client library ------------------------------------------------------------------------------- @@ -486,5 +462,4 @@ to `browse the source`_ and `report issues`_. https://github.com/GoogleCloudPlatform/google-cloud-python/issues - -.. _Google Cloud SDK: https://cloud.google.com/sdk/ +.. _Google Cloud SDK: https://cloud.google.com/sdk/ \ No newline at end of file diff --git a/samples/snippets/answer_record_management.py b/samples/snippets/answer_record_management.py index dd5690dd6..c1bad0479 100644 --- a/samples/snippets/answer_record_management.py +++ b/samples/snippets/answer_record_management.py @@ -30,19 +30,17 @@ def update_answer_record(project_id, answer_record_id, is_clicked): is_clicked: whether the answer record is clicked.""" client = dialogflow.AnswerRecordsClient() - answer_record_path = client.answer_record_path(project_id, - answer_record_id) + answer_record_path = client.answer_record_path(project_id, answer_record_id) response = client.update_answer_record( answer_record={ - 'name': answer_record_path, - 'answer_feedback': { - 'clicked': is_clicked - } + "name": answer_record_path, + "answer_feedback": {"clicked": is_clicked}, }, - update_mask={'paths': ['answer_feedback']}) - print('AnswerRecord Name: {}'.format(response.name)) - print('Clicked: {}'.format(response.answer_feedback.clicked)) + update_mask={"paths": ["answer_feedback"]}, + ) + print("AnswerRecord Name: {}".format(response.name)) + print("Clicked: {}".format(response.answer_feedback.clicked)) return response diff --git a/samples/snippets/answer_record_management_test.py b/samples/snippets/answer_record_management_test.py index b72b479e7..5008c077d 100644 --- a/samples/snippets/answer_record_management_test.py +++ b/samples/snippets/answer_record_management_test.py @@ -19,10 +19,10 @@ import conversation_profile_management import participant_management -PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT') -SMART_REPLY_MODEL = os.getenv('SMART_REPLY_MODEL') -SMART_REPLY_ALLOWLIST = os.getenv('SMART_REPLY_ALLOWLIST') -CONVERSATION_PROFILE_DISPLAY_NAME = 'sample code profile for smart reply' +PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") +SMART_REPLY_MODEL = os.getenv("SMART_REPLY_MODEL") +SMART_REPLY_ALLOWLIST = os.getenv("SMART_REPLY_ALLOWLIST") +CONVERSATION_PROFILE_DISPLAY_NAME = "sample code profile for smart reply" def test_smart_reply(capsys): @@ -34,64 +34,72 @@ def test_smart_reply(capsys): project_id=PROJECT_ID, display_name=CONVERSATION_PROFILE_DISPLAY_NAME, smart_reply_allowlist_name=SMART_REPLY_ALLOWLIST, - smart_reply_model_name=SMART_REPLY_MODEL) + smart_reply_model_name=SMART_REPLY_MODEL, + ) out, _ = capsys.readouterr() - assert 'Display Name: {}'.format(CONVERSATION_PROFILE_DISPLAY_NAME) in out - conversation_profile_id = out.split('conversationProfiles/')[1].rstrip() + assert "Display Name: {}".format(CONVERSATION_PROFILE_DISPLAY_NAME) in out + conversation_profile_id = out.split("conversationProfiles/")[1].rstrip() # Create conversation. conversation_management.create_conversation( - project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id) + project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id + ) out, _ = capsys.readouterr() - conversation_id = out.split('conversations/')[1].rstrip() + conversation_id = out.split("conversations/")[1].rstrip() # Create end user participant. - participant_management.create_participant(project_id=PROJECT_ID, - conversation_id=conversation_id, - role='END_USER') + participant_management.create_participant( + project_id=PROJECT_ID, conversation_id=conversation_id, role="END_USER" + ) out, _ = capsys.readouterr() - end_user_id = out.split('participants/')[1].rstrip() + end_user_id = out.split("participants/")[1].rstrip() # Create human agent participant. - participant_management.create_participant(project_id=PROJECT_ID, - conversation_id=conversation_id, - role='HUMAN_AGENT') + participant_management.create_participant( + project_id=PROJECT_ID, conversation_id=conversation_id, role="HUMAN_AGENT" + ) out, _ = capsys.readouterr() - human_agent_id = out.split('participants/')[1].rstrip() + human_agent_id = out.split("participants/")[1].rstrip() # AnalyzeContent participant_management.analyze_content_text( project_id=PROJECT_ID, conversation_id=conversation_id, participant_id=human_agent_id, - text='Hi, how are you?') + text="Hi, how are you?", + ) out, _ = capsys.readouterr() - assert 'What would you like to know?' in out + assert "What would you like to know?" in out response = participant_management.analyze_content_text( project_id=PROJECT_ID, conversation_id=conversation_id, participant_id=end_user_id, - text='I am doing well, just want to check') + text="I am doing well, just want to check", + ) out, _ = capsys.readouterr() - assert 'Sounds good.' in out + assert "Sounds good." in out # Update AnswerRecord. - answer_record_id = response.human_agent_suggestion_results[ - 0].suggest_smart_replies_response.smart_reply_answers[ - 0].answer_record.split('answerRecords/')[1].rstrip() + answer_record_id = ( + response.human_agent_suggestion_results[0] + .suggest_smart_replies_response.smart_reply_answers[0] + .answer_record.split("answerRecords/")[1] + .rstrip() + ) answer_record_management.update_answer_record( - project_id=PROJECT_ID, - answer_record_id=answer_record_id, - is_clicked=True) + project_id=PROJECT_ID, answer_record_id=answer_record_id, is_clicked=True + ) out, _ = capsys.readouterr() - assert 'Clicked: True' in out + assert "Clicked: True" in out # Complete conversation. conversation_management.complete_conversation( - project_id=PROJECT_ID, conversation_id=conversation_id) + project_id=PROJECT_ID, conversation_id=conversation_id + ) # Delete conversation profile. conversation_profile_management.delete_conversation_profile( - project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id) + project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id + ) diff --git a/samples/snippets/conversation_management.py b/samples/snippets/conversation_management.py index e6c734929..d85feea3a 100644 --- a/samples/snippets/conversation_management.py +++ b/samples/snippets/conversation_management.py @@ -31,17 +31,17 @@ def create_conversation(project_id, conversation_profile_id): client = dialogflow.ConversationsClient() conversation_profile_client = dialogflow.ConversationProfilesClient() project_path = client.common_project_path(project_id) - conversation_profile_path = ( - conversation_profile_client.conversation_profile_path( - project_id, conversation_profile_id)) - conversation = {'conversation_profile': conversation_profile_path} - response = client.create_conversation(parent=project_path, - conversation=conversation) - - print('Life Cycle State: {}'.format(response.lifecycle_state)) - print('Conversation Profile Name: {}'.format( - response.conversation_profile)) - print('Name: {}'.format(response.name)) + conversation_profile_path = conversation_profile_client.conversation_profile_path( + project_id, conversation_profile_id + ) + conversation = {"conversation_profile": conversation_profile_path} + response = client.create_conversation( + parent=project_path, conversation=conversation + ) + + print("Life Cycle State: {}".format(response.lifecycle_state)) + print("Conversation Profile Name: {}".format(response.conversation_profile)) + print("Name: {}".format(response.name)) return response @@ -61,10 +61,9 @@ def get_conversation(project_id, conversation_id): response = client.get_conversation(name=conversation_path) - print('Life Cycle State: {}'.format(response.lifecycle_state)) - print('Conversation Profile Name: {}'.format( - response.conversation_profile)) - print('Name: {}'.format(response.name)) + print("Life Cycle State: {}".format(response.lifecycle_state)) + print("Conversation Profile Name: {}".format(response.conversation_profile)) + print("Name: {}".format(response.name)) return response @@ -82,11 +81,10 @@ def complete_conversation(project_id, conversation_id): client = dialogflow.ConversationsClient() conversation_path = client.conversation_path(project_id, conversation_id) conversation = client.complete_conversation(name=conversation_path) - print('Completed Conversation.') - print('Life Cycle State: {}'.format(conversation.lifecycle_state)) - print('Conversation Profile Name: {}'.format( - conversation.conversation_profile)) - print('Name: {}'.format(conversation.name)) + print("Completed Conversation.") + print("Life Cycle State: {}".format(conversation.lifecycle_state)) + print("Conversation Profile Name: {}".format(conversation.conversation_profile)) + print("Name: {}".format(conversation.name)) return conversation diff --git a/samples/snippets/conversation_profile_management.py b/samples/snippets/conversation_profile_management.py index 22ae1d384..1316ceab1 100644 --- a/samples/snippets/conversation_profile_management.py +++ b/samples/snippets/conversation_profile_management.py @@ -29,8 +29,8 @@ def list_conversation_profiles(project_id): project_path = client.common_project_path(project_id) response = client.list_conversation_profiles(parent=project_path) for conversation_profile in response: - print('Display Name: {}'.format(conversation_profile.display_name)) - print('Name: {}'.format(conversation_profile.name)) + print("Display Name: {}".format(conversation_profile.display_name)) + print("Name: {}".format(conversation_profile.name)) return response @@ -39,10 +39,11 @@ def list_conversation_profiles(project_id): # [START dialogflow_create_conversation_profile_article_faq] def create_conversation_profile_article_faq( - project_id, - display_name, - article_suggestion_knowledge_base_id=None, - faq_knowledge_base_id=None): + project_id, + display_name, + article_suggestion_knowledge_base_id=None, + faq_knowledge_base_id=None, +): """Creates a conversation profile with given values Args: project_id: The GCP project linked with the conversation profile. @@ -56,65 +57,58 @@ def create_conversation_profile_article_faq( project_path = client.common_project_path(project_id) conversation_profile = { - 'display_name': display_name, - 'human_agent_assistant_config': { - 'human_agent_suggestion_config': { - 'feature_configs': [] - } + "display_name": display_name, + "human_agent_assistant_config": { + "human_agent_suggestion_config": {"feature_configs": []} }, - 'language_code': 'en-US' + "language_code": "en-US", } if article_suggestion_knowledge_base_id is not None: as_kb_path = dialogflow.KnowledgeBasesClient.knowledge_base_path( - project_id, article_suggestion_knowledge_base_id) + project_id, article_suggestion_knowledge_base_id + ) feature_config = { - 'suggestion_feature': { - 'type_': 'ARTICLE_SUGGESTION' + "suggestion_feature": {"type_": "ARTICLE_SUGGESTION"}, + "suggestion_trigger_settings": { + "no_small_talk": True, + "only_end_user": True, }, - 'suggestion_trigger_settings': { - 'no_small_talk': True, - 'only_end_user': True, - }, - 'query_config': { - 'knowledge_base_query_source': { - 'knowledge_bases': [as_kb_path] - }, - 'max_results': 3 + "query_config": { + "knowledge_base_query_source": {"knowledge_bases": [as_kb_path]}, + "max_results": 3, }, } - conversation_profile['human_agent_assistant_config'][ - 'human_agent_suggestion_config']['feature_configs'].append( - feature_config) + conversation_profile["human_agent_assistant_config"][ + "human_agent_suggestion_config" + ]["feature_configs"].append(feature_config) if faq_knowledge_base_id is not None: faq_kb_path = dialogflow.KnowledgeBasesClient.knowledge_base_path( - project_id, faq_knowledge_base_id) + project_id, faq_knowledge_base_id + ) feature_config = { - 'suggestion_feature': { - 'type_': 'FAQ' - }, - 'suggestion_trigger_settings': { - 'no_small_talk': True, - 'only_end_user': True, + "suggestion_feature": {"type_": "FAQ"}, + "suggestion_trigger_settings": { + "no_small_talk": True, + "only_end_user": True, }, - 'query_config': { - 'knowledge_base_query_source': { - 'knowledge_bases': [faq_kb_path] - }, - 'max_results': 3 + "query_config": { + "knowledge_base_query_source": {"knowledge_bases": [faq_kb_path]}, + "max_results": 3, }, } - conversation_profile['human_agent_assistant_config'][ - 'human_agent_suggestion_config']['feature_configs'].append( - feature_config) + conversation_profile["human_agent_assistant_config"][ + "human_agent_suggestion_config" + ]["feature_configs"].append(feature_config) response = client.create_conversation_profile( - parent=project_path, conversation_profile=conversation_profile) + parent=project_path, conversation_profile=conversation_profile + ) - print('Conversation Profile created:') - print('Display Name: {}'.format(response.display_name)) + print("Conversation Profile created:") + print("Display Name: {}".format(response.display_name)) # Put Name is the last to make it easier to retrieve. - print('Name: {}'.format(response.name)) + print("Name: {}".format(response.name)) return response @@ -122,9 +116,9 @@ def create_conversation_profile_article_faq( # [START dialogflow_create_conversation_profile_smart_reply] -def create_conversation_profile_smart_reply(project_id, display_name, - smart_reply_allowlist_name, - smart_reply_model_name): +def create_conversation_profile_smart_reply( + project_id, display_name, smart_reply_allowlist_name, smart_reply_model_name +): """Creates a conversation profile with given values for smart reply Args: project_id: The GCP project linked with the conversation profile. @@ -137,43 +131,33 @@ def create_conversation_profile_smart_reply(project_id, display_name, project_path = client.common_project_path(project_id) conversation_profile = { - 'display_name': display_name, - 'human_agent_assistant_config': { - 'human_agent_suggestion_config': { - 'feature_configs': [] - } + "display_name": display_name, + "human_agent_assistant_config": { + "human_agent_suggestion_config": {"feature_configs": []} }, - 'language_code': 'en-US' + "language_code": "en-US", } feature_config = { - 'suggestion_feature': { - 'type_': 'SMART_REPLY' - }, - 'suggestion_trigger_settings': { - 'no_small_talk': True, - 'only_end_user': True, + "suggestion_feature": {"type_": "SMART_REPLY"}, + "suggestion_trigger_settings": {"no_small_talk": True, "only_end_user": True, }, + "query_config": { + "document_query_source": {"documents": [smart_reply_allowlist_name]}, + "max_results": 3, }, - 'query_config': { - 'document_query_source': { - 'documents': [smart_reply_allowlist_name] - }, - 'max_results': 3 - }, - 'conversation_model_config': { - 'model': smart_reply_model_name - } + "conversation_model_config": {"model": smart_reply_model_name}, } - conversation_profile['human_agent_assistant_config'][ - 'human_agent_suggestion_config']['feature_configs'].append( - feature_config) + conversation_profile["human_agent_assistant_config"][ + "human_agent_suggestion_config" + ]["feature_configs"].append(feature_config) response = client.create_conversation_profile( - parent=project_path, conversation_profile=conversation_profile) + parent=project_path, conversation_profile=conversation_profile + ) - print('Conversation Profile created:') - print('Display Name: {}'.format(response.display_name)) + print("Conversation Profile created:") + print("Display Name: {}".format(response.display_name)) # Put Name is the last to make it easier to retrieve. - print('Name: {}'.format(response.name)) + print("Name: {}".format(response.name)) return response @@ -189,13 +173,14 @@ def get_conversation_profile(project_id, conversation_profile_id): client = dialogflow.ConversationProfilesClient() conversation_profile_path = client.conversation_profile_path( - project_id, conversation_profile_id) + project_id, conversation_profile_id + ) response = client.get_conversation_profile(name=conversation_profile_path) - print('Got conversation profile:') - print('Display Name: {}'.format(response.display_name)) - print('Name: {}'.format(response.name)) + print("Got conversation profile:") + print("Display Name: {}".format(response.display_name)) + print("Name: {}".format(response.name)) return response @@ -211,11 +196,12 @@ def delete_conversation_profile(project_id, conversation_profile_id): client = dialogflow.ConversationProfilesClient() conversation_profile_path = client.conversation_profile_path( - project_id, conversation_profile_id) + project_id, conversation_profile_id + ) client.delete_conversation_profile(name=conversation_profile_path) - print('Conversation Profile deleted.') + print("Conversation Profile deleted.") # [END dialogflow_delete_conversation_profile] diff --git a/samples/snippets/conversation_profile_management_test.py b/samples/snippets/conversation_profile_management_test.py index 4ecb6bbb7..fb250897f 100644 --- a/samples/snippets/conversation_profile_management_test.py +++ b/samples/snippets/conversation_profile_management_test.py @@ -18,9 +18,9 @@ import conversation_profile_management -PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT') +PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") -CONVERSATION_PROFILE_DISPLAY_NAME = 'fake_conversation_profile_name' +CONVERSATION_PROFILE_DISPLAY_NAME = "fake_conversation_profile_name" def test_create_conversation_profile(capsys): @@ -28,40 +28,40 @@ def test_create_conversation_profile(capsys): conversation_profile_management.list_conversation_profiles(PROJECT_ID) out, _ = capsys.readouterr() - assert 'Display Name: {}'.format( - CONVERSATION_PROFILE_DISPLAY_NAME) not in out + assert "Display Name: {}".format(CONVERSATION_PROFILE_DISPLAY_NAME) not in out # Create a conversation profile. conversation_profile_management.create_conversation_profile_article_faq( - project_id=PROJECT_ID, display_name=CONVERSATION_PROFILE_DISPLAY_NAME, - article_suggestion_knowledge_base_id='abc') + project_id=PROJECT_ID, + display_name=CONVERSATION_PROFILE_DISPLAY_NAME, + article_suggestion_knowledge_base_id="abc", + ) out, _ = capsys.readouterr() - assert 'Display Name: {}'.format( - CONVERSATION_PROFILE_DISPLAY_NAME) in out + assert "Display Name: {}".format(CONVERSATION_PROFILE_DISPLAY_NAME) in out - conversation_profile_id = out.split('conversationProfiles/')[1].rstrip() + conversation_profile_id = out.split("conversationProfiles/")[1].rstrip() # List conversation profiles. conversation_profile_management.list_conversation_profiles(PROJECT_ID) out, _ = capsys.readouterr() - assert 'Display Name: {}'.format( - CONVERSATION_PROFILE_DISPLAY_NAME) in out + assert "Display Name: {}".format(CONVERSATION_PROFILE_DISPLAY_NAME) in out # Get the conversation profile. conversation_profile_management.get_conversation_profile( - PROJECT_ID, conversation_profile_id) + PROJECT_ID, conversation_profile_id + ) out, _ = capsys.readouterr() - assert 'Display Name: {}'.format(CONVERSATION_PROFILE_DISPLAY_NAME) in out + assert "Display Name: {}".format(CONVERSATION_PROFILE_DISPLAY_NAME) in out # Delete the conversation profile. conversation_profile_management.delete_conversation_profile( - PROJECT_ID, conversation_profile_id) + PROJECT_ID, conversation_profile_id + ) # Verify the conversation profile is deleted. conversation_profile_management.list_conversation_profiles(PROJECT_ID) out, _ = capsys.readouterr() - assert 'Display Name: {}'.format( - CONVERSATION_PROFILE_DISPLAY_NAME) not in out + assert "Display Name: {}".format(CONVERSATION_PROFILE_DISPLAY_NAME) not in out diff --git a/samples/snippets/create_document_test.py b/samples/snippets/create_document_test.py index b65e577aa..db4c4ea9c 100644 --- a/samples/snippets/create_document_test.py +++ b/samples/snippets/create_document_test.py @@ -35,18 +35,20 @@ def setup_teardown(): client = dialogflow.KnowledgeBasesClient() project_path = client.common_project_path(PROJECT_ID) knowledge_base = dialogflow.KnowledgeBase(display_name=KNOWLEDGE_BASE_NAME) - response = client.create_knowledge_base(parent=project_path, - knowledge_base=knowledge_base) - pytest.KNOWLEDGE_BASE_ID = response.name.split( - "/knowledgeBases/")[1].split("\n")[0] + response = client.create_knowledge_base( + parent=project_path, knowledge_base=knowledge_base + ) + pytest.KNOWLEDGE_BASE_ID = response.name.split("/knowledgeBases/")[1].split("\n")[0] yield # Delete the created knowledge base - knowledge_base_path = client.knowledge_base_path(PROJECT_ID, - pytest.KNOWLEDGE_BASE_ID) - request = dialogflow.DeleteKnowledgeBaseRequest(name=knowledge_base_path, - force=True) + knowledge_base_path = client.knowledge_base_path( + PROJECT_ID, pytest.KNOWLEDGE_BASE_ID + ) + request = dialogflow.DeleteKnowledgeBaseRequest( + name=knowledge_base_path, force=True + ) client.delete_knowledge_base(request=request) diff --git a/samples/snippets/detect_intent_audio.py b/samples/snippets/detect_intent_audio.py index 6c3981687..e0cbd78fc 100644 --- a/samples/snippets/detect_intent_audio.py +++ b/samples/snippets/detect_intent_audio.py @@ -58,9 +58,7 @@ def detect_intent_audio(project_id, session_id, audio_file_path, language_code): query_input = dialogflow.QueryInput(audio_config=audio_config) request = dialogflow.DetectIntentRequest( - session=session, - query_input=query_input, - input_audio=input_audio, + session=session, query_input=query_input, input_audio=input_audio, ) response = session_client.detect_intent(request=request) diff --git a/samples/snippets/document_management.py b/samples/snippets/document_management.py index b08ddf752..8957ee034 100644 --- a/samples/snippets/document_management.py +++ b/samples/snippets/document_management.py @@ -36,7 +36,12 @@ import argparse -KNOWLEDGE_TYPES = ['KNOWLEDGE_TYPE_UNSPECIFIED', 'FAQ', 'EXTRACTIVE_QA', 'ARTICLE_SUGGESTION'] +KNOWLEDGE_TYPES = [ + "KNOWLEDGE_TYPE_UNSPECIFIED", + "FAQ", + "EXTRACTIVE_QA", + "ARTICLE_SUGGESTION", +] # [START dialogflow_list_document] @@ -47,27 +52,32 @@ def list_documents(project_id, knowledge_base_id): 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) + project_id, knowledge_base_id + ) - print('Documents for Knowledge Id: {}'.format(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:') + 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)) + print(" - {}".format(KNOWLEDGE_TYPES[knowledge_type])) + print(" - Source: {}\n".format(document.content_uri)) return response + + # [END dialogflow_list_document] # [START dialogflow_create_document]] -def create_document(project_id, knowledge_base_id, display_name, mime_type, - knowledge_type, content_uri): +def create_document( + project_id, knowledge_base_id, display_name, mime_type, knowledge_type, content_uri +): """Creates a Document. Args: @@ -81,29 +91,33 @@ def create_document(project_id, knowledge_base_id, display_name, mime_type, 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) + project_id, knowledge_base_id + ) document = dialogflow.Document( - display_name=display_name, mime_type=mime_type, - content_uri=content_uri) + 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...') + 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:') + 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)) + print(" - {}".format(KNOWLEDGE_TYPES[knowledge_type])) + print(" - Source: {}\n".format(document.content_uri)) + + # [END dialogflow_create_document] @@ -116,20 +130,22 @@ def get_document(project_id, knowledge_base_id, document_id): 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) + 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:') + 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)) + print(" - {}".format(KNOWLEDGE_TYPES[knowledge_type])) + print(" - Source: {}\n".format(response.content_uri)) return response + + # [END dialogflow_get_document]] @@ -142,79 +158,91 @@ def delete_document(project_id, knowledge_base_id, document_id): 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) + 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())) + print("operation running:\n {}".format(response.operation)) + print("Waiting for results...") + print("Done.\n {}".format(response.result())) + + # [END dialogflow_delete_document]] -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument( - '--project-id', help='Project id. Required.', required=True) + description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter + ) + parser.add_argument("--project-id", help="Project id. Required.", required=True) parser.add_argument( - '--knowledge-base-id', - help='The id of the Knowledge Base that the Document belongs to', - required=True) + "--knowledge-base-id", + help="The id of the Knowledge Base that the Document belongs to", + required=True, + ) - subparsers = parser.add_subparsers(dest='command') + subparsers = parser.add_subparsers(dest="command") list_parser = subparsers.add_parser( - 'list', - help='List all Documents that belong to a certain Knowledge base.') + "list", help="List all Documents that belong to a certain Knowledge base." + ) create_parser = subparsers.add_parser( - 'create', help='Create a Document for a certain Knowledge base.') + "create", help="Create a Document for a certain Knowledge base." + ) create_parser.add_argument( - '--display-name', - help='A name of the Document, mainly used for display purpose, ' - 'can not be used to identify the Document.', - default=str('')) + "--display-name", + help="A name of the Document, mainly used for display purpose, " + "can not be used to identify the Document.", + default=str(""), + ) create_parser.add_argument( - '--mime-type', - help='The mime-type of the Document, e.g. text/csv, text/html, ' - 'text/plain, text/pdf etc. ', - required=True) + "--mime-type", + help="The mime-type of the Document, e.g. text/csv, text/html, " + "text/plain, text/pdf etc. ", + required=True, + ) create_parser.add_argument( - '--knowledge-type', - help='The knowledge-type of the Document, e.g. FAQ, EXTRACTIVE_QA.', - required=True) + "--knowledge-type", + help="The knowledge-type of the Document, e.g. FAQ, EXTRACTIVE_QA.", + required=True, + ) create_parser.add_argument( - '--content-uri', - help='The uri of the Document, e.g. gs://path/mydoc.csv, ' - 'http://mypage.com/faq.html', - required=True) + "--content-uri", + help="The uri of the Document, e.g. gs://path/mydoc.csv, " + "http://mypage.com/faq.html", + required=True, + ) get_parser = subparsers.add_parser( - 'get', help='Get a Document by its id and the Knowledge base id.') + "get", help="Get a Document by its id and the Knowledge base id." + ) get_parser.add_argument( - '--document-id', help='The id of the Document', required=True) + "--document-id", help="The id of the Document", required=True + ) delete_parser = subparsers.add_parser( - 'delete', help='Delete a Document by its id and the Knowledge base' - 'id.') + "delete", help="Delete a Document by its id and the Knowledge base" "id." + ) delete_parser.add_argument( - '--document-id', - help='The id of the Document you want to delete', - required=True) + "--document-id", help="The id of the Document you want to delete", required=True + ) args = parser.parse_args() - if args.command == 'list': + if args.command == "list": list_documents(args.project_id, args.knowledge_base_id) - elif args.command == 'create': - create_document(args.project_id, args.knowledge_base_id, - args.display_name, args.mime_type, args.knowledge_type, - args.content_uri) - elif args.command == 'get': + elif args.command == "create": + create_document( + args.project_id, + args.knowledge_base_id, + args.display_name, + args.mime_type, + args.knowledge_type, + args.content_uri, + ) + elif args.command == "get": get_document(args.project_id, args.knowledge_base_id, args.document_id) - elif args.command == 'delete': - delete_document(args.project_id, args.knowledge_base_id, - args.document_id) + elif args.command == "delete": + delete_document(args.project_id, args.knowledge_base_id, args.document_id) diff --git a/samples/snippets/knowledge_base_management.py b/samples/snippets/knowledge_base_management.py index d33044456..5bd71d46d 100644 --- a/samples/snippets/knowledge_base_management.py +++ b/samples/snippets/knowledge_base_management.py @@ -39,20 +39,21 @@ def create_knowledge_base(project_id, display_name): project_id: The GCP project linked with the agent. display_name: The display name of the Knowledge base.""" from google.cloud import dialogflow_v2beta1 as dialogflow + client = dialogflow.KnowledgeBasesClient() project_path = client.common_project_path(project_id) - knowledge_base = dialogflow.KnowledgeBase( - display_name=display_name) + knowledge_base = dialogflow.KnowledgeBase(display_name=display_name) response = client.create_knowledge_base( - parent=project_path, - knowledge_base=knowledge_base + parent=project_path, knowledge_base=knowledge_base ) - print('Knowledge Base created:\n') - print('Display Name: {}\n'.format(response.display_name)) - print('Knowledge ID: {}\n'.format(response.name)) + print("Knowledge Base created:\n") + print("Display Name: {}\n".format(response.display_name)) + print("Knowledge ID: {}\n".format(response.name)) + + # [END dialogflow_create_knowledge_base] @@ -64,16 +65,18 @@ def get_knowledge_base(project_id, knowledge_base_id): 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.KnowledgeBasesClient() - knowledge_base_path = client.knowledge_base_path( - project_id, knowledge_base_id) + knowledge_base_path = client.knowledge_base_path(project_id, knowledge_base_id) response = client.get_knowledge_base(name=knowledge_base_path) - print('Got Knowledge Base:') - print(' - Display Name: {}'.format(response.display_name)) - print(' - Knowledge ID: {}'.format(response.name)) + print("Got Knowledge Base:") + print(" - Display Name: {}".format(response.display_name)) + print(" - Knowledge ID: {}".format(response.name)) return response + + # [END dialogflow_get_knowledge_base] @@ -85,54 +88,57 @@ def delete_knowledge_base(project_id, knowledge_base_id): 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.KnowledgeBasesClient() - knowledge_base_path = client.knowledge_base_path( - project_id, knowledge_base_id) + knowledge_base_path = client.knowledge_base_path(project_id, knowledge_base_id) client.delete_knowledge_base(name=knowledge_base_path) - print('Knowledge Base deleted.') + print("Knowledge Base deleted.") + + # [END dialogflow_delete_knowledge_base] -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument( - '--project-id', help='Project/agent id.', required=True) + description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter + ) + parser.add_argument("--project-id", help="Project/agent id.", required=True) - subparsers = parser.add_subparsers(dest='command') + subparsers = parser.add_subparsers(dest="command") list_parser = subparsers.add_parser( - 'list', help='List all Knowledge bases that belong to the project.') + "list", help="List all Knowledge bases that belong to the project." + ) - create_parser = subparsers.add_parser( - 'create', help='Create a new Knowledge base.') + create_parser = subparsers.add_parser("create", help="Create a new Knowledge base.") create_parser.add_argument( - '--display-name', - help='A name of the Knowledge base, used for display purpose, ' - 'can not be used to identify the Knowledge base.', - default=str('')) + "--display-name", + help="A name of the Knowledge base, used for display purpose, " + "can not be used to identify the Knowledge base.", + default=str(""), + ) - get_parser = subparsers.add_parser( - 'get', help='Get a Knowledge base by its id.') + get_parser = subparsers.add_parser("get", help="Get a Knowledge base by its id.") get_parser.add_argument( - '--knowledge-base-id', help='The id of the Knowledge base.', - required=True) + "--knowledge-base-id", help="The id of the Knowledge base.", required=True + ) delete_parser = subparsers.add_parser( - 'delete', help='Delete a Knowledge base by its id.') + "delete", help="Delete a Knowledge base by its id." + ) delete_parser.add_argument( - '--knowledge-base-id', - help='The id of the Knowledge base you want to delete.', - required=True) + "--knowledge-base-id", + help="The id of the Knowledge base you want to delete.", + required=True, + ) args = parser.parse_args() - if args.command == 'create': + if args.command == "create": create_knowledge_base(args.project_id, args.display_name) - elif args.command == 'get': + elif args.command == "get": get_knowledge_base(args.project_id, args.knowledge_base_id) - elif args.command == 'delete': + elif args.command == "delete": delete_knowledge_base(args.project_id, args.knowledge_base_id) diff --git a/samples/snippets/list_training_phrases.py b/samples/snippets/list_training_phrases.py new file mode 100644 index 000000000..7ce4e8201 --- /dev/null +++ b/samples/snippets/list_training_phrases.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Dialogflow API Python sample showing how to list Training Phrases for a specified Intent. +""" + +# [START dialogflow_list_training_phrases] + + +def list_training_phrases(project_id, intent_id): + """Returns all training phrases for a specified intent.""" + + from google.cloud import dialogflow + + # Create the intents client + intent_client = dialogflow.IntentsClient() + + # Specify working intent + intent_name = f"projects/{project_id}/agent/intents/{intent_id}" + + # The options for views of an intent + intent_view = dialogflow.IntentView.INTENT_VIEW_FULL + + # Compose the get-intent request + get_intent_request = dialogflow.GetIntentRequest( + name=intent_name, intent_view=intent_view + ) + + intent = intent_client.get_intent(get_intent_request) + + # Iterate through the training phrases. + for phrase in intent.training_phrases: + print(phrase) + + return intent.training_phrases + + +# [END dialogflow_list_training_phrases] diff --git a/samples/snippets/list_training_phrases_test.py b/samples/snippets/list_training_phrases_test.py new file mode 100644 index 000000000..871a94fc6 --- /dev/null +++ b/samples/snippets/list_training_phrases_test.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import google.auth + +import list_training_phrases + + +_, PROJECT_ID = google.auth.default() +INTENT_ID = "7b5bd47e-6dd9-4b45-8624-565862bd2d85" + + +def test_list_training_phrases(capsys): + training_phrases = list_training_phrases.list_training_phrases( + PROJECT_ID, INTENT_ID, + ) + assert len(training_phrases) >= 9 # Number of training phrases at this point. diff --git a/samples/snippets/participant_management_test.py b/samples/snippets/participant_management_test.py index f26c9376c..fc2754790 100644 --- a/samples/snippets/participant_management_test.py +++ b/samples/snippets/participant_management_test.py @@ -20,10 +20,10 @@ import knowledge_base_management import participant_management -PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT') -KNOWLEDGE_BASE_DISPLAY_NAME = 'fake_KNOWLEDGE_BASE_DISPLAY_NAME' -DOCUMENT_DISPLAY_NAME = 'Cancel an order' -CONVERSATION_PROFILE_DISPLAY_NAME = 'fake_conversation_profile' +PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") +KNOWLEDGE_BASE_DISPLAY_NAME = "fake_KNOWLEDGE_BASE_DISPLAY_NAME" +DOCUMENT_DISPLAY_NAME = "Cancel an order" +CONVERSATION_PROFILE_DISPLAY_NAME = "fake_conversation_profile" def test_analyze_content_text(capsys): @@ -31,97 +31,108 @@ def test_analyze_content_text(capsys): """ # Create knowledge base. knowledge_base_management.create_knowledge_base( - PROJECT_ID, KNOWLEDGE_BASE_DISPLAY_NAME) + PROJECT_ID, KNOWLEDGE_BASE_DISPLAY_NAME + ) out, _ = capsys.readouterr() - knowledge_base_id = out.split('knowledgeBases/')[1].rstrip() + knowledge_base_id = out.split("knowledgeBases/")[1].rstrip() # Get the knowledge base knowledge_base_management.get_knowledge_base(PROJECT_ID, knowledge_base_id) out, _ = capsys.readouterr() - assert 'Display Name: {}'.format(KNOWLEDGE_BASE_DISPLAY_NAME) in out + assert "Display Name: {}".format(KNOWLEDGE_BASE_DISPLAY_NAME) in out # Create documents. Note that you should get read permission of bucket gs://cloud-samples-data/dialogflow/participant_test.html # via Pantheon for service account (google application credential account) from here: # https://support.google.com/googleshopping/answer/9116497 - document_management.create_document(PROJECT_ID, knowledge_base_id, - DOCUMENT_DISPLAY_NAME, 'text/html', - 'ARTICLE_SUGGESTION', - 'gs://cloud-samples-data/dialogflow/participant_test.html') + document_management.create_document( + PROJECT_ID, + knowledge_base_id, + DOCUMENT_DISPLAY_NAME, + "text/html", + "ARTICLE_SUGGESTION", + "gs://cloud-samples-data/dialogflow/participant_test.html", + ) out, _ = capsys.readouterr() - document_id = out.split('documents/')[1].split(' - MIME Type:')[0].rstrip() + document_id = out.split("documents/")[1].split(" - MIME Type:")[0].rstrip() # Get the Document - document_management.get_document(PROJECT_ID, knowledge_base_id, - document_id) + document_management.get_document(PROJECT_ID, knowledge_base_id, document_id) out, _ = capsys.readouterr() - assert 'Display Name: {}'.format(DOCUMENT_DISPLAY_NAME) in out + assert "Display Name: {}".format(DOCUMENT_DISPLAY_NAME) in out # Create conversation profile. conversation_profile_management.create_conversation_profile_article_faq( project_id=PROJECT_ID, display_name=CONVERSATION_PROFILE_DISPLAY_NAME, - article_suggestion_knowledge_base_id=knowledge_base_id) + article_suggestion_knowledge_base_id=knowledge_base_id, + ) out, _ = capsys.readouterr() - assert 'Display Name: {}'.format(CONVERSATION_PROFILE_DISPLAY_NAME) in out - conversation_profile_id = out.split('conversationProfiles/')[1].rstrip() + assert "Display Name: {}".format(CONVERSATION_PROFILE_DISPLAY_NAME) in out + conversation_profile_id = out.split("conversationProfiles/")[1].rstrip() # Create conversation. conversation_management.create_conversation( - project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id) + project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id + ) out, _ = capsys.readouterr() - conversation_id = out.split('conversations/')[1].rstrip() + conversation_id = out.split("conversations/")[1].rstrip() # Create end user participant. - participant_management.create_participant(project_id=PROJECT_ID, - conversation_id=conversation_id, - role='END_USER') + participant_management.create_participant( + project_id=PROJECT_ID, conversation_id=conversation_id, role="END_USER" + ) out, _ = capsys.readouterr() - end_user_id = out.split('participants/')[1].rstrip() + end_user_id = out.split("participants/")[1].rstrip() # Create human agent participant. - participant_management.create_participant(project_id=PROJECT_ID, - conversation_id=conversation_id, - role='HUMAN_AGENT') + participant_management.create_participant( + project_id=PROJECT_ID, conversation_id=conversation_id, role="HUMAN_AGENT" + ) out, _ = capsys.readouterr() - human_agent_id = out.split('participants/')[1].rstrip() + human_agent_id = out.split("participants/")[1].rstrip() # AnalyzeContent participant_management.analyze_content_text( project_id=PROJECT_ID, conversation_id=conversation_id, participant_id=human_agent_id, - text='Hi, how are you?') + text="Hi, how are you?", + ) out, _ = capsys.readouterr() participant_management.analyze_content_text( project_id=PROJECT_ID, conversation_id=conversation_id, participant_id=end_user_id, - text='Hi, I am doing well, how about you?') + text="Hi, I am doing well, how about you?", + ) out, _ = capsys.readouterr() participant_management.analyze_content_text( project_id=PROJECT_ID, conversation_id=conversation_id, participant_id=human_agent_id, - text='Great. How can I help you?') + text="Great. How can I help you?", + ) out, _ = capsys.readouterr() participant_management.analyze_content_text( project_id=PROJECT_ID, conversation_id=conversation_id, participant_id=end_user_id, - text='So I ordered something, but I do not like it.') + text="So I ordered something, but I do not like it.", + ) out, _ = capsys.readouterr() participant_management.analyze_content_text( project_id=PROJECT_ID, conversation_id=conversation_id, participant_id=end_user_id, - text='Thinking if I can cancel that order') + text="Thinking if I can cancel that order", + ) suggestion_out, _ = capsys.readouterr() # Currently suggestion_out won't contain the suggestion we want since it # takes time for document to be ready to serve. @@ -129,16 +140,16 @@ def test_analyze_content_text(capsys): # Complete conversation. conversation_management.complete_conversation( - project_id=PROJECT_ID, conversation_id=conversation_id) + project_id=PROJECT_ID, conversation_id=conversation_id + ) # Delete conversation profile. conversation_profile_management.delete_conversation_profile( - project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id) + project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id + ) # Delete document. - document_management.delete_document(PROJECT_ID, knowledge_base_id, - document_id) + document_management.delete_document(PROJECT_ID, knowledge_base_id, document_id) # Delete the Knowledge Base. - knowledge_base_management.delete_knowledge_base(PROJECT_ID, - knowledge_base_id) + knowledge_base_management.delete_knowledge_base(PROJECT_ID, knowledge_base_id) diff --git a/samples/snippets/update_intent.py b/samples/snippets/update_intent.py index 5c9e0692a..796ce8d1a 100644 --- a/samples/snippets/update_intent.py +++ b/samples/snippets/update_intent.py @@ -28,4 +28,6 @@ def update_intent(project_id, intent_id, display_name): update_mask = field_mask_pb2.FieldMask(paths=["display_name"]) response = intents_client.update_intent(intent=intent, update_mask=update_mask) return response + + # [END dialogflow_es_update_intent] diff --git a/samples/snippets/update_intent_test.py b/samples/snippets/update_intent_test.py index 1feb298f4..432c0531f 100644 --- a/samples/snippets/update_intent_test.py +++ b/samples/snippets/update_intent_test.py @@ -36,7 +36,7 @@ def create_intent(project_id): intent.display_name = "fake_intent" - intents = intents_client.create_intent(request={"parent": parent, "intent": intent}) + intents = intents_client.create_intent(request={"parent": parent, "intent": intent}) return intents.name.split("/")[4]