diff --git a/dialogflow/cloud-client/context_management.py b/dialogflow/cloud-client/context_management.py deleted file mode 100644 index d2a75bd711a..00000000000 --- a/dialogflow/cloud-client/context_management.py +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2017 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 Context Python sample showing how to manage session -contexts. - -Examples: - python context_management.py -h - python context_management.py --project-id PROJECT_ID \ - list --session-id SESSION_ID - python context_management.py --project-id PROJECT_ID \ - create --session-id SESSION_ID --context-id CONTEXT_ID - python context_management.py --project-id PROJECT_ID \ - delete --session-id SESSION_ID --context-id CONTEXT_ID -""" - -import argparse - - -# [START dialogflow_list_contexts] -def list_contexts(project_id, session_id): - import dialogflow_v2 as dialogflow - contexts_client = dialogflow.ContextsClient() - - session_path = contexts_client.session_path(project_id, session_id) - - contexts = contexts_client.list_contexts(session_path) - - print('Contexts for session {}:\n'.format(session_path)) - for context in contexts: - print('Context name: {}'.format(context.name)) - print('Lifespan count: {}'.format(context.lifespan_count)) - print('Fields:') - for field, value in context.parameters.fields.items(): - if value.string_value: - print('\t{}: {}'.format(field, value)) -# [END dialogflow_list_contexts] - - -# [START dialogflow_create_context] -def create_context(project_id, session_id, context_id, lifespan_count): - import dialogflow_v2 as dialogflow - contexts_client = dialogflow.ContextsClient() - - session_path = contexts_client.session_path(project_id, session_id) - context_name = contexts_client.context_path( - project_id, session_id, context_id) - - context = dialogflow.types.Context( - name=context_name, lifespan_count=lifespan_count) - - response = contexts_client.create_context(session_path, context) - - print('Context created: \n{}'.format(response)) -# [END dialogflow_create_context] - - -# [START dialogflow_delete_context] -def delete_context(project_id, session_id, context_id): - import dialogflow_v2 as dialogflow - contexts_client = dialogflow.ContextsClient() - - context_name = contexts_client.context_path( - project_id, session_id, context_id) - - contexts_client.delete_context(context_name) -# [END dialogflow_delete_context] - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument( - '--project-id', - help='Project/agent id. Required.', - required=True) - - subparsers = parser.add_subparsers(dest='command') - - list_parser = subparsers.add_parser( - 'list', help=list_contexts.__doc__) - list_parser.add_argument( - '--session-id', - required=True) - - create_parser = subparsers.add_parser( - 'create', help=create_context.__doc__) - create_parser.add_argument( - '--session-id', - required=True) - create_parser.add_argument( - '--context-id', - help='The id of the context.', - required=True) - create_parser.add_argument( - '--lifespan-count', - help='The lifespan_count of the context. Defaults to 1.', - default=1) - - delete_parser = subparsers.add_parser( - 'delete', help=delete_context.__doc__) - delete_parser.add_argument( - '--session-id', - required=True) - delete_parser.add_argument( - '--context-id', - help='The id of the context.', - required=True) - - args = parser.parse_args() - - if args.command == 'list': - list_contexts(args.project_id, args.session_id, ) - elif args.command == 'create': - create_context( - args.project_id, args.session_id, args.context_id, - args.lifespan_count) - elif args.command == 'delete': - delete_context(args.project_id, args.session_id, args.context_id) diff --git a/dialogflow/cloud-client/context_management_test.py b/dialogflow/cloud-client/context_management_test.py deleted file mode 100644 index e0172d7d128..00000000000 --- a/dialogflow/cloud-client/context_management_test.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2017 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. - -from __future__ import absolute_import - -import os -import uuid - -import context_management -import detect_intent_texts - -PROJECT_ID = os.getenv('GCLOUD_PROJECT') -SESSION_ID = 'test_session_{}'.format(uuid.uuid4()) -CONTEXT_ID = 'test_context_{}'.format(uuid.uuid4()) - - -def test_create_context(capsys): - # Calling detect intent to create a session. - detect_intent_texts.detect_intent_texts( - PROJECT_ID, SESSION_ID, ['hi'], 'en-US') - - context_management.create_context(PROJECT_ID, SESSION_ID, CONTEXT_ID, 1) - context_management.list_contexts(PROJECT_ID, SESSION_ID) - - out, _ = capsys.readouterr() - assert CONTEXT_ID in out - - -def test_delete_context(capsys): - context_management.delete_context(PROJECT_ID, SESSION_ID, CONTEXT_ID) - context_management.list_contexts(PROJECT_ID, SESSION_ID) - - out, _ = capsys.readouterr() - assert CONTEXT_ID not in out diff --git a/dialogflow/cloud-client/create_entity_test.py b/dialogflow/cloud-client/create_entity_test.py deleted file mode 100644 index 81a92cca629..00000000000 --- a/dialogflow/cloud-client/create_entity_test.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os -import uuid -import pytest - -import dialogflow_v2 as dialogflow - -import entity_management - -PROJECT_ID = os.getenv("GCLOUD_PROJECT") -DISPLAY_NAME = "entity_{}".format(uuid.uuid4()).replace('-', '')[:30] -ENTITY_VALUE_1 = "test_entity_value_1" -ENTITY_VALUE_2 = "test_entity_value_2" -SYNONYMS = ["fake_synonym_for_testing_1", "fake_synonym_for_testing_2"] - -pytest.ENTITY_TYPE_ID = None - - -@pytest.fixture(scope="function", autouse=True) -def setup_teardown(): - # Create an entity type to use with create entity - entity_types_client = dialogflow.EntityTypesClient() - parent = entity_types_client.project_agent_path(PROJECT_ID) - entity_type = dialogflow.types.EntityType( - display_name=DISPLAY_NAME, - kind=dialogflow.enums.EntityType.Kind.KIND_MAP, - ) - - response = entity_types_client.create_entity_type(parent, entity_type) - pytest.ENTITY_TYPE_ID = response.name.split("agent/entityTypes/")[1] - - yield - # Delete the created entity type and its entities - assert pytest.ENTITY_TYPE_ID is not None - entity_type_path = entity_types_client.entity_type_path( - PROJECT_ID, pytest.ENTITY_TYPE_ID - ) - entity_types_client.delete_entity_type(entity_type_path) - - -def test_create_entity(capsys): - entity_management.create_entity( - PROJECT_ID, pytest.ENTITY_TYPE_ID, ENTITY_VALUE_1, [] - ) - entity_management.create_entity( - PROJECT_ID, pytest.ENTITY_TYPE_ID, ENTITY_VALUE_2, SYNONYMS - ) - - entity_management.list_entities(PROJECT_ID, pytest.ENTITY_TYPE_ID) - - out, _ = capsys.readouterr() - assert ENTITY_VALUE_1 in out - assert ENTITY_VALUE_2 in out - for synonym in SYNONYMS: - assert synonym in out diff --git a/dialogflow/cloud-client/create_entity_type_test.py b/dialogflow/cloud-client/create_entity_type_test.py deleted file mode 100644 index fab7d8accfd..00000000000 --- a/dialogflow/cloud-client/create_entity_type_test.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os -import uuid -import pytest - -import dialogflow_v2 as dialogflow - -import entity_type_management - -PROJECT_ID = os.getenv("GCLOUD_PROJECT") -DISPLAY_NAME = "entity_type_{}".format(uuid.uuid4()).replace('-', '')[:30] -pytest.ENTITY_TYPE_ID = None - - -@pytest.fixture(scope="function", autouse=True) -def teardown(): - yield - - # Delete the created entity type - entity_types_client = dialogflow.EntityTypesClient() - assert pytest.ENTITY_TYPE_ID is not None - entity_type_path = entity_types_client.entity_type_path( - PROJECT_ID, pytest.ENTITY_TYPE_ID - ) - entity_types_client.delete_entity_type(entity_type_path) - - -def test_create_entity_type(capsys): - entity_type_management.create_entity_type( - PROJECT_ID, DISPLAY_NAME, "KIND_MAP" - ) - out, _ = capsys.readouterr() - - assert 'display_name: "{}"'.format(DISPLAY_NAME) in out - - # Save the entity id so that it can be deleted - pytest.ENTITY_TYPE_ID = out.split("agent/entityTypes/")[1].split('"\n')[0] diff --git a/dialogflow/cloud-client/delete_document_test.py b/dialogflow/cloud-client/delete_document_test.py deleted file mode 100644 index f36905dabe0..00000000000 --- a/dialogflow/cloud-client/delete_document_test.py +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os -import uuid - -import dialogflow_v2beta1 as dialogflow -import pytest - -import document_management - -PROJECT_ID = os.getenv('GCLOUD_PROJECT') -KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4()) -DOCUMENT_DISPLAY_NAME = 'test_document_{}'.format(uuid.uuid4()) -pytest.KNOWLEDGE_BASE_ID = None -pytest.DOCUMENT_ID = None - - -@pytest.fixture(scope="function", autouse=True) -def setup_teardown(): - # Create a knowledge base to use in document management - client = dialogflow.KnowledgeBasesClient() - project_path = client.project_path(PROJECT_ID) - knowledge_base = dialogflow.types.KnowledgeBase( - display_name=KNOWLEDGE_BASE_NAME) - response = client.create_knowledge_base(project_path, knowledge_base) - pytest.KNOWLEDGE_BASE_ID = response.name.split( - '/knowledgeBases/')[1].split('\n')[0] - - # Create a document to delete - knowledge_base_path = client.knowledge_base_path( - PROJECT_ID, pytest.KNOWLEDGE_BASE_ID) - document = dialogflow.types.Document( - display_name=DOCUMENT_DISPLAY_NAME, mime_type='text/html', - content_uri='https://cloud.google.com/storage/docs/faq') - document.knowledge_types.append( - dialogflow.types.Document.KnowledgeType.Value('FAQ')) - documents_client = dialogflow.DocumentsClient() - response = documents_client.create_document(knowledge_base_path, document) - document = response.result(timeout=90) - pytest.DOCUMENT_ID = document.name.split('/documents/')[1].split('\n')[0] - - yield - - # Delete the created knowledge base - client.delete_knowledge_base(knowledge_base_path, force=True) - - -def test_delete_document(capsys): - document_management.delete_document( - PROJECT_ID, pytest.KNOWLEDGE_BASE_ID, pytest.DOCUMENT_ID) - document_management.list_documents(PROJECT_ID, pytest.KNOWLEDGE_BASE_ID) - out, _ = capsys.readouterr() - assert DOCUMENT_DISPLAY_NAME not in out diff --git a/dialogflow/cloud-client/delete_entity_test.py b/dialogflow/cloud-client/delete_entity_test.py deleted file mode 100644 index 91d9184cc2f..00000000000 --- a/dialogflow/cloud-client/delete_entity_test.py +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os -import uuid -import pytest - -import dialogflow_v2 as dialogflow - -import entity_management - -PROJECT_ID = os.getenv("GCLOUD_PROJECT") -DISPLAY_NAME = "entity_{}".format(uuid.uuid4()).replace('-', '')[:30] -ENTITY_VALUE_1 = "test_delete_entity_value" - -pytest.ENTITY_TYPE_ID = None - - -@pytest.fixture(scope="function", autouse=True) -def setup_teardown(): - # Create an entity type - entity_types_client = dialogflow.EntityTypesClient() - parent = entity_types_client.project_agent_path(PROJECT_ID) - entity_type = dialogflow.types.EntityType( - display_name=DISPLAY_NAME, - kind=dialogflow.enums.EntityType.Kind.KIND_MAP, - ) - - response = entity_types_client.create_entity_type(parent, entity_type) - pytest.ENTITY_TYPE_ID = response.name.split("agent/entityTypes/")[1] - - # Create an entity inside the entity type - entity_type_path = entity_types_client.entity_type_path( - PROJECT_ID, pytest.ENTITY_TYPE_ID - ) - entity = dialogflow.types.EntityType.Entity( - value=ENTITY_VALUE_1, synonyms=[ENTITY_VALUE_1] - ) - response = entity_types_client.batch_create_entities( - entity_type_path, [entity] - ) - response.result() - - yield - - # Delete the created entity type and its entities - entity_types_client.delete_entity_type(entity_type_path) - - -def test_delete_entity(capsys): - entity_management.delete_entity( - PROJECT_ID, pytest.ENTITY_TYPE_ID, ENTITY_VALUE_1 - ) - - entity_management.list_entities(PROJECT_ID, pytest.ENTITY_TYPE_ID) - - out, _ = capsys.readouterr() - assert ENTITY_VALUE_1 not in out diff --git a/dialogflow/cloud-client/delete_entity_type_test.py b/dialogflow/cloud-client/delete_entity_type_test.py deleted file mode 100644 index b6b0a6d1ede..00000000000 --- a/dialogflow/cloud-client/delete_entity_type_test.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os -import uuid -import pytest - -import dialogflow_v2 as dialogflow - -import entity_type_management - -PROJECT_ID = os.getenv("GCLOUD_PROJECT") -DISPLAY_NAME = "entity_type_{}".format(uuid.uuid4()).replace('-', '')[:30] -pytest.ENTITY_TYPE_ID = None - - -@pytest.fixture(scope="function", autouse=True) -def setup(): - # Create an entity type for deletion - entity_types_client = dialogflow.EntityTypesClient() - parent = entity_types_client.project_agent_path(PROJECT_ID) - entity_type = dialogflow.types.EntityType( - display_name=DISPLAY_NAME, - kind=dialogflow.enums.EntityType.Kind.KIND_MAP, - ) - - response = entity_types_client.create_entity_type(parent, entity_type) - pytest.ENTITY_TYPE_ID = response.name.split("agent/entityTypes/")[1] - - -def test_delete_entity_type(capsys): - entity_type_management.delete_entity_type( - PROJECT_ID, pytest.ENTITY_TYPE_ID - ) - - entity_type_management.list_entity_types(PROJECT_ID) - out, _ = capsys.readouterr() - assert DISPLAY_NAME not in out diff --git a/dialogflow/cloud-client/delete_knowledge_base_test.py b/dialogflow/cloud-client/delete_knowledge_base_test.py deleted file mode 100644 index dc47eaa833c..00000000000 --- a/dialogflow/cloud-client/delete_knowledge_base_test.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os -import uuid - -import dialogflow_v2beta1 as dialogflow -import pytest - -import knowledge_base_management - -PROJECT_ID = os.getenv('GCLOUD_PROJECT') -KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4()) -pytest.KNOWLEDGE_BASE_ID = None - - -@pytest.fixture(scope="function", autouse=True) -def setup(): - # Create a knowledge base to delete - client = dialogflow.KnowledgeBasesClient() - project_path = client.project_path(PROJECT_ID) - knowledge_base = dialogflow.types.KnowledgeBase( - display_name=KNOWLEDGE_BASE_NAME) - response = client.create_knowledge_base(project_path, knowledge_base) - pytest.KNOWLEDGE_BASE_ID = response.name.split( - '/knowledgeBases/')[1].split('\n')[0] - - -def test_delete_knowledge_base(capsys): - knowledge_base_management.delete_knowledge_base( - PROJECT_ID, pytest.KNOWLEDGE_BASE_ID) - knowledge_base_management.list_knowledge_bases(PROJECT_ID) - out, _ = capsys.readouterr() - assert KNOWLEDGE_BASE_NAME not in out diff --git a/dialogflow/cloud-client/detect_intent_with_model_selection.py b/dialogflow/cloud-client/detect_intent_with_model_selection.py deleted file mode 100644 index fc47b8e64d2..00000000000 --- a/dialogflow/cloud-client/detect_intent_with_model_selection.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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 Beta Detect Intent Python sample with model selection. - -Examples: - python detect_intent_with_model_selection.py -h - python detect_intent_with_model_selection.py --project-id PROJECT_ID \ - --session-id SESSION_ID --audio-file-path resources/book_a_room.wav -""" - -import argparse -import uuid - - -# [START dialogflow_detect_intent_with_model_selection] -def detect_intent_with_model_selection(project_id, session_id, audio_file_path, - language_code): - """Returns the result of detect intent with model selection on an audio file - as input - - Using the same `session_id` between requests allows continuation - of the conversation.""" - import dialogflow_v2beta1 as dialogflow - session_client = dialogflow.SessionsClient() - - # Note: hard coding audio_encoding and sample_rate_hertz for simplicity. - audio_encoding = dialogflow.enums.AudioEncoding.AUDIO_ENCODING_LINEAR_16 - sample_rate_hertz = 16000 - - session_path = session_client.session_path(project_id, session_id) - print('Session path: {}\n'.format(session_path)) - - with open(audio_file_path, 'rb') as audio_file: - input_audio = audio_file.read() - - # Which Speech model to select for the given request. - # Possible models: video, phone_call, command_and_search, default - model = 'phone_call' - - audio_config = dialogflow.types.InputAudioConfig( - audio_encoding=audio_encoding, language_code=language_code, - sample_rate_hertz=sample_rate_hertz, - model=model) - query_input = dialogflow.types.QueryInput(audio_config=audio_config) - - response = session_client.detect_intent( - session=session_path, query_input=query_input, - input_audio=input_audio) - - print('=' * 20) - print('Query text: {}'.format(response.query_result.query_text)) - print('Detected intent: {} (confidence: {})\n'.format( - response.query_result.intent.display_name, - response.query_result.intent_detection_confidence)) - print('Fulfillment text: {}\n'.format( - response.query_result.fulfillment_text)) -# [END dialogflow_detect_intent_with_model_selection] - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument( - '--project-id', - help='Project/agent id. Required.', - required=True) - parser.add_argument( - '--session-id', - help='Identifier of the DetectIntent session. ' - 'Defaults to a random UUID.', - default=str(uuid.uuid4())) - parser.add_argument( - '--language-code', - help='Language code of the query. Defaults to "en-US".', - default='en-US') - parser.add_argument( - '--audio-file-path', - help='Path to the audio file.', - required=True) - - args = parser.parse_args() - - detect_intent_with_model_selection( - args.project_id, args.session_id, args.audio_file_path, - args.language_code) diff --git a/dialogflow/cloud-client/detect_intent_with_model_selection_test.py b/dialogflow/cloud-client/detect_intent_with_model_selection_test.py deleted file mode 100644 index 30cc165b9f7..00000000000 --- a/dialogflow/cloud-client/detect_intent_with_model_selection_test.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2018, 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. - -from __future__ import absolute_import - -import os -import uuid - -from detect_intent_with_model_selection import \ - detect_intent_with_model_selection - -DIRNAME = os.path.realpath(os.path.dirname(__file__)) -PROJECT_ID = os.getenv('GCLOUD_PROJECT') -SESSION_ID = 'test_{}'.format(uuid.uuid4()) -AUDIOS = [ - '{0}/resources/book_a_room.wav'.format(DIRNAME), - '{0}/resources/mountain_view.wav'.format(DIRNAME), - '{0}/resources/today.wav'.format(DIRNAME), -] - - -def test_detect_intent_audio_with_model_selection(capsys): - for audio_file_path in AUDIOS: - detect_intent_with_model_selection(PROJECT_ID, SESSION_ID, - audio_file_path, 'en-US') - out, _ = capsys.readouterr() - - assert 'Fulfillment text: What time will the meeting start?' in out diff --git a/dialogflow/cloud-client/document_management.py b/dialogflow/cloud-client/document_management.py index 6145c9df8a6..b5e1c91d84f 100644 --- a/dialogflow/cloud-client/document_management.py +++ b/dialogflow/cloud-client/document_management.py @@ -20,49 +20,17 @@ 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 \ - get --document-id DOCUMENT_ID - python document_management.py --project-id PROJECT_ID \ - --knowledge-base-id knowledge_base_id \ - delete --document-id DOCUMENT_ID """ import argparse - KNOWLEDGE_TYPES = ['KNOWLEDGE_TYPE_UNSPECIFIED', 'FAQ', 'EXTRACTIVE_QA'] -# [START dialogflow_list_document] -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.""" - import dialogflow_v2beta1 as dialogflow - client = dialogflow.DocumentsClient() - knowledge_base_path = client.knowledge_base_path(project_id, - knowledge_base_id) - - print('Documents for Knowledge Id: {}'.format(knowledge_base_id)) - for document in client.list_documents(knowledge_base_path): - 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)) -# [END dialogflow_list_document] - - # [START dialogflow_create_document]] def create_document(project_id, knowledge_base_id, display_name, mime_type, knowledge_type, content_uri): @@ -104,51 +72,6 @@ def create_document(project_id, knowledge_base_id, display_name, mime_type, # [END dialogflow_create_document]] -# [START dialogflow_get_document]] -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.""" - import dialogflow_v2beta1 as dialogflow - client = dialogflow.DocumentsClient() - document_path = client.document_path(project_id, knowledge_base_id, - document_id) - - response = client.get_document(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)) -# [END dialogflow_get_document]] - - -# [START dialogflow_delete_document]] -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.""" - import dialogflow_v2beta1 as dialogflow - client = dialogflow.DocumentsClient() - document_path = client.document_path(project_id, knowledge_base_id, - document_id) - - response = client.delete_document(document_path) - print('operation running:\n {}'.format(response.operation)) - print('Waiting for results...') - print('Done.\n {}'.format(response.result())) -# [END dialogflow_delete_document]] - - if __name__ == '__main__': parser = argparse.ArgumentParser( description=__doc__, @@ -162,10 +85,6 @@ def delete_document(project_id, knowledge_base_id, document_id): subparsers = parser.add_subparsers(dest='command') - list_parser = subparsers.add_parser( - '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_parser.add_argument( @@ -188,29 +107,9 @@ def delete_document(project_id, knowledge_base_id, document_id): '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_parser.add_argument( - '--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_parser.add_argument( - '--document-id', - help='The id of the Document you want to delete', - required=True) - args = parser.parse_args() - if args.command == 'list': - list_documents(args.project_id, args.knowledge_base_id) - elif args.command == 'create': + if 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) diff --git a/dialogflow/cloud-client/entity_management.py b/dialogflow/cloud-client/entity_management.py deleted file mode 100644 index 2fff2fe12fe..00000000000 --- a/dialogflow/cloud-client/entity_management.py +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2017 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 Entity Python sample showing how to manage entities. - -Examples: - python entity_management.py -h - python entity_management.py --project-id PROJECT_ID \ - list --entity-type-id e57238e2-e692-44ea-9216-6be1b2332e2a - python entity_management.py --project-id PROJECT_ID \ - create new_room --synonyms basement cellar \ - --entity-type-id e57238e2-e692-44ea-9216-6be1b2332e2a - python entity_management.py --project-id PROJECT_ID \ - delete new_room \ - --entity-type-id e57238e2-e692-44ea-9216-6be1b2332e2a -""" - -import argparse - - -# [START dialogflow_list_entities] -def list_entities(project_id, entity_type_id): - import dialogflow_v2 as dialogflow - entity_types_client = dialogflow.EntityTypesClient() - - parent = entity_types_client.entity_type_path( - project_id, entity_type_id) - - entities = entity_types_client.get_entity_type(parent).entities - - for entity in entities: - print('Entity value: {}'.format(entity.value)) - print('Entity synonyms: {}\n'.format(entity.synonyms)) -# [END dialogflow_list_entities] - - -# [START dialogflow_create_entity] -def create_entity(project_id, entity_type_id, entity_value, synonyms): - """Create an entity of the given entity type.""" - import dialogflow_v2 as dialogflow - entity_types_client = dialogflow.EntityTypesClient() - - # Note: synonyms must be exactly [entity_value] if the - # entity_type's kind is KIND_LIST - synonyms = synonyms or [entity_value] - - entity_type_path = entity_types_client.entity_type_path( - project_id, entity_type_id) - - entity = dialogflow.types.EntityType.Entity() - entity.value = entity_value - entity.synonyms.extend(synonyms) - - response = entity_types_client.batch_create_entities( - entity_type_path, [entity]) - - print('Entity created: {}'.format(response)) -# [END dialogflow_create_entity] - - -# [START dialogflow_delete_entity] -def delete_entity(project_id, entity_type_id, entity_value): - """Delete entity with the given entity type and entity value.""" - import dialogflow_v2 as dialogflow - entity_types_client = dialogflow.EntityTypesClient() - - entity_type_path = entity_types_client.entity_type_path( - project_id, entity_type_id) - - entity_types_client.batch_delete_entities( - entity_type_path, [entity_value]) -# [END dialogflow_delete_entity] - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument( - '--project-id', - help='Project/agent id. Required.', - required=True) - - subparsers = parser.add_subparsers(dest='command') - - list_parser = subparsers.add_parser( - 'list', help=list_entities.__doc__) - list_parser.add_argument( - '--entity-type-id', - help='The id of the entity_type.') - - create_parser = subparsers.add_parser( - 'create', help=create_entity.__doc__) - create_parser.add_argument( - 'entity_value', - help='The entity value to be added.') - create_parser.add_argument( - '--entity-type-id', - help='The id of the entity_type to which to add an entity.', - required=True) - create_parser.add_argument( - '--synonyms', - nargs='*', - help='The synonyms that will map to the provided entity value.', - default=[]) - - delete_parser = subparsers.add_parser( - 'delete', help=delete_entity.__doc__) - delete_parser.add_argument( - '--entity-type-id', - help='The id of the entity_type.', - required=True) - delete_parser.add_argument( - 'entity_value', - help='The value of the entity to delete.') - - args = parser.parse_args() - - if args.command == 'list': - list_entities(args.project_id, args.entity_type_id) - elif args.command == 'create': - create_entity( - args.project_id, args.entity_type_id, args.entity_value, - args.synonyms) - elif args.command == 'delete': - delete_entity( - args.project_id, args.entity_type_id, args.entity_value) diff --git a/dialogflow/cloud-client/entity_type_management.py b/dialogflow/cloud-client/entity_type_management.py deleted file mode 100644 index 1f342f3a1b9..00000000000 --- a/dialogflow/cloud-client/entity_type_management.py +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2017 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 EntityType Python sample showing how to manage entity types. - -Examples: - python entity_type_management.py -h - python entity_type_management.py --project-id PROJECT_ID list - python entity_type_management.py --project-id PROJECT_ID create employee - python entity_type_management.py --project-id PROJECT_ID delete \ - e57238e2-e692-44ea-9216-6be1b2332e2a -""" - -import argparse - - -# [START dialogflow_list_entity_types] -def list_entity_types(project_id): - import dialogflow_v2 as dialogflow - entity_types_client = dialogflow.EntityTypesClient() - - parent = entity_types_client.project_agent_path(project_id) - - entity_types = entity_types_client.list_entity_types(parent) - - for entity_type in entity_types: - print('Entity type name: {}'.format(entity_type.name)) - print('Entity type display name: {}'.format(entity_type.display_name)) - print('Number of entities: {}\n'.format(len(entity_type.entities))) -# [END dialogflow_list_entity_types] - - -# [START dialogflow_create_entity_type] -def create_entity_type(project_id, display_name, kind): - """Create an entity type with the given display name.""" - import dialogflow_v2 as dialogflow - entity_types_client = dialogflow.EntityTypesClient() - - parent = entity_types_client.project_agent_path(project_id) - entity_type = dialogflow.types.EntityType( - display_name=display_name, kind=kind) - - response = entity_types_client.create_entity_type(parent, entity_type) - - print('Entity type created: \n{}'.format(response)) -# [END dialogflow_create_entity_type] - - -# [START dialogflow_delete_entity_type] -def delete_entity_type(project_id, entity_type_id): - """Delete entity type with the given entity type name.""" - import dialogflow_v2 as dialogflow - entity_types_client = dialogflow.EntityTypesClient() - - entity_type_path = entity_types_client.entity_type_path( - project_id, entity_type_id) - - entity_types_client.delete_entity_type(entity_type_path) -# [END dialogflow_delete_entity_type] - - -# Helper to get entity_type_id from display name. -def _get_entity_type_ids(project_id, display_name): - import dialogflow_v2 as dialogflow - entity_types_client = dialogflow.EntityTypesClient() - - parent = entity_types_client.project_agent_path(project_id) - entity_types = entity_types_client.list_entity_types(parent) - entity_type_names = [ - entity_type.name for entity_type in entity_types - if entity_type.display_name == display_name] - - entity_type_ids = [ - entity_type_name.split('/')[-1] for entity_type_name - in entity_type_names] - - return entity_type_ids - - -if __name__ == '__main__': - import dialogflow_v2 - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument( - '--project-id', - help='Project/agent id. Required.', - required=True) - - subparsers = parser.add_subparsers(dest='command') - - list_parser = subparsers.add_parser( - 'list', help=list_entity_types.__doc__) - - create_parser = subparsers.add_parser( - 'create', help=create_entity_type.__doc__) - create_parser.add_argument( - 'display_name', - help='The display name of the entity.') - create_parser.add_argument( - '--kind', - help='The kind of entity. KIND_MAP (default) or KIND_LIST.', - default=dialogflow_v2.enums.EntityType.Kind.KIND_MAP) - - delete_parser = subparsers.add_parser( - 'delete', help=delete_entity_type.__doc__) - delete_parser.add_argument( - 'entity_type_id', - help='The id of the entity_type.') - - args = parser.parse_args() - - if args.command == 'list': - list_entity_types(args.project_id) - elif args.command == 'create': - create_entity_type(args.project_id, args.display_name, args.kind) - elif args.command == 'delete': - delete_entity_type(args.project_id, args.entity_type_id) diff --git a/dialogflow/cloud-client/get_document_test.py b/dialogflow/cloud-client/get_document_test.py deleted file mode 100644 index 3b6563e5f22..00000000000 --- a/dialogflow/cloud-client/get_document_test.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os - -import document_management - -PROJECT_ID = os.getenv('GCLOUD_PROJECT') -DOCUMENT_DISPLAY_NAME = 'DO_NOT_DELETE_TEST_DOCUMENT' -KNOWLEDGE_BASE_ID = 'MjEwMjE4MDQ3MDQwMDc0NTQ3Mg' -DOCUMENT_ID = 'MzMxOTU0NjU1MDUzNDc5OTM2MA' - - -def test_get_document(capsys): - document_management.get_document( - PROJECT_ID, KNOWLEDGE_BASE_ID, DOCUMENT_ID) - out, _ = capsys.readouterr() - assert DOCUMENT_DISPLAY_NAME in out diff --git a/dialogflow/cloud-client/get_knowledge_base_test.py b/dialogflow/cloud-client/get_knowledge_base_test.py deleted file mode 100644 index 17f08dca1ed..00000000000 --- a/dialogflow/cloud-client/get_knowledge_base_test.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os -import uuid - -import dialogflow_v2beta1 as dialogflow -import pytest - -import knowledge_base_management - -PROJECT_ID = os.getenv('GCLOUD_PROJECT') -KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4()) -pytest.KNOWLEDGE_BASE_ID = None - - -@pytest.fixture(scope="function", autouse=True) -def setup_teardown(): - # Create a knowledge base to get - client = dialogflow.KnowledgeBasesClient() - project_path = client.project_path(PROJECT_ID) - knowledge_base = dialogflow.types.KnowledgeBase( - display_name=KNOWLEDGE_BASE_NAME) - response = client.create_knowledge_base(project_path, 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) - client.delete_knowledge_base(knowledge_base_path) - - -def test_get_knowledge_base(capsys): - knowledge_base_management.get_knowledge_base( - PROJECT_ID, pytest.KNOWLEDGE_BASE_ID) - out, _ = capsys.readouterr() - assert KNOWLEDGE_BASE_NAME in out diff --git a/dialogflow/cloud-client/knowledge_base_management.py b/dialogflow/cloud-client/knowledge_base_management.py index b5ceab786cc..070f04d02ca 100644 --- a/dialogflow/cloud-client/knowledge_base_management.py +++ b/dialogflow/cloud-client/knowledge_base_management.py @@ -19,35 +19,12 @@ 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 """ import argparse -# [START dialogflow_list_knowledge_base] -def list_knowledge_bases(project_id): - """Lists the Knowledge bases belonging to a project. - - Args: - project_id: The GCP project linked with the agent.""" - import dialogflow_v2beta1 as dialogflow - client = dialogflow.KnowledgeBasesClient() - project_path = client.project_path(project_id) - - print('Knowledge Bases for: {}'.format(project_id)) - for knowledge_base in client.list_knowledge_bases(project_path): - print(' - Display Name: {}'.format(knowledge_base.display_name)) - print(' - Knowledge ID: {}\n'.format(knowledge_base.name)) -# [END dialogflow_list_knowledge_base] - - # [START dialogflow_create_knowledge_base] def create_knowledge_base(project_id, display_name): """Creates a Knowledge base. @@ -70,44 +47,6 @@ def create_knowledge_base(project_id, display_name): # [END dialogflow_create_knowledge_base] -# [START dialogflow_get_knowledge_base] -def get_knowledge_base(project_id, knowledge_base_id): - """Gets a specific Knowledge base. - - Args: - project_id: The GCP project linked with the agent. - knowledge_base_id: Id of the Knowledge base.""" - import dialogflow_v2beta1 as dialogflow - client = dialogflow.KnowledgeBasesClient() - knowledge_base_path = client.knowledge_base_path( - project_id, knowledge_base_id) - - response = client.get_knowledge_base(knowledge_base_path) - - print('Got Knowledge Base:') - print(' - Display Name: {}'.format(response.display_name)) - print(' - Knowledge ID: {}'.format(response.name)) -# [END dialogflow_get_knowledge_base] - - -# [START dialogflow_delete_knowledge_base] -def delete_knowledge_base(project_id, knowledge_base_id): - """Deletes a specific Knowledge base. - - Args: - project_id: The GCP project linked with the agent. - knowledge_base_id: Id of the Knowledge base.""" - import dialogflow_v2beta1 as dialogflow - client = dialogflow.KnowledgeBasesClient() - knowledge_base_path = client.knowledge_base_path( - project_id, knowledge_base_id) - - response = client.delete_knowledge_base(knowledge_base_path) - - print('Knowledge Base deleted.'.format(response)) -# [END dialogflow_delete_knowledge_base] - - if __name__ == '__main__': parser = argparse.ArgumentParser( description=__doc__, @@ -117,9 +56,6 @@ def delete_knowledge_base(project_id, knowledge_base_id): subparsers = parser.add_subparsers(dest='command') - list_parser = subparsers.add_parser( - '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.add_argument( @@ -128,26 +64,7 @@ def delete_knowledge_base(project_id, knowledge_base_id): '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.add_argument( - '--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_parser.add_argument( - '--knowledge-base-id', - help='The id of the Knowledge base you want to delete.', - required=True) - args = parser.parse_args() - if args.command == 'list': - list_knowledge_bases(args.project_id) - elif args.command == 'create': + if args.command == 'create': create_knowledge_base(args.project_id, args.display_name) - elif args.command == 'get': - get_knowledge_base(args.project_id, args.knowledge_base_id) - elif args.command == 'delete': - delete_knowledge_base(args.project_id, args.knowledge_base_id) diff --git a/dialogflow/cloud-client/list_documents_test.py b/dialogflow/cloud-client/list_documents_test.py deleted file mode 100644 index d1be64ccd6d..00000000000 --- a/dialogflow/cloud-client/list_documents_test.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os - -import document_management - -PROJECT_ID = os.getenv('GCLOUD_PROJECT') -DOCUMENT_DISPLAY_NAME = 'DO_NOT_DELETE_TEST_DOCUMENT' -KNOWLEDGE_BASE_ID = 'MjEwMjE4MDQ3MDQwMDc0NTQ3Mg' - - -def test_list_documents(capsys): - document_management.list_documents(PROJECT_ID, KNOWLEDGE_BASE_ID) - out, _ = capsys.readouterr() - assert DOCUMENT_DISPLAY_NAME in out diff --git a/dialogflow/cloud-client/list_entities_test.py b/dialogflow/cloud-client/list_entities_test.py deleted file mode 100644 index 0e808048218..00000000000 --- a/dialogflow/cloud-client/list_entities_test.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os -import uuid -import pytest - -import dialogflow_v2 as dialogflow - -import entity_management - -PROJECT_ID = os.getenv("GCLOUD_PROJECT") -DISPLAY_NAME = "entity_{}".format(uuid.uuid4()).replace('-', '')[:30] -ENTITY_VALUE_1 = "test_list_entity_value" - -pytest.ENTITY_TYPE_ID = None - - -@pytest.fixture(scope="function", autouse=True) -def setup_teardown(): - # Create an entity type - entity_types_client = dialogflow.EntityTypesClient() - parent = entity_types_client.project_agent_path(PROJECT_ID) - entity_type = dialogflow.types.EntityType( - display_name=DISPLAY_NAME, - kind=dialogflow.enums.EntityType.Kind.KIND_MAP, - ) - - response = entity_types_client.create_entity_type(parent, entity_type) - pytest.ENTITY_TYPE_ID = response.name.split("agent/entityTypes/")[1] - - # Create an entity inside the entity type - entity_type_path = entity_types_client.entity_type_path( - PROJECT_ID, pytest.ENTITY_TYPE_ID - ) - entity = dialogflow.types.EntityType.Entity( - value=ENTITY_VALUE_1, synonyms=[ENTITY_VALUE_1] - ) - response = entity_types_client.batch_create_entities( - entity_type_path, [entity] - ) - response.result() - - yield - - # Delete the created entity type and its entities - entity_types_client.delete_entity_type(entity_type_path) - - -def test_list_entities(capsys): - entity_management.list_entities(PROJECT_ID, pytest.ENTITY_TYPE_ID) - out, _ = capsys.readouterr() - assert ENTITY_VALUE_1 in out diff --git a/dialogflow/cloud-client/list_entity_types_test.py b/dialogflow/cloud-client/list_entity_types_test.py deleted file mode 100644 index 33cac5ec3cd..00000000000 --- a/dialogflow/cloud-client/list_entity_types_test.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os -import uuid -import pytest - -import dialogflow_v2 as dialogflow - -import entity_type_management - -PROJECT_ID = os.getenv("GCLOUD_PROJECT") -DISPLAY_NAME = "entity_type_{}".format(uuid.uuid4()).replace('-', '')[:30] - - -@pytest.fixture(scope="function", autouse=True) -def setup_teardown(): - # Create an entity type to list - entity_types_client = dialogflow.EntityTypesClient() - parent = entity_types_client.project_agent_path(PROJECT_ID) - entity_type = dialogflow.types.EntityType( - display_name=DISPLAY_NAME, - kind=dialogflow.enums.EntityType.Kind.KIND_MAP, - ) - response = entity_types_client.create_entity_type(parent, entity_type) - entity_type_id = response.name.split("agent/entityTypes/")[1] - - yield - - # Delete the created entity type - entity_type_path = entity_types_client.entity_type_path( - PROJECT_ID, entity_type_id - ) - entity_types_client.delete_entity_type(entity_type_path) - - -def test_list_entity_types(capsys): - entity_type_management.list_entity_types(PROJECT_ID) - out, _ = capsys.readouterr() - assert DISPLAY_NAME in out diff --git a/dialogflow/cloud-client/list_knowledge_bases_test.py b/dialogflow/cloud-client/list_knowledge_bases_test.py deleted file mode 100644 index ad66a659502..00000000000 --- a/dialogflow/cloud-client/list_knowledge_bases_test.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2020 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. - -from __future__ import absolute_import - -import os -import uuid - -import dialogflow_v2beta1 as dialogflow -import pytest - -import knowledge_base_management - -PROJECT_ID = os.getenv('GCLOUD_PROJECT') -KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4()) - - -@pytest.fixture(scope="function", autouse=True) -def setup_teardown(): - # Create a knowledge base to list - client = dialogflow.KnowledgeBasesClient() - project_path = client.project_path(PROJECT_ID) - knowledge_base = dialogflow.types.KnowledgeBase( - display_name=KNOWLEDGE_BASE_NAME) - response = client.create_knowledge_base(project_path, knowledge_base) - 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, knowledge_base_id) - client.delete_knowledge_base(knowledge_base_path) - - -def test_list_knowledge_base(capsys): - knowledge_base_management.list_knowledge_bases(PROJECT_ID) - out, _ = capsys.readouterr() - assert KNOWLEDGE_BASE_NAME in out diff --git a/dialogflow/cloud-client/session_entity_type_management.py b/dialogflow/cloud-client/session_entity_type_management.py deleted file mode 100644 index 2c852325338..00000000000 --- a/dialogflow/cloud-client/session_entity_type_management.py +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2017 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 SessionEntityType Python sample showing how to manage -session entity types. - -Examples: - python session_entity_type_management.py -h - python session_entity_type_management.py --project-id PROJECT_ID list \ - --session-id SESSION_ID - python session_entity_type_management.py --project-id PROJECT_ID create \ - --session-id SESSION_ID \ - --entity-type-display-name room --entity-values C D E F - python session_entity_type_management.py --project-id PROJECT_ID delete \ - --session-id SESSION_ID \ - --entity-type-display-name room -""" - -import argparse - - -# [START dialogflow_list_session_entity_types] -def list_session_entity_types(project_id, session_id): - import dialogflow_v2 as dialogflow - session_entity_types_client = dialogflow.SessionEntityTypesClient() - - session_path = session_entity_types_client.session_path( - project_id, session_id) - - session_entity_types = ( - session_entity_types_client. - list_session_entity_types(session_path)) - - print('SessionEntityTypes for session {}:\n'.format(session_path)) - for session_entity_type in session_entity_types: - print('\tSessionEntityType name: {}'.format(session_entity_type.name)) - print('\tNumber of entities: {}\n'.format( - len(session_entity_type.entities))) -# [END dialogflow_list_session_entity_types] - - -# [START dialogflow_create_session_entity_type] -def create_session_entity_type(project_id, session_id, entity_values, - entity_type_display_name, entity_override_mode): - """Create a session entity type with the given display name.""" - import dialogflow_v2 as dialogflow - session_entity_types_client = dialogflow.SessionEntityTypesClient() - - session_path = session_entity_types_client.session_path( - project_id, session_id) - session_entity_type_name = ( - session_entity_types_client.session_entity_type_path( - project_id, session_id, entity_type_display_name)) - - # Here we use the entity value as the only synonym. - entities = [ - dialogflow.types.EntityType.Entity(value=value, synonyms=[value]) - for value in entity_values] - session_entity_type = dialogflow.types.SessionEntityType( - name=session_entity_type_name, - entity_override_mode=entity_override_mode, - entities=entities) - - response = session_entity_types_client.create_session_entity_type( - session_path, session_entity_type) - - print('SessionEntityType created: \n\n{}'.format(response)) -# [END dialogflow_create_session_entity_type] - - -# [START dialogflow_delete_session_entity_type] -def delete_session_entity_type(project_id, session_id, - entity_type_display_name): - """Delete session entity type with the given entity type display name.""" - import dialogflow_v2 as dialogflow - session_entity_types_client = dialogflow.SessionEntityTypesClient() - - session_entity_type_name = ( - session_entity_types_client.session_entity_type_path( - project_id, session_id, entity_type_display_name)) - - session_entity_types_client.delete_session_entity_type( - session_entity_type_name) -# [END dialogflow_delete_session_entity_type] - - -if __name__ == '__main__': - import dialogflow_v2 - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument( - '--project-id', - help='Project/agent id. Required.', - required=True) - - subparsers = parser.add_subparsers(dest='command') - - list_parser = subparsers.add_parser( - 'list', help=list_session_entity_types.__doc__) - list_parser.add_argument( - '--session-id', - required=True) - - create_parser = subparsers.add_parser( - 'create', help=create_session_entity_type.__doc__) - create_parser.add_argument( - '--session-id', - required=True) - create_parser.add_argument( - '--entity-type-display-name', - help='The DISPLAY NAME of the entity type to be overridden ' - 'in the session.', - required=True) - create_parser.add_argument( - '--entity-values', - nargs='*', - help='The entity values of the session entity type.', - required=True) - create_parser.add_argument( - '--entity-override-mode', - help='ENTITY_OVERRIDE_MODE_OVERRIDE (default) or ' - 'ENTITY_OVERRIDE_MODE_SUPPLEMENT', - default=(dialogflow_v2.enums.SessionEntityType.EntityOverrideMode. - ENTITY_OVERRIDE_MODE_OVERRIDE)) - - delete_parser = subparsers.add_parser( - 'delete', help=delete_session_entity_type.__doc__) - delete_parser.add_argument( - '--session-id', - required=True) - delete_parser.add_argument( - '--entity-type-display-name', - help='The DISPLAY NAME of the entity type.', - required=True) - - args = parser.parse_args() - - if args.command == 'list': - list_session_entity_types(args.project_id, args.session_id) - elif args.command == 'create': - create_session_entity_type( - args.project_id, args.session_id, args.entity_values, - args.entity_type_display_name, args.entity_override_mode) - elif args.command == 'delete': - delete_session_entity_type( - args.project_id, args.session_id, args.entity_type_display_name) diff --git a/dialogflow/cloud-client/session_entity_type_management_test.py b/dialogflow/cloud-client/session_entity_type_management_test.py deleted file mode 100644 index 2e844818d2f..00000000000 --- a/dialogflow/cloud-client/session_entity_type_management_test.py +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright 2017 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. - -from __future__ import absolute_import - -import os -import uuid - -import entity_type_management -import session_entity_type_management - -PROJECT_ID = os.getenv('GCLOUD_PROJECT') -SESSION_ID = 'test_session_{}'.format(uuid.uuid4()) -ENTITY_TYPE_DISPLAY_NAME = 'test_{}'.format(uuid.uuid4()).replace('-', '')[:30] -ENTITY_VALUES = ['fake_entity_value_1', 'fake_entity_value_2'] - - -def test_create_session_entity_type(capsys): - # Create an entity type - entity_type_management.create_entity_type( - PROJECT_ID, ENTITY_TYPE_DISPLAY_NAME, 'KIND_MAP') - - session_entity_type_management.create_session_entity_type( - PROJECT_ID, SESSION_ID, ENTITY_VALUES, ENTITY_TYPE_DISPLAY_NAME, - 'ENTITY_OVERRIDE_MODE_SUPPLEMENT') - session_entity_type_management.list_session_entity_types( - PROJECT_ID, SESSION_ID) - - out, _ = capsys.readouterr() - - assert SESSION_ID in out - assert ENTITY_TYPE_DISPLAY_NAME in out - for entity_value in ENTITY_VALUES: - assert entity_value in out - - -def test_delete_session_entity_type(capsys): - session_entity_type_management.delete_session_entity_type( - PROJECT_ID, SESSION_ID, ENTITY_TYPE_DISPLAY_NAME) - session_entity_type_management.list_session_entity_types( - PROJECT_ID, SESSION_ID) - - out, _ = capsys.readouterr() - assert ENTITY_TYPE_DISPLAY_NAME not in out - for entity_value in ENTITY_VALUES: - assert entity_value not in out - - # Clean up entity type - entity_type_ids = entity_type_management._get_entity_type_ids( - PROJECT_ID, ENTITY_TYPE_DISPLAY_NAME) - for entity_type_id in entity_type_ids: - entity_type_management.delete_entity_type( - PROJECT_ID, entity_type_id)