Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

docs(samples): adds list training phrases sample #196

Merged
merged 2 commits into from Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions samples/snippets/list_training_phrases.py
@@ -0,0 +1,41 @@
# 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
#
# https://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.

# [START dialogflow_list_training_phrases]


def list_training_phrases(project_id, agent_id, intent_id, location):
"""Returns all training phrases for a specified intent."""

from google.cloud import dialogflowcx

# Create the intents client
intent_client = dialogflowcx.IntentsClient()

# Specify working intent
intent_name = intent_client.intent_path(project_id, location, agent_id, intent_id)

# Compose the get-intent request
get_intent_request = dialogflowcx.GetIntentRequest(name=intent_name)

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]
34 changes: 34 additions & 0 deletions samples/snippets/list_training_phrases_test.py
@@ -0,0 +1,34 @@
#!/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 os

import google.auth

import list_training_phrases


_, PROJECT_ID = google.auth.default()
INTENT_ID = os.getenv("INTENT_ID")
LOCATION = "global"
AGENT_ID = os.getenv("AGENT_ID")


def test_list_training_phrases(capsys):
training_phrases = list_training_phrases.list_training_phrases(
PROJECT_ID, AGENT_ID, INTENT_ID, LOCATION
)
assert len(training_phrases) >= 15 # Number of training phrases at this point.
1 change: 1 addition & 0 deletions samples/snippets/noxfile_config.py
Expand Up @@ -35,5 +35,6 @@
"AGENT_ID": "53516802-3e2a-4016-80b6-a3df0d240240",
"AGENT_ID_US_CENTRAL1": "edf8372c-c66a-4984-83ba-b85885e95e2a",
"AUDIO_PATH": "resources/hello.wav",
"INTENT_ID": "164428bd-647a-4e30-ab0f-cc7f3e3b76f9",
},
}